gitlab.com/evatix-go/core@v1.3.55/coredata/coredynamic/MapAnyItemDiff.go (about)

     1  package coredynamic
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"gitlab.com/evatix-go/core/coredata/corejson"
     7  	"gitlab.com/evatix-go/core/internal/mapdiffinternal"
     8  )
     9  
    10  type MapAnyItemDiff map[string]interface{}
    11  
    12  func (it *MapAnyItemDiff) Length() int {
    13  	if it == nil {
    14  		return 0
    15  	}
    16  
    17  	return len(*it)
    18  }
    19  
    20  func (it MapAnyItemDiff) IsEmpty() bool {
    21  	return it.Length() == 0
    22  }
    23  
    24  func (it MapAnyItemDiff) HasAnyItem() bool {
    25  	return it.Length() > 0
    26  }
    27  
    28  func (it MapAnyItemDiff) LastIndex() int {
    29  	return it.Length() - 1
    30  }
    31  
    32  func (it MapAnyItemDiff) AllKeysSorted() []string {
    33  	return mapdiffinternal.MapStringAnyDiff(it.Raw()).AllKeysSorted()
    34  }
    35  
    36  func (it *MapAnyItemDiff) IsRawEqual(
    37  	isRegardlessType bool,
    38  	rightMap map[string]interface{},
    39  ) bool {
    40  	differ := mapdiffinternal.
    41  		MapStringAnyDiff(it.Raw())
    42  
    43  	return differ.
    44  		IsRawEqual(
    45  			isRegardlessType,
    46  			rightMap)
    47  }
    48  
    49  func (it *MapAnyItemDiff) HashmapDiffUsingRaw(
    50  	isRegardlessType bool,
    51  	rightMap map[string]interface{},
    52  ) MapAnyItemDiff {
    53  	diffMap := it.DiffRaw(
    54  		isRegardlessType,
    55  		rightMap)
    56  
    57  	if len(diffMap) == 0 {
    58  		return map[string]interface{}{}
    59  	}
    60  
    61  	return diffMap
    62  }
    63  
    64  func (it *MapAnyItemDiff) MapAnyItems() *MapAnyItems {
    65  	return &MapAnyItems{
    66  		Items: it.Raw(),
    67  	}
    68  }
    69  
    70  func (it *MapAnyItemDiff) HasAnyChanges(
    71  	isRegardlessType bool,
    72  	rightMap map[string]interface{},
    73  ) bool {
    74  	return !it.IsRawEqual(
    75  		isRegardlessType,
    76  		rightMap)
    77  }
    78  
    79  func (it *MapAnyItemDiff) RawMapDiffer() mapdiffinternal.MapStringAnyDiff {
    80  	return it.Raw()
    81  }
    82  
    83  func (it *MapAnyItemDiff) DiffRaw(
    84  	isRegardlessType bool,
    85  	rightMap map[string]interface{},
    86  ) map[string]interface{} {
    87  	differ := mapdiffinternal.
    88  		MapStringAnyDiff(it.Raw())
    89  
    90  	return differ.
    91  		DiffRaw(
    92  			isRegardlessType,
    93  			rightMap)
    94  }
    95  
    96  func (it *MapAnyItemDiff) DiffJsonMessage(
    97  	isRegardlessType bool,
    98  	rightMap map[string]interface{},
    99  ) string {
   100  	differ := mapdiffinternal.
   101  		MapStringAnyDiff(it.Raw())
   102  
   103  	return differ.DiffJsonMessage(
   104  		isRegardlessType,
   105  		rightMap)
   106  }
   107  
   108  func (it *MapAnyItemDiff) ToStringsSliceOfDiffMap(
   109  	diffMap map[string]interface{},
   110  ) (diffSlice []string) {
   111  	differ := mapdiffinternal.
   112  		MapStringAnyDiff(it.Raw())
   113  
   114  	return differ.ToStringsSliceOfDiffMap(
   115  		diffMap)
   116  }
   117  
   118  func (it *MapAnyItemDiff) ShouldDiffMessage(
   119  	isRegardlessType bool,
   120  	title string,
   121  	rightMap map[string]interface{},
   122  ) string {
   123  	differ := mapdiffinternal.
   124  		MapStringAnyDiff(it.Raw())
   125  
   126  	return differ.ShouldDiffMessage(
   127  		isRegardlessType,
   128  		title,
   129  		rightMap)
   130  }
   131  
   132  func (it *MapAnyItemDiff) LogShouldDiffMessage(
   133  	isRegardlessType bool,
   134  	title string,
   135  	rightMap map[string]interface{},
   136  ) (diffMessage string) {
   137  	differ := mapdiffinternal.
   138  		MapStringAnyDiff(it.Raw())
   139  
   140  	return differ.LogShouldDiffMessage(
   141  		isRegardlessType,
   142  		title,
   143  		rightMap)
   144  }
   145  
   146  func (it *MapAnyItemDiff) Raw() map[string]interface{} {
   147  	if it == nil {
   148  		return map[string]interface{}{}
   149  	}
   150  
   151  	return *it
   152  }
   153  
   154  func (it *MapAnyItemDiff) Clear() MapAnyItemDiff {
   155  	if it == nil {
   156  		return map[string]interface{}{}
   157  	}
   158  
   159  	*it = map[string]interface{}{}
   160  
   161  	return *it
   162  }
   163  
   164  func (it MapAnyItemDiff) Json() corejson.Result {
   165  	return corejson.New(it)
   166  }
   167  
   168  func (it MapAnyItemDiff) JsonPtr() *corejson.Result {
   169  	return corejson.NewPtr(it)
   170  }
   171  
   172  func (it MapAnyItemDiff) PrettyJsonString() string {
   173  	return corejson.NewPtr(it).PrettyJsonString()
   174  }
   175  
   176  func (it MapAnyItemDiff) LogPrettyJsonString() {
   177  	if it.IsEmpty() {
   178  		fmt.Println("Empty Map")
   179  	}
   180  
   181  	prettyJson := it.JsonPtr().PrettyJsonString()
   182  
   183  	fmt.Println(prettyJson)
   184  }