gitlab.com/evatix-go/core@v1.3.55/coredata/corestr/HashmapDiff.go (about) 1 package corestr 2 3 import ( 4 "gitlab.com/evatix-go/core/coredata/corejson" 5 "gitlab.com/evatix-go/core/internal/mapdiffinternal" 6 ) 7 8 type HashmapDiff map[string]string 9 10 func (it *HashmapDiff) Length() int { 11 if it == nil { 12 return 0 13 } 14 15 return len(*it) 16 } 17 18 func (it HashmapDiff) IsEmpty() bool { 19 return it.Length() == 0 20 } 21 22 func (it HashmapDiff) HasAnyItem() bool { 23 return it.Length() > 0 24 } 25 26 func (it HashmapDiff) LastIndex() int { 27 return it.Length() - 1 28 } 29 30 func (it HashmapDiff) AllKeysSorted() []string { 31 return mapdiffinternal.HashmapDiff(it.Raw()).AllKeysSorted() 32 } 33 34 func (it *HashmapDiff) MapAnyItems() map[string]interface{} { 35 if it == nil || len(*it) == 0 { 36 return map[string]interface{}{} 37 } 38 39 newMap := make( 40 map[string]interface{}, 41 it.Length()+1) 42 43 for name, value := range *it { 44 newMap[name] = value 45 } 46 47 return newMap 48 } 49 50 func (it *HashmapDiff) HasAnyChanges( 51 rightMap map[string]string, 52 ) bool { 53 return !it.IsRawEqual( 54 rightMap) 55 } 56 57 func (it *HashmapDiff) RawMapStringAnyDiff() mapdiffinternal.MapStringAnyDiff { 58 return it.MapAnyItems() 59 } 60 61 func (it *HashmapDiff) IsRawEqual( 62 rightMap map[string]string, 63 ) bool { 64 differ := mapdiffinternal. 65 HashmapDiff(it.Raw()) 66 67 return differ. 68 IsRawEqual(rightMap) 69 } 70 71 func (it *HashmapDiff) HashmapDiffUsingRaw( 72 rightMap map[string]string, 73 ) HashmapDiff { 74 diffMap := it.DiffRaw( 75 rightMap) 76 77 if len(diffMap) == 0 { 78 return map[string]string{} 79 } 80 81 return diffMap 82 } 83 84 func (it *HashmapDiff) DiffRaw( 85 rightMap map[string]string, 86 ) map[string]string { 87 differ := mapdiffinternal. 88 HashmapDiff(it.Raw()) 89 90 return differ. 91 DiffRaw(rightMap) 92 } 93 94 func (it *HashmapDiff) DiffJsonMessage( 95 rightMap map[string]string, 96 ) string { 97 differ := mapdiffinternal. 98 HashmapDiff(it.Raw()) 99 100 return differ.DiffJsonMessage( 101 rightMap) 102 } 103 104 func (it *HashmapDiff) ToStringsSliceOfDiffMap( 105 diffMap map[string]string, 106 ) (diffSlice []string) { 107 differ := mapdiffinternal. 108 HashmapDiff(it.Raw()) 109 110 return differ.ToStringsSliceOfDiffMap( 111 diffMap) 112 } 113 114 func (it *HashmapDiff) ShouldDiffMessage( 115 title string, 116 rightMap map[string]string, 117 ) string { 118 differ := mapdiffinternal. 119 HashmapDiff(it.Raw()) 120 121 return differ.ShouldDiffMessage( 122 title, 123 rightMap) 124 } 125 126 func (it *HashmapDiff) LogShouldDiffMessage( 127 title string, 128 rightMap map[string]string, 129 ) (diffMessage string) { 130 differ := mapdiffinternal. 131 HashmapDiff(it.Raw()) 132 133 return differ.LogShouldDiffMessage( 134 title, 135 rightMap) 136 } 137 138 func (it *HashmapDiff) Raw() map[string]string { 139 if it == nil { 140 return map[string]string{} 141 } 142 143 return *it 144 } 145 146 func (it *HashmapDiff) Serialize() ([]byte, error) { 147 return corejson.Serialize.Raw(it.Raw()) 148 } 149 150 func (it *HashmapDiff) Deserialize(toPtr interface{}) (parsingErr error) { 151 return corejson.NewPtr(it.Raw()).Deserialize(toPtr) 152 }