gitlab.com/evatix-go/core@v1.3.55/coredata/corestr/newKeyValuesCreator.go (about)

     1  package corestr
     2  
     3  import "gitlab.com/evatix-go/core/constants"
     4  
     5  type newKeyValuesCreator struct{}
     6  
     7  func (it *newKeyValuesCreator) Cap(
     8  	capacity int,
     9  ) *KeyValueCollection {
    10  	collection := make(
    11  		[]*KeyValuePair,
    12  		constants.Zero,
    13  		capacity)
    14  
    15  	return &KeyValueCollection{
    16  		KeyValuePairs: collection,
    17  	}
    18  }
    19  
    20  func (it *newKeyValuesCreator) Empty() *KeyValueCollection {
    21  	collection := make(
    22  		[]*KeyValuePair,
    23  		constants.Zero,
    24  		constants.Zero)
    25  
    26  	return &KeyValueCollection{
    27  		KeyValuePairs: collection,
    28  	}
    29  }
    30  
    31  func (it *newKeyValuesCreator) UsingMap(
    32  	input map[string]string,
    33  ) *KeyValueCollection {
    34  	length := len(input)
    35  	keyValCollection := it.Cap(length)
    36  
    37  	if length == 0 {
    38  		return keyValCollection
    39  	}
    40  
    41  	return keyValCollection.AddMap(input)
    42  }
    43  
    44  func (it *newKeyValuesCreator) UsingKeyValuePairs(
    45  	keyValPairs ...KeyValuePair,
    46  ) *KeyValueCollection {
    47  	length := len(keyValPairs)
    48  	keyValCollection := it.Cap(length)
    49  
    50  	if length == 0 {
    51  		return keyValCollection
    52  	}
    53  
    54  	return keyValCollection.Adds(keyValPairs...)
    55  }
    56  
    57  func (it *newKeyValuesCreator) UsingKeyValueStrings(
    58  	keys, values []string,
    59  ) *KeyValueCollection {
    60  	length := len(keys)
    61  	keyValCollection := it.Cap(length)
    62  
    63  	if length == 0 {
    64  		return keyValCollection
    65  	}
    66  
    67  	for i, key := range keys {
    68  		keyValCollection.Add(key, values[i])
    69  	}
    70  
    71  	return keyValCollection
    72  }