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

     1  package corestr
     2  
     3  import (
     4  	"strings"
     5  
     6  	"gitlab.com/evatix-go/core/constants"
     7  )
     8  
     9  type newCollectionCreator struct{}
    10  
    11  func (it *newCollectionCreator) Empty() *Collection {
    12  	return &Collection{
    13  		items: []string{},
    14  	}
    15  }
    16  
    17  func (it *newCollectionCreator) Cap(capacity int) *Collection {
    18  	collection := make([]string, constants.Zero, capacity)
    19  
    20  	return &Collection{
    21  		items: collection,
    22  	}
    23  }
    24  
    25  func (it *newCollectionCreator) CloneStrings(stringItems []string) *Collection {
    26  	length := len(stringItems)
    27  	slice := make([]string, 0, length+constants.Capacity4)
    28  
    29  	collection := &Collection{
    30  		items: slice,
    31  	}
    32  
    33  	return collection.AddStringsPtr(&stringItems)
    34  }
    35  
    36  func (it *newCollectionCreator) Create(stringItems []string) *Collection {
    37  	return &Collection{
    38  		items: stringItems,
    39  	}
    40  }
    41  
    42  func (it *newCollectionCreator) Strings(stringItems []string) *Collection {
    43  	return &Collection{
    44  		items: stringItems,
    45  	}
    46  }
    47  
    48  func (it *newCollectionCreator) StringsPtr(stringItems *[]string) *Collection {
    49  	if stringItems == nil {
    50  		return it.Empty()
    51  	}
    52  
    53  	return &Collection{
    54  		items: *stringItems,
    55  	}
    56  }
    57  
    58  func (it *newCollectionCreator) StringsOptions(isMakeClone bool, stringItems []string) *Collection {
    59  	if isMakeClone {
    60  		return it.CloneStrings(stringItems)
    61  	}
    62  
    63  	return &Collection{
    64  		items: stringItems,
    65  	}
    66  }
    67  
    68  func (it *newCollectionCreator) StringsPtrOption(isMakeClone bool, stringItems *[]string) *Collection {
    69  	if isMakeClone {
    70  		length := LengthOfStringsPtr(stringItems)
    71  		slice := make([]string, 0, length+constants.Capacity4)
    72  
    73  		collection := &Collection{
    74  			items: slice,
    75  		}
    76  
    77  		return collection.AddStringsPtr(stringItems)
    78  	}
    79  
    80  	if stringItems == nil {
    81  		return it.Empty()
    82  	}
    83  
    84  	return &Collection{
    85  		items: *stringItems,
    86  	}
    87  }
    88  
    89  func (it *newCollectionCreator) LineUsingSep(sep, line string) *Collection {
    90  	lines := strings.Split(line, sep)
    91  
    92  	return &Collection{
    93  		items: lines,
    94  	}
    95  }
    96  
    97  func (it *newCollectionCreator) LineDefault(compiledLine string) *Collection {
    98  	lines := strings.Split(compiledLine, constants.DefaultLine)
    99  
   100  	return &Collection{
   101  		items: lines,
   102  	}
   103  }
   104  
   105  func (it *newCollectionCreator) StringsPlusCap(
   106  	additionalCapacity int,
   107  	stringItems []string,
   108  ) *Collection {
   109  	if additionalCapacity == 0 {
   110  		return it.Strings(stringItems)
   111  	}
   112  
   113  	length := len(stringItems)
   114  	collection := it.Cap(length + additionalCapacity)
   115  
   116  	return collection.Adds(stringItems...)
   117  }
   118  
   119  func (it *newCollectionCreator) StringsPtrPlusCap(
   120  	additionalCap int,
   121  	stringItems *[]string,
   122  ) *Collection {
   123  	if additionalCap == 0 {
   124  		return it.StringsPtrOption(
   125  			false,
   126  			stringItems)
   127  	}
   128  
   129  	length := LengthOfStringsPtr(stringItems)
   130  	collection := it.Cap(length + additionalCap)
   131  
   132  	return collection.AddStringsPtr(stringItems)
   133  }
   134  
   135  func (it *newCollectionCreator) PointerStrings(
   136  	stringItems []*string,
   137  ) *Collection {
   138  	if len(stringItems) == 0 {
   139  		return it.Empty()
   140  	}
   141  
   142  	length := LengthOfPointerStrings(&stringItems)
   143  	collection := it.Cap(length)
   144  
   145  	return collection.AddPointerStringsPtr(&stringItems)
   146  }
   147  
   148  func (it *newCollectionCreator) PointerStringsPtrUsingCap(
   149  	capacity int,
   150  	stringItems *[]*string,
   151  ) *Collection {
   152  	length := LengthOfPointerStrings(stringItems)
   153  	collection := it.Cap(length + capacity)
   154  
   155  	return collection.AddPointerStringsPtr(stringItems)
   156  }
   157  
   158  func (it *newCollectionCreator) LenCap(length, capacity int) *Collection {
   159  	collection := make([]string, length, capacity)
   160  
   161  	return &Collection{
   162  		items: collection,
   163  	}
   164  }