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

     1  package corestr
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"math"
     7  	"sort"
     8  	"strings"
     9  	"sync"
    10  
    11  	"gitlab.com/evatix-go/core/constants"
    12  	"gitlab.com/evatix-go/core/converters"
    13  	"gitlab.com/evatix-go/core/coredata/corejson"
    14  	"gitlab.com/evatix-go/core/coreindexes"
    15  	"gitlab.com/evatix-go/core/coresort/strsort"
    16  	"gitlab.com/evatix-go/core/errcore"
    17  	"gitlab.com/evatix-go/core/internal/strutilinternal"
    18  )
    19  
    20  type CollectionPtr struct {
    21  	items []*string
    22  	sync.Mutex
    23  }
    24  
    25  func (it *CollectionPtr) Count() int {
    26  	return it.Length()
    27  }
    28  
    29  func (it *CollectionPtr) HasAnyItem() bool {
    30  	return it.Length() > 0
    31  }
    32  
    33  func (it *CollectionPtr) LastIndex() int {
    34  	return it.Length() - 1
    35  }
    36  
    37  func (it *CollectionPtr) HasIndex(index int) bool {
    38  	return it.LastIndex() >= index
    39  }
    40  
    41  func (it *CollectionPtr) ListStringsPtr() *[]string {
    42  	return it.SimpleListPtr()
    43  }
    44  
    45  func (it *CollectionPtr) ListStrings() []string {
    46  	return *it.SimpleListPtr()
    47  }
    48  
    49  func (it *CollectionPtr) StringJSON() string {
    50  	return it.JsonPtr().JsonString()
    51  }
    52  
    53  func (it *CollectionPtr) RemoveAt(index int) (isSuccess bool) {
    54  	if !it.HasIndex(index) {
    55  		return false
    56  	}
    57  
    58  	it.ChainRemoveAt(index)
    59  
    60  	return true
    61  }
    62  
    63  func (it *CollectionPtr) Capacity() int {
    64  	if it.items == nil {
    65  		return 0
    66  	}
    67  
    68  	return cap(it.items)
    69  }
    70  
    71  func (it *CollectionPtr) Length() int {
    72  	if it == nil || it.items == nil {
    73  		return 0
    74  	}
    75  
    76  	return len(it.items)
    77  }
    78  
    79  func (it *CollectionPtr) LengthLock() int {
    80  	it.Lock()
    81  	defer it.Unlock()
    82  
    83  	if it == nil || it.items == nil {
    84  		return 0
    85  	}
    86  
    87  	return len(it.items)
    88  }
    89  
    90  //goland:noinspection GoVetCopyLock
    91  func (it *CollectionPtr) IsEquals(
    92  	anotherCollectionPtr CollectionPtr,
    93  ) bool {
    94  	return it.IsEqualsWithSensitivePtr(
    95  		&anotherCollectionPtr,
    96  		true)
    97  }
    98  
    99  func (it *CollectionPtr) IsEqualsPtr(
   100  	anotherCollectionPtr *CollectionPtr,
   101  ) bool {
   102  	return it.IsEqualsWithSensitivePtr(
   103  		anotherCollectionPtr,
   104  		true)
   105  }
   106  
   107  func (it *CollectionPtr) IsEqualsWithSensitivePtr(
   108  	anotherCollectionPtr *CollectionPtr,
   109  	isCaseSensitive bool,
   110  ) bool {
   111  	if anotherCollectionPtr == nil && it == nil {
   112  		return true
   113  	}
   114  
   115  	if anotherCollectionPtr == nil || it == nil {
   116  		return false
   117  	}
   118  
   119  	if it == anotherCollectionPtr {
   120  		return true
   121  	}
   122  
   123  	if it.IsEmpty() && anotherCollectionPtr.IsEmpty() {
   124  		return true
   125  	}
   126  
   127  	if it.IsEmpty() || anotherCollectionPtr.IsEmpty() {
   128  		return false
   129  	}
   130  
   131  	if it.Length() != anotherCollectionPtr.Length() {
   132  		return false
   133  	}
   134  
   135  	leftItems := it.items
   136  	rightItems := anotherCollectionPtr.items
   137  
   138  	if isCaseSensitive {
   139  		for i, leftVal := range leftItems {
   140  			if leftVal != rightItems[i] {
   141  				return false
   142  			}
   143  		}
   144  
   145  		return true
   146  	}
   147  
   148  	for i, leftVal := range leftItems {
   149  		rightVal := rightItems[i]
   150  
   151  		if leftVal == nil && rightVal == nil {
   152  			continue
   153  		}
   154  
   155  		if leftVal == nil || rightVal == nil {
   156  			return false
   157  		}
   158  
   159  		if !strings.EqualFold(*leftVal, *rightVal) {
   160  			return false
   161  		}
   162  	}
   163  
   164  	return true
   165  }
   166  
   167  func (it *CollectionPtr) IsEmptyLock() bool {
   168  	it.Lock()
   169  	defer it.Unlock()
   170  
   171  	return it.Length() == 0
   172  }
   173  
   174  func (it *CollectionPtr) IsEmpty() bool {
   175  	return it.Length() == 0
   176  }
   177  
   178  func (it *CollectionPtr) HasItems() bool {
   179  	return it.Length() > 0
   180  }
   181  
   182  func (it *CollectionPtr) AddLock(str string) *CollectionPtr {
   183  	it.Lock()
   184  	defer it.Unlock()
   185  
   186  	it.items = append(
   187  		it.items,
   188  		&str)
   189  
   190  	return it
   191  }
   192  
   193  func (it *CollectionPtr) Add(str string) *CollectionPtr {
   194  	it.items = append(
   195  		it.items,
   196  		&str)
   197  
   198  	return it
   199  }
   200  
   201  func (it *CollectionPtr) AddNonEmptyWhitespace(str string) *CollectionPtr {
   202  	if str == "" {
   203  		return it
   204  	}
   205  
   206  	if strutilinternal.IsEmptyOrWhitespace(str) {
   207  		return it
   208  	}
   209  
   210  	it.items = append(
   211  		it.items,
   212  		&str)
   213  
   214  	return it
   215  }
   216  
   217  func (it *CollectionPtr) AddIf(isAdd bool, addingStringPtr *string) *CollectionPtr {
   218  	if !isAdd {
   219  		return it
   220  	}
   221  
   222  	it.items = append(
   223  		it.items,
   224  		addingStringPtr)
   225  
   226  	return it
   227  }
   228  
   229  func (it *CollectionPtr) AddIfMany(
   230  	isAdd bool,
   231  	addingStrings ...*string,
   232  ) *CollectionPtr {
   233  	if !isAdd {
   234  		return it
   235  	}
   236  
   237  	it.items = append(
   238  		it.items,
   239  		addingStrings...)
   240  
   241  	return it
   242  }
   243  
   244  func (it *CollectionPtr) AddFunc(f func() *string) *CollectionPtr {
   245  	it.items = append(
   246  		it.items,
   247  		f())
   248  
   249  	return it
   250  }
   251  
   252  func (it *CollectionPtr) AddFuncErr(
   253  	funcReturnsError func() (result *string, err error),
   254  	errHandler func(errInput error),
   255  ) *CollectionPtr {
   256  	r, err := funcReturnsError()
   257  
   258  	if err != nil {
   259  		errHandler(err)
   260  
   261  		return it
   262  	}
   263  
   264  	it.items = append(
   265  		it.items,
   266  		r)
   267  
   268  	return it
   269  }
   270  
   271  func (it *CollectionPtr) AddsLock(items ...string) *CollectionPtr {
   272  	it.Lock()
   273  	defer it.Unlock()
   274  
   275  	for i := range items {
   276  		it.items = append(
   277  			it.items,
   278  			&(items[i]))
   279  	}
   280  
   281  	return it
   282  }
   283  
   284  func (it *CollectionPtr) Adds(items ...string) *CollectionPtr {
   285  	for i := range items {
   286  		it.items = append(
   287  			it.items,
   288  			&(items[i]))
   289  	}
   290  
   291  	return it
   292  }
   293  
   294  func (it *CollectionPtr) AddHashmapsValues(
   295  	hashmaps ...*Hashmap,
   296  ) *CollectionPtr {
   297  	if hashmaps == nil {
   298  		return it
   299  	}
   300  
   301  	for _, hashmap := range hashmaps {
   302  		if hashmap == nil || hashmap.IsEmpty() {
   303  			continue
   304  		}
   305  
   306  		for _, v := range hashmap.items {
   307  			newV := v
   308  			it.items = append(
   309  				it.items,
   310  				&newV)
   311  		}
   312  	}
   313  
   314  	return it
   315  }
   316  
   317  func (it *CollectionPtr) AddHashmapsKeys(
   318  	hashmaps ...*Hashmap,
   319  ) *CollectionPtr {
   320  	if hashmaps == nil {
   321  		return it
   322  	}
   323  
   324  	it.resizeForHashmaps(
   325  		&hashmaps,
   326  		constants.One)
   327  
   328  	for _, hashmap := range hashmaps {
   329  		if hashmap == nil || hashmap.IsEmpty() {
   330  			continue
   331  		}
   332  
   333  		for k := range hashmap.items {
   334  			keyCopied := k
   335  			it.items = append(
   336  				it.items,
   337  				&keyCopied)
   338  		}
   339  	}
   340  
   341  	return it
   342  }
   343  
   344  func (it *CollectionPtr) resizeForHashmaps(
   345  	hashmaps *[]*Hashmap,
   346  	multiplier int,
   347  ) *CollectionPtr {
   348  	if hashmaps == nil {
   349  		return it
   350  	}
   351  
   352  	length := 0
   353  
   354  	for _, hashmap := range *hashmaps {
   355  		if hashmap == nil || hashmap.IsEmpty() {
   356  			continue
   357  		}
   358  
   359  		length += hashmap.Length()
   360  	}
   361  
   362  	if !it.isResizeRequired(length) {
   363  		return it
   364  	}
   365  
   366  	finalLength :=
   367  		length*multiplier +
   368  			length/2
   369  
   370  	return it.AddCapacity(finalLength)
   371  }
   372  
   373  func (it *CollectionPtr) resizeForCollectionPtrs(
   374  	collections *[]*CollectionPtr,
   375  	multiplier int,
   376  ) *CollectionPtr {
   377  	if collections == nil {
   378  		return it
   379  	}
   380  
   381  	length := 0
   382  
   383  	for _, collection := range *collections {
   384  		if collection == nil || collection.IsEmpty() {
   385  			continue
   386  		}
   387  
   388  		length += collection.Length()
   389  	}
   390  
   391  	if !it.isResizeRequired(length) {
   392  		return it
   393  	}
   394  
   395  	finalLength :=
   396  		length*multiplier +
   397  			length/2
   398  
   399  	return it.AddCapacity(finalLength)
   400  }
   401  
   402  func (it *CollectionPtr) resizeForItems(
   403  	items []*string,
   404  	multiplier int,
   405  ) *CollectionPtr {
   406  	if items == nil {
   407  		return it
   408  	}
   409  
   410  	length := len(items)
   411  	if !it.isResizeRequired(length) {
   412  		return it
   413  	}
   414  
   415  	finalLength :=
   416  		length*multiplier +
   417  			length/2
   418  
   419  	return it.AddCapacity(finalLength)
   420  }
   421  
   422  func (it *CollectionPtr) isResizeRequired(
   423  	length int,
   424  ) bool {
   425  	if length < constants.ArbitraryCapacity200 {
   426  		return false
   427  	}
   428  
   429  	windowLength := it.Capacity() - it.Length()
   430  	if windowLength >= length {
   431  		return false
   432  	}
   433  
   434  	return true
   435  }
   436  
   437  func (it *CollectionPtr) resizeForAnys(
   438  	items *[]interface{},
   439  	multiplier int,
   440  ) *CollectionPtr {
   441  	if items == nil {
   442  		return it
   443  	}
   444  
   445  	length := len(*items)
   446  	if !it.isResizeRequired(length) {
   447  		return it
   448  	}
   449  
   450  	finalLength :=
   451  		length*multiplier +
   452  			length/2
   453  
   454  	return it.AddCapacity(finalLength)
   455  }
   456  
   457  func (it *CollectionPtr) AddHashmapsKeysValues(
   458  	hashmaps ...*Hashmap,
   459  ) *CollectionPtr {
   460  	if hashmaps == nil {
   461  		return it
   462  	}
   463  
   464  	it.resizeForHashmaps(
   465  		&hashmaps,
   466  		constants.ArbitraryCapacity2)
   467  
   468  	for _, hashmap := range hashmaps {
   469  		if hashmap == nil || hashmap.IsEmpty() {
   470  			continue
   471  		}
   472  
   473  		for k, v := range hashmap.items {
   474  			kc := k
   475  			vc := v
   476  			it.items = append(
   477  				it.items,
   478  				&kc)
   479  			it.items = append(
   480  				it.items,
   481  				&vc)
   482  		}
   483  	}
   484  
   485  	return it
   486  }
   487  
   488  func (it *CollectionPtr) AddHashmapsKeysValuesUsingFilter(
   489  	filter IsKeyValueFilter,
   490  	hashmaps ...*Hashmap,
   491  ) *CollectionPtr {
   492  	if hashmaps == nil {
   493  		return it
   494  	}
   495  
   496  	it.resizeForHashmaps(
   497  		&hashmaps,
   498  		constants.One)
   499  
   500  	for _, hashmap := range hashmaps {
   501  		if hashmap == nil || hashmap.IsEmpty() {
   502  			continue
   503  		}
   504  
   505  		for k, v := range hashmap.items {
   506  			result, isAcceptable, isBreak := filter(KeyValuePair{
   507  				Key:   k,
   508  				Value: v,
   509  			})
   510  
   511  			if isAcceptable {
   512  				it.items = append(
   513  					it.items,
   514  					&result)
   515  			}
   516  
   517  			if isBreak {
   518  				return it
   519  			}
   520  		}
   521  	}
   522  
   523  	return it
   524  }
   525  
   526  func (it *CollectionPtr) AddPtr(str *string) *CollectionPtr {
   527  	it.items = append(
   528  		it.items,
   529  		str)
   530  
   531  	return it
   532  }
   533  
   534  func (it *CollectionPtr) AddPtrLock(str *string) *CollectionPtr {
   535  	it.Lock()
   536  	defer it.Unlock()
   537  
   538  	it.items = append(
   539  		it.items,
   540  		str)
   541  
   542  	return it
   543  }
   544  
   545  func (it *CollectionPtr) AddWithWgLock(
   546  	str string,
   547  	group *sync.WaitGroup,
   548  ) *CollectionPtr {
   549  	it.Lock()
   550  	defer it.Unlock()
   551  
   552  	it.items = append(
   553  		it.items,
   554  		&str)
   555  
   556  	group.Done()
   557  
   558  	return it
   559  }
   560  
   561  func (it *CollectionPtr) AddsPtrLock(itemsPtr ...*string) *CollectionPtr {
   562  	it.Lock()
   563  	defer it.Unlock()
   564  
   565  	for _, str := range itemsPtr {
   566  		it.items = append(
   567  			it.items,
   568  			str)
   569  	}
   570  
   571  	return it
   572  }
   573  
   574  func (it *CollectionPtr) AddStringsPtrWgLock(
   575  	stringItems *[]string,
   576  	group *sync.WaitGroup,
   577  ) *CollectionPtr {
   578  	it.Lock()
   579  	defer it.Unlock()
   580  
   581  	it.AddStringsPtr(stringItems)
   582  	group.Done()
   583  
   584  	return it
   585  }
   586  
   587  func (it *CollectionPtr) AddStringsPtr(stringItems *[]string) *CollectionPtr {
   588  	for i := range *stringItems {
   589  		it.items = append(
   590  			it.items,
   591  			&(*stringItems)[i])
   592  	}
   593  
   594  	return it
   595  }
   596  
   597  func (it *CollectionPtr) InsertItemsAt(index int, stringItems *[]string) *CollectionPtr {
   598  	length := it.Length()
   599  	isAtFirst := length == 0
   600  	isAtLast := length-1 == index
   601  	isAppendItems := isAtFirst || isAtLast
   602  
   603  	if isAppendItems {
   604  		return it.AddStringsPtr(stringItems)
   605  	}
   606  
   607  	pointerStrings := converters.StringsTo.PointerStrings(stringItems)
   608  
   609  	// https://bit.ly/3pIDfRY
   610  	it.items =
   611  		append(
   612  			it.items[:index],
   613  			*pointerStrings...)
   614  
   615  	it.items = append(
   616  		it.items,
   617  		it.items[index:]...)
   618  
   619  	return it
   620  }
   621  
   622  func (it *CollectionPtr) ChainRemoveAt(index int) *CollectionPtr {
   623  	it.items = append(
   624  		it.items[:index],
   625  		it.items[index+1:]...)
   626  
   627  	return it
   628  }
   629  
   630  // RemoveItemsIndexes creates a new collection without the indexes mentioned.
   631  //
   632  // it is better to filter out than remove.
   633  func (it *CollectionPtr) RemoveItemsIndexes(
   634  	isIgnoreRemoveError bool,
   635  	indexes ...int,
   636  ) *CollectionPtr {
   637  	if isIgnoreRemoveError && indexes == nil {
   638  		return it
   639  	}
   640  
   641  	return it.
   642  		RemoveItemsIndexesPtr(isIgnoreRemoveError, indexes)
   643  }
   644  
   645  // RemoveItemsIndexesPtr creates a new collection without the indexes mentioned.
   646  //
   647  // it is better to filter out than remove.
   648  func (it *CollectionPtr) RemoveItemsIndexesPtr(
   649  	isIgnoreRemoveError bool,
   650  	indexes []int,
   651  ) *CollectionPtr {
   652  	length := it.Length()
   653  	indexesLength := len(indexes)
   654  	hasPossibleError := length == 0 && indexesLength > 0
   655  
   656  	if hasPossibleError && !isIgnoreRemoveError {
   657  		panic(errcore.CannotRemoveIndexesFromEmptyCollectionType)
   658  	}
   659  
   660  	if !isIgnoreRemoveError {
   661  		errcore.PanicOnIndexOutOfRange(length, indexes)
   662  	}
   663  
   664  	if hasPossibleError {
   665  		return it
   666  	}
   667  
   668  	newList := make([]*string, constants.Zero, it.Capacity())
   669  	for i, s := range it.items {
   670  		if coreindexes.HasIndex(indexes, i) {
   671  			continue
   672  		}
   673  
   674  		newList = append(newList, s)
   675  	}
   676  
   677  	it.items = newList
   678  
   679  	return it
   680  }
   681  
   682  func (it *CollectionPtr) AddPointerStringsPtrLock(
   683  	pointerStringItems []*string,
   684  ) *CollectionPtr {
   685  	it.Lock()
   686  	defer it.Unlock()
   687  
   688  	return it.
   689  		AddPointerStrings(pointerStringItems...)
   690  }
   691  
   692  func (it *CollectionPtr) AddPointerStrings(
   693  	pointerStringItems ...*string,
   694  ) *CollectionPtr {
   695  	for i := range pointerStringItems {
   696  		it.items = append(
   697  			it.items,
   698  			pointerStringItems[i])
   699  	}
   700  
   701  	return it
   702  }
   703  
   704  //goland:noinspection GoVetCopyLock
   705  func (it *CollectionPtr) AppendCollectionPtr(
   706  	anotherCollectionPtr CollectionPtr,
   707  ) *CollectionPtr {
   708  	it.resizeForItems(
   709  		anotherCollectionPtr.items,
   710  		constants.One)
   711  
   712  	it.items = append(
   713  		it.items,
   714  		anotherCollectionPtr.items...)
   715  
   716  	return it
   717  }
   718  
   719  func (it *CollectionPtr) AppendCollectionPtrPtr(
   720  	anotherCollectionPtr *CollectionPtr,
   721  ) *CollectionPtr {
   722  	it.resizeForItems(
   723  		anotherCollectionPtr.items,
   724  		constants.One)
   725  
   726  	it.items = append(
   727  		it.items,
   728  		anotherCollectionPtr.items...)
   729  
   730  	return it
   731  }
   732  
   733  func (it *CollectionPtr) AppendCollectionPtrsPtr(
   734  	anotherCollectionPtrsPtr ...*CollectionPtr,
   735  ) *CollectionPtr {
   736  	if anotherCollectionPtrsPtr == nil {
   737  		return it
   738  	}
   739  
   740  	it.resizeForCollectionPtrs(
   741  		&anotherCollectionPtrsPtr,
   742  		constants.One)
   743  
   744  	capacitiesIncrease := 0
   745  	for _, currentCollectionPtr := range anotherCollectionPtrsPtr {
   746  		if currentCollectionPtr == nil || currentCollectionPtr.IsEmpty() {
   747  			continue
   748  		}
   749  
   750  		capacitiesIncrease += currentCollectionPtr.Length()
   751  	}
   752  
   753  	it.AddCapacity(capacitiesIncrease)
   754  
   755  	for _, currentCollectionPtr := range anotherCollectionPtrsPtr {
   756  		if currentCollectionPtr == nil || currentCollectionPtr.IsEmpty() {
   757  			continue
   758  		}
   759  
   760  		it.items = append(
   761  			it.items,
   762  			currentCollectionPtr.items...)
   763  	}
   764  
   765  	return it
   766  }
   767  
   768  // AppendAnysLock Continue on nil
   769  func (it *CollectionPtr) AppendAnysLock(
   770  	anys ...interface{},
   771  ) *CollectionPtr {
   772  	if anys == nil {
   773  		return it
   774  	}
   775  
   776  	it.resizeForAnys(
   777  		&anys,
   778  		constants.One)
   779  
   780  	for _, any := range anys {
   781  		if any == nil {
   782  			continue
   783  		}
   784  
   785  		anyStr := fmt.Sprintf(constants.SprintValueFormat, any)
   786  
   787  		it.Lock()
   788  		it.items = append(
   789  			it.items,
   790  			&anyStr)
   791  		it.Unlock()
   792  	}
   793  
   794  	return it
   795  }
   796  
   797  // AppendAnys Continue on nil
   798  func (it *CollectionPtr) AppendAnys(
   799  	anys ...interface{},
   800  ) *CollectionPtr {
   801  	if anys == nil {
   802  		return it
   803  	}
   804  
   805  	it.resizeForAnys(
   806  		&anys,
   807  		constants.One)
   808  
   809  	for _, any := range anys {
   810  		if any == nil {
   811  			continue
   812  		}
   813  
   814  		anyStr := fmt.Sprintf(
   815  			constants.SprintValueFormat,
   816  			any,
   817  		)
   818  
   819  		it.items = append(
   820  			it.items,
   821  			&anyStr)
   822  	}
   823  
   824  	return it
   825  }
   826  
   827  // AppendAnysUsingFilter Skip on nil
   828  func (it *CollectionPtr) AppendAnysUsingFilter(
   829  	filter IsStringFilter,
   830  	anys ...interface{},
   831  ) *CollectionPtr {
   832  	if anys == nil {
   833  		return it
   834  	}
   835  
   836  	it.resizeForAnys(
   837  		&anys,
   838  		constants.One)
   839  
   840  	for i, any := range anys {
   841  		if any == nil {
   842  			continue
   843  		}
   844  
   845  		anyStr := fmt.Sprintf(
   846  			constants.SprintValueFormat,
   847  			any)
   848  
   849  		result, isKeep, isBreak := filter(anyStr, i)
   850  
   851  		if !isKeep {
   852  			continue
   853  		}
   854  
   855  		it.items = append(
   856  			it.items,
   857  			&result)
   858  
   859  		if isBreak {
   860  			return it
   861  		}
   862  	}
   863  
   864  	return it
   865  }
   866  
   867  // AppendAnysUsingFilterLock Skip on nil
   868  func (it *CollectionPtr) AppendAnysUsingFilterLock(
   869  	filter IsStringFilter,
   870  	anys ...interface{},
   871  ) *CollectionPtr {
   872  	if anys == nil {
   873  		return it
   874  	}
   875  
   876  	it.resizeForAnys(
   877  		&anys,
   878  		constants.One)
   879  
   880  	for i, any := range anys {
   881  		if any == nil {
   882  			continue
   883  		}
   884  
   885  		anyStr := fmt.Sprintf(constants.SprintValueFormat, any)
   886  		result, isKeep, isBreak := filter(anyStr, i)
   887  
   888  		if !isKeep {
   889  			continue
   890  		}
   891  
   892  		it.Lock()
   893  		it.items = append(
   894  			it.items,
   895  			&result)
   896  		it.Unlock()
   897  
   898  		if isBreak {
   899  			return it
   900  		}
   901  	}
   902  
   903  	return it
   904  }
   905  
   906  // AppendNonEmptyAnys Continue on nil
   907  func (it *CollectionPtr) AppendNonEmptyAnys(
   908  	anys ...interface{},
   909  ) *CollectionPtr {
   910  	if anys == nil {
   911  		return it
   912  	}
   913  
   914  	it.resizeForAnys(
   915  		&anys,
   916  		constants.One)
   917  
   918  	for _, any := range anys {
   919  		if any == nil {
   920  			continue
   921  		}
   922  
   923  		anyStr := fmt.Sprintf(constants.SprintValueFormat, any)
   924  		if anyStr == "" {
   925  			continue
   926  		}
   927  
   928  		it.items = append(
   929  			it.items,
   930  			&anyStr)
   931  	}
   932  
   933  	return it
   934  }
   935  
   936  // AddsPtr adds nil
   937  func (it *CollectionPtr) AddsPtr(
   938  	itemsPtr ...*string,
   939  ) *CollectionPtr {
   940  	if itemsPtr == nil {
   941  		return it
   942  	}
   943  
   944  	for _, str := range itemsPtr {
   945  		it.items = append(
   946  			it.items,
   947  			str)
   948  	}
   949  
   950  	return it
   951  }
   952  
   953  func (it *CollectionPtr) AddsNonEmptyPtr(
   954  	itemsPtr ...*string,
   955  ) *CollectionPtr {
   956  	if itemsPtr == nil {
   957  		return it
   958  	}
   959  
   960  	for _, str := range itemsPtr {
   961  		if str == nil || *str == "" {
   962  			continue
   963  		}
   964  
   965  		it.items = append(
   966  			it.items,
   967  			str)
   968  	}
   969  
   970  	return it
   971  }
   972  
   973  func (it *CollectionPtr) AddsNonEmptyPtrLock(
   974  	itemsPtr ...*string,
   975  ) *CollectionPtr {
   976  	if itemsPtr == nil {
   977  		return it
   978  	}
   979  
   980  	for _, str := range itemsPtr {
   981  		if str == nil || *str == "" {
   982  			continue
   983  		}
   984  
   985  		it.Lock()
   986  		it.items = append(
   987  			it.items,
   988  			str)
   989  		it.Unlock()
   990  	}
   991  
   992  	return it
   993  }
   994  
   995  func (it *CollectionPtr) UniqueBoolMapLock(
   996  	isAddEmptyStringOnNil bool,
   997  ) *map[string]bool {
   998  	it.Lock()
   999  	defer it.Unlock()
  1000  
  1001  	return it.UniqueBoolMap(isAddEmptyStringOnNil)
  1002  }
  1003  
  1004  // UniqueBoolMap continue on nil
  1005  func (it *CollectionPtr) UniqueBoolMap(
  1006  	isAddEmptyStringOnNil bool,
  1007  ) *map[string]bool {
  1008  	respectiveMap := make(
  1009  		map[string]bool,
  1010  		it.Length())
  1011  
  1012  	for _, item := range it.items {
  1013  		if item == nil && !isAddEmptyStringOnNil {
  1014  			continue
  1015  		} else if item == nil && isAddEmptyStringOnNil {
  1016  			respectiveMap[""] = true
  1017  
  1018  			continue
  1019  		}
  1020  
  1021  		//goland:noinspection GoNilness
  1022  		respectiveMap[*item] = true
  1023  	}
  1024  
  1025  	return &respectiveMap
  1026  }
  1027  
  1028  func (it *CollectionPtr) UniqueListPtr(
  1029  	isAddEmptyStringOnNil bool,
  1030  ) *[]string {
  1031  	boolMap := it.UniqueBoolMap(isAddEmptyStringOnNil)
  1032  	list := make([]string, len(*boolMap))
  1033  
  1034  	i := 0
  1035  	for str := range *boolMap {
  1036  		list[i] = str
  1037  		i++
  1038  	}
  1039  
  1040  	return &list
  1041  }
  1042  
  1043  func (it *CollectionPtr) UniqueListPtrLock(
  1044  	isAddEmptyStringOnNil bool,
  1045  ) *[]string {
  1046  	it.Lock()
  1047  	defer it.Unlock()
  1048  
  1049  	return it.UniqueListPtr(isAddEmptyStringOnNil)
  1050  }
  1051  
  1052  func (it *CollectionPtr) UniqueListLock(
  1053  	isAddEmptyStringOnNil bool,
  1054  ) []string {
  1055  	it.Lock()
  1056  	defer it.Unlock()
  1057  
  1058  	return it.UniqueList(isAddEmptyStringOnNil)
  1059  }
  1060  
  1061  func (it *CollectionPtr) UniqueList(
  1062  	isAddEmptyStringOnNil bool,
  1063  ) []string {
  1064  	return *it.UniqueListPtr(isAddEmptyStringOnNil)
  1065  }
  1066  
  1067  func (it *CollectionPtr) List() []*string {
  1068  	return it.items
  1069  }
  1070  
  1071  // ListCopyPtrLock returns a copy of the items
  1072  //
  1073  // must return a slice
  1074  func (it *CollectionPtr) ListCopyPtrLock() []*string {
  1075  	it.Lock()
  1076  	defer it.Unlock()
  1077  
  1078  	if it.IsEmpty() {
  1079  		return []*string{}
  1080  	}
  1081  
  1082  	newSlice := make([]*string, it.Length())
  1083  	copy(newSlice, it.items)
  1084  
  1085  	return newSlice
  1086  }
  1087  
  1088  // FilterSimpleArray must return a slice
  1089  func (it *CollectionPtr) FilterSimpleArray(
  1090  	filter IsStringPointerFilter,
  1091  ) *[]string {
  1092  	if it.IsEmpty() {
  1093  		return &([]string{})
  1094  	}
  1095  
  1096  	list := make([]string, constants.Zero, it.Length())
  1097  
  1098  	for i, element := range it.items {
  1099  		result, isKeep, isBreak := filter(element, i)
  1100  
  1101  		if isKeep && result != nil {
  1102  			list = append(list, *result)
  1103  		}
  1104  
  1105  		if isBreak {
  1106  			return &list
  1107  		}
  1108  	}
  1109  
  1110  	return &list
  1111  }
  1112  
  1113  // FilterSimpleArrayLock assumed wg is added to be done here.
  1114  //
  1115  // must return a slice
  1116  func (it *CollectionPtr) FilterSimpleArrayLock(
  1117  	filter IsStringPointerFilter,
  1118  	wg *sync.WaitGroup,
  1119  ) *[]string {
  1120  	copyList := it.ListCopyPtrLock()
  1121  	length := len(copyList)
  1122  	if length == 0 {
  1123  		return &([]string{})
  1124  	}
  1125  
  1126  	list := make([]string, constants.Zero, length)
  1127  
  1128  	for i, element := range it.items {
  1129  		result, isKeep, isBreak := filter(element, i)
  1130  
  1131  		if isKeep && result != nil {
  1132  			list = append(list, *result)
  1133  		}
  1134  
  1135  		if isBreak {
  1136  			return &list
  1137  		}
  1138  	}
  1139  
  1140  	wg.Done()
  1141  
  1142  	return &list
  1143  }
  1144  
  1145  // Filter must return a slice
  1146  func (it *CollectionPtr) Filter(
  1147  	filter IsStringPointerFilter,
  1148  ) *[]*string {
  1149  	if it.IsEmpty() {
  1150  		return &([]*string{})
  1151  	}
  1152  
  1153  	list := make([]*string, constants.Zero, it.Length())
  1154  
  1155  	for i, element := range it.items {
  1156  		result, isKeep, isBreak := filter(element, i)
  1157  
  1158  		if isKeep {
  1159  			list = append(list, result)
  1160  		}
  1161  
  1162  		if isBreak {
  1163  			return &list
  1164  		}
  1165  	}
  1166  
  1167  	return &list
  1168  }
  1169  
  1170  // FilterLock must return a slice
  1171  func (it *CollectionPtr) FilterLock(
  1172  	filter IsStringPointerFilter,
  1173  ) []*string {
  1174  	elements := it.ListCopyPtrLock()
  1175  	length := len(elements)
  1176  
  1177  	if length == 0 {
  1178  		return elements
  1179  	}
  1180  
  1181  	list := make([]*string, constants.Zero, length)
  1182  
  1183  	for i, element := range elements {
  1184  		result, isKeep, isBreak := filter(element, i)
  1185  
  1186  		if isKeep {
  1187  			list = append(list, result)
  1188  		}
  1189  
  1190  		if isBreak {
  1191  			return list
  1192  		}
  1193  	}
  1194  
  1195  	return list
  1196  }
  1197  
  1198  // FilteredCollection must return a items
  1199  func (it *CollectionPtr) FilteredCollection(
  1200  	filter IsStringPointerFilter,
  1201  ) *CollectionPtr {
  1202  	return New.CollectionPtr.StringsPtr(
  1203  		it.FilterSimpleArray(
  1204  			filter))
  1205  }
  1206  
  1207  // FilteredCollectionLock must return a items
  1208  func (it *CollectionPtr) FilteredCollectionLock(
  1209  	filter IsStringPointerFilter,
  1210  ) *CollectionPtr {
  1211  	it.Lock()
  1212  	defer it.Unlock()
  1213  
  1214  	return New.CollectionPtr.StringsPtr(
  1215  		it.FilterSimpleArray(filter),
  1216  	)
  1217  }
  1218  
  1219  // FilterPtrLock must return a slice
  1220  func (it *CollectionPtr) FilterPtrLock(
  1221  	filterPtr IsStringPointerFilter,
  1222  ) []*string {
  1223  	elements := it.ListCopyPtrLock()
  1224  	length := len(elements)
  1225  
  1226  	if length == 0 {
  1227  		return []*string{}
  1228  	}
  1229  
  1230  	list := make(
  1231  		[]*string,
  1232  		constants.Zero,
  1233  		length)
  1234  
  1235  	for i, element := range elements {
  1236  		result, isKeep, isBreak :=
  1237  			filterPtr(element, i)
  1238  
  1239  		if isKeep {
  1240  			list = append(
  1241  				list,
  1242  				result)
  1243  		}
  1244  
  1245  		if isBreak {
  1246  			return list
  1247  		}
  1248  	}
  1249  
  1250  	return list
  1251  }
  1252  
  1253  // FilterPtr must return a slice
  1254  func (it *CollectionPtr) FilterPtr(
  1255  	filterPtr IsStringPointerFilter,
  1256  ) []*string {
  1257  	if it.IsEmpty() {
  1258  		return []*string{}
  1259  	}
  1260  
  1261  	list := make([]*string, constants.Zero, it.Length())
  1262  
  1263  	for i, element := range it.items {
  1264  		result, isKeep, isBreak := filterPtr(element, i)
  1265  
  1266  		if isKeep {
  1267  			list = append(list, result)
  1268  		}
  1269  
  1270  		if isBreak {
  1271  			return list
  1272  		}
  1273  	}
  1274  
  1275  	return list
  1276  }
  1277  
  1278  // GetAllExceptCollection
  1279  //
  1280  // Get all items except the mentioned ones in itemsCollection.
  1281  // Always returns a copy of new strings.
  1282  // It is like set A - B
  1283  // Set A = this collection
  1284  // Set B = itemsCollection given in parameters.
  1285  func (it *CollectionPtr) GetAllExceptCollection(
  1286  	itemsCollection *CollectionPtr,
  1287  ) *[]*string {
  1288  	if itemsCollection == nil || itemsCollection.IsEmpty() {
  1289  		newItems := it.items
  1290  
  1291  		return &newItems
  1292  	}
  1293  
  1294  	finalList := make(
  1295  		[]*string,
  1296  		constants.Zero,
  1297  		it.Length())
  1298  
  1299  	for _, item := range it.items {
  1300  		if itemsCollection.HasPtr(item) {
  1301  			continue
  1302  		}
  1303  
  1304  		finalList = append(
  1305  			finalList,
  1306  			item)
  1307  	}
  1308  
  1309  	return &finalList
  1310  }
  1311  
  1312  // GetAllExcept Get all items except the mentioned ones.
  1313  // Always returns a copy of new strings.
  1314  // It is like set A - B
  1315  // Set A = this collection
  1316  // Set B = items given in parameters.
  1317  func (it *CollectionPtr) GetAllExcept(
  1318  	items []*string,
  1319  ) *[]*string {
  1320  	if items == nil {
  1321  		newItems := it.items
  1322  
  1323  		return &newItems
  1324  	}
  1325  
  1326  	newCollection := New.CollectionPtr.Default(
  1327  		items)
  1328  
  1329  	return it.GetAllExceptCollection(
  1330  		newCollection)
  1331  }
  1332  
  1333  // NonEmptySimpleListPtr must return a slice
  1334  func (it *CollectionPtr) NonEmptySimpleListPtr() *[]string {
  1335  	if it.IsEmpty() {
  1336  		return &([]string{})
  1337  	}
  1338  
  1339  	list := make([]string, constants.Zero, it.Length())
  1340  
  1341  	for _, element := range it.items {
  1342  		if element == nil || *element == "" {
  1343  			continue
  1344  		}
  1345  
  1346  		list = append(list, *element)
  1347  	}
  1348  
  1349  	return &list
  1350  }
  1351  
  1352  func (it *CollectionPtr) HashsetAsIs() *Hashset {
  1353  	if it.IsEmpty() {
  1354  		return New.Hashset.Empty()
  1355  	}
  1356  
  1357  	return New.Hashset.PointerStrings(
  1358  		it.items,
  1359  	)
  1360  }
  1361  
  1362  func (it *CollectionPtr) HashsetDoubleLength() *Hashset {
  1363  	if it.IsEmpty() {
  1364  		return New.Hashset.Empty()
  1365  	}
  1366  
  1367  	return New.Hashset.PointerStringsPtrOption(
  1368  		it.Length()*2,
  1369  		false,
  1370  		&it.items,
  1371  	)
  1372  }
  1373  
  1374  func (it *CollectionPtr) HashsetLock() *Hashset {
  1375  	items := it.ListCopyPtrLock()
  1376  
  1377  	return New.Hashset.PointerStrings(
  1378  		items,
  1379  	)
  1380  }
  1381  
  1382  func (it *CollectionPtr) SimpleList() []string {
  1383  	if it.IsEmpty() {
  1384  		return []string{}
  1385  	}
  1386  
  1387  	return *converters.PointerStringsToStrings(
  1388  		&it.items)
  1389  }
  1390  
  1391  func (it *CollectionPtr) SimpleListPtr() *[]string {
  1392  	if it.IsEmpty() {
  1393  		return &[]string{}
  1394  	}
  1395  
  1396  	return converters.PointerStringsToStrings(
  1397  		&it.items)
  1398  }
  1399  
  1400  func (it *CollectionPtr) SimpleListPtrLock() *[]string {
  1401  	it.Lock()
  1402  	defer it.Unlock()
  1403  
  1404  	return it.SimpleListPtr()
  1405  }
  1406  
  1407  // ListPtr direct return pointer
  1408  func (it *CollectionPtr) ListPtr() []*string {
  1409  	return it.items
  1410  }
  1411  
  1412  func (it *CollectionPtr) HasLock(str string) bool {
  1413  	it.Lock()
  1414  	defer it.Unlock()
  1415  
  1416  	return it.Has(str)
  1417  }
  1418  
  1419  func (it *CollectionPtr) Has(str string) bool {
  1420  	if it.IsEmpty() {
  1421  		return false
  1422  	}
  1423  
  1424  	for _, element := range it.items {
  1425  		if element == nil {
  1426  			continue
  1427  		}
  1428  
  1429  		if *element == str {
  1430  			return true
  1431  		}
  1432  	}
  1433  
  1434  	return false
  1435  }
  1436  
  1437  func (it *CollectionPtr) HasPtr(str *string) bool {
  1438  	if it.IsEmpty() {
  1439  		return false
  1440  	}
  1441  
  1442  	for _, element := range it.items {
  1443  		if element == nil && str == nil {
  1444  			return true
  1445  		}
  1446  
  1447  		if element == nil {
  1448  			continue
  1449  		}
  1450  
  1451  		if *element == *str {
  1452  			return true
  1453  		}
  1454  	}
  1455  
  1456  	return false
  1457  }
  1458  
  1459  func (it *CollectionPtr) HasUsingSensitivity(
  1460  	str string, isCaseSensitive bool,
  1461  ) bool {
  1462  	if it.IsEmpty() {
  1463  		return false
  1464  	}
  1465  
  1466  	if isCaseSensitive {
  1467  		return it.Has(str)
  1468  	}
  1469  
  1470  	for _, element := range it.items {
  1471  		if element == nil {
  1472  			continue
  1473  		}
  1474  
  1475  		if strings.EqualFold(*element, str) {
  1476  			return true
  1477  		}
  1478  	}
  1479  
  1480  	return false
  1481  }
  1482  
  1483  func (it *CollectionPtr) HasAll(
  1484  	items ...string,
  1485  ) bool {
  1486  	if it.IsEmpty() {
  1487  		return false
  1488  	}
  1489  
  1490  	for _, element := range items {
  1491  		if !it.IsContainsPtr(&element) {
  1492  			return false
  1493  		}
  1494  	}
  1495  
  1496  	return true
  1497  }
  1498  
  1499  func (it *CollectionPtr) First() string {
  1500  	return *it.items[0]
  1501  }
  1502  
  1503  func (it *CollectionPtr) Single() string {
  1504  	length := it.Length()
  1505  	if length != 1 {
  1506  		errcore.LengthShouldBeEqualToType.HandleUsingPanic("1", length)
  1507  	}
  1508  
  1509  	return *it.items[0]
  1510  }
  1511  
  1512  func (it *CollectionPtr) Last() string {
  1513  	length := it.Length()
  1514  
  1515  	return *it.items[length-1]
  1516  }
  1517  
  1518  func (it *CollectionPtr) LastOrDefault() string {
  1519  	length := it.Length()
  1520  
  1521  	if length == 0 {
  1522  		return constants.EmptyString
  1523  	}
  1524  
  1525  	return *it.items[length-1]
  1526  }
  1527  
  1528  func (it *CollectionPtr) FirstOrDefault() string {
  1529  	if it.IsEmpty() {
  1530  		return constants.EmptyString
  1531  	}
  1532  
  1533  	return *it.items[0]
  1534  }
  1535  
  1536  // Take use One based index
  1537  func (it *CollectionPtr) Take(
  1538  	take int,
  1539  ) *CollectionPtr {
  1540  	length := it.Length()
  1541  
  1542  	if length <= take {
  1543  		return it
  1544  	}
  1545  
  1546  	if take == 0 {
  1547  		return Empty.CollectionPtr()
  1548  	}
  1549  
  1550  	list := it.items[:take]
  1551  
  1552  	return New.CollectionPtr.Default(
  1553  		list,
  1554  	)
  1555  }
  1556  
  1557  // Skip use One based index
  1558  func (it *CollectionPtr) Skip(
  1559  	skip int,
  1560  ) *CollectionPtr {
  1561  	length := it.Length()
  1562  
  1563  	if length < skip {
  1564  		errcore.
  1565  			LengthShouldBeEqualToType.
  1566  			HandleUsingPanic(
  1567  				"Length is lower than skip value. Skip:",
  1568  				skip)
  1569  	}
  1570  
  1571  	if skip == 0 {
  1572  		return it
  1573  	}
  1574  
  1575  	list := it.items[skip:]
  1576  
  1577  	return New.CollectionPtr.Default(
  1578  		list,
  1579  	)
  1580  }
  1581  
  1582  func (it *CollectionPtr) GetPagesSize(
  1583  	eachPageSize int,
  1584  ) int {
  1585  	length := it.Length()
  1586  
  1587  	pagesPossibleFloat := float64(length) / float64(eachPageSize)
  1588  	pagesPossibleCeiling := int(math.Ceil(pagesPossibleFloat))
  1589  
  1590  	return pagesPossibleCeiling
  1591  }
  1592  
  1593  func (it *CollectionPtr) GetPagedCollection(
  1594  	eachPageSize int,
  1595  ) *CollectionsOfCollectionPtr {
  1596  	length := it.Length()
  1597  
  1598  	if length < eachPageSize {
  1599  		return New.CollectionsOfCollectionPtr.PointerStrings(
  1600  			it.items,
  1601  		)
  1602  	}
  1603  
  1604  	pagesPossibleFloat := float64(length) / float64(eachPageSize)
  1605  	pagesPossibleCeiling := int(math.Ceil(pagesPossibleFloat))
  1606  	collectionOfCollection := New.CollectionsOfCollectionPtr.Cap(
  1607  		pagesPossibleCeiling)
  1608  
  1609  	for i := 1; i <= pagesPossibleCeiling; i++ {
  1610  		pagedCollection := it.GetSinglePageCollection(
  1611  			eachPageSize, i)
  1612  
  1613  		collectionOfCollection.Adds(
  1614  			pagedCollection)
  1615  	}
  1616  
  1617  	return collectionOfCollection
  1618  }
  1619  
  1620  // GetSinglePageCollection PageIndex is one based index. Should be above or equal 1
  1621  func (it *CollectionPtr) GetSinglePageCollection(
  1622  	eachPageSize int,
  1623  	pageIndex int,
  1624  ) *CollectionPtr {
  1625  	length := it.Length()
  1626  
  1627  	if length < eachPageSize {
  1628  		return it
  1629  	}
  1630  
  1631  	/**
  1632  	 * eachPageItems = 10
  1633  	 * pageIndex = 4
  1634  	 * skipItems = 10 * (4 - 1) = 30
  1635  	 */
  1636  	skipItems := eachPageSize * (pageIndex - 1)
  1637  	if skipItems < 0 {
  1638  		errcore.
  1639  			CannotBeNegativeIndexType.
  1640  			HandleUsingPanic(
  1641  				"pageIndex cannot be negative or zero.",
  1642  				pageIndex)
  1643  	}
  1644  
  1645  	endingIndex := skipItems + eachPageSize
  1646  
  1647  	if endingIndex > length {
  1648  		endingIndex = length
  1649  	}
  1650  
  1651  	list := it.items[skipItems:endingIndex]
  1652  
  1653  	return New.CollectionPtr.PointerStrings(
  1654  		list,
  1655  	)
  1656  }
  1657  
  1658  func (it *CollectionPtr) IndexAt(
  1659  	index int,
  1660  ) string {
  1661  	return *it.items[index]
  1662  }
  1663  
  1664  func (it *CollectionPtr) SafePointerIndexAt(
  1665  	index int,
  1666  ) *string {
  1667  	length := it.Length()
  1668  	if length-1 < index {
  1669  		return nil
  1670  	}
  1671  
  1672  	return it.items[index]
  1673  }
  1674  
  1675  func (it *CollectionPtr) SafePointerIndexAtUsingLength(
  1676  	length, index int,
  1677  ) *string {
  1678  	if length-1 < index {
  1679  		return nil
  1680  	}
  1681  
  1682  	return it.items[index]
  1683  }
  1684  
  1685  func (it *CollectionPtr) SafeIndexAtUsingLength(
  1686  	defaultString string, length, index int,
  1687  ) string {
  1688  	if length-1 < index {
  1689  		return defaultString
  1690  	}
  1691  
  1692  	pointer := it.items[index]
  1693  
  1694  	if pointer == nil {
  1695  		return defaultString
  1696  	}
  1697  
  1698  	return *pointer
  1699  }
  1700  
  1701  // SortedListAsc Creates new doesn't modify current collection
  1702  func (it *CollectionPtr) SortedListAsc() *[]string {
  1703  	if it.IsEmpty() {
  1704  		return &[]string{}
  1705  	}
  1706  
  1707  	list := it.SimpleListPtr()
  1708  	sort.Strings(*list)
  1709  
  1710  	return list
  1711  }
  1712  
  1713  // SortedAsc mutates current collection
  1714  func (it *CollectionPtr) SortedAsc() *CollectionPtr {
  1715  	if it.IsEmpty() {
  1716  		return it
  1717  	}
  1718  
  1719  	strsort.QuickPtr(&it.items)
  1720  
  1721  	return it
  1722  }
  1723  
  1724  // SortedAscLock mutates current collection
  1725  func (it *CollectionPtr) SortedAscLock() *CollectionPtr {
  1726  	if it.IsEmptyLock() {
  1727  		return it
  1728  	}
  1729  
  1730  	it.Lock()
  1731  	defer it.Unlock()
  1732  
  1733  	strsort.QuickPtr(&it.items)
  1734  
  1735  	return it
  1736  }
  1737  
  1738  // SortedListDsc Creates new one.
  1739  func (it *CollectionPtr) SortedListDsc() *[]string {
  1740  	list := it.SortedListAsc()
  1741  	length := len(*list)
  1742  	mid := length / 2
  1743  
  1744  	for i := 0; i < mid; i++ {
  1745  		temp := (*list)[i]
  1746  		(*list)[i] = (*list)[length-1-i]
  1747  		(*list)[length-1-i] = temp
  1748  	}
  1749  
  1750  	return list
  1751  }
  1752  
  1753  // SortedDsc mutates itself.
  1754  func (it *CollectionPtr) SortedDsc() *CollectionPtr {
  1755  	list := it.items
  1756  	length := len(list)
  1757  	mid := length / 2
  1758  
  1759  	for i := 0; i < mid; i++ {
  1760  		temp := list[i]
  1761  		list[i] = list[length-1-i]
  1762  		list[length-1-i] = temp
  1763  	}
  1764  
  1765  	return it
  1766  }
  1767  
  1768  func (it *CollectionPtr) IsContainsPtr(
  1769  	item *string,
  1770  ) bool {
  1771  	if item == nil || it.IsEmpty() {
  1772  		return false
  1773  	}
  1774  
  1775  	for _, element := range it.items {
  1776  		if element == nil {
  1777  			continue
  1778  		}
  1779  
  1780  		if *element == *item {
  1781  			return true
  1782  		}
  1783  	}
  1784  
  1785  	return false
  1786  }
  1787  
  1788  // GetHashsetPlusHasAll nil will return false.
  1789  func (it *CollectionPtr) GetHashsetPlusHasAll(
  1790  	items []string,
  1791  ) (*Hashset, bool) {
  1792  	hashset := it.HashsetAsIs()
  1793  
  1794  	if items == nil || it.IsEmpty() {
  1795  		return hashset, false
  1796  	}
  1797  
  1798  	return hashset, hashset.HasAllStrings(items)
  1799  }
  1800  
  1801  // IsContainsAllPtr nil will return false.
  1802  func (it *CollectionPtr) IsContainsAllPtr(
  1803  	items *[]string,
  1804  ) bool {
  1805  	if items == nil {
  1806  		return false
  1807  	}
  1808  
  1809  	if it.IsEmpty() {
  1810  		return false
  1811  	}
  1812  
  1813  	for _, item := range *items {
  1814  		if !it.IsContainsPtr(&item) {
  1815  			return false
  1816  		}
  1817  	}
  1818  
  1819  	return true
  1820  }
  1821  
  1822  // IsContainsAll nil will return false.
  1823  func (it *CollectionPtr) IsContainsAll(
  1824  	items ...string,
  1825  ) bool {
  1826  	if items == nil {
  1827  		return false
  1828  	}
  1829  
  1830  	return it.IsContainsAllPtr(&items)
  1831  }
  1832  
  1833  // IsContainsAllLock
  1834  //
  1835  // nil will return false.
  1836  func (it *CollectionPtr) IsContainsAllLock(
  1837  	items ...string,
  1838  ) bool {
  1839  	it.Lock()
  1840  	defer it.Unlock()
  1841  
  1842  	if items == nil {
  1843  		return false
  1844  	}
  1845  
  1846  	return it.IsContainsAllPtr(&items)
  1847  }
  1848  
  1849  func (it *CollectionPtr) CharCollectionPtrMap() *CharCollectionMap {
  1850  	length := it.Length()
  1851  	lengthByFourBestGuess := length / 4
  1852  	runeMap := New.CharCollectionMap.CapSelfCap(
  1853  		length,
  1854  		lengthByFourBestGuess)
  1855  
  1856  	for _, item := range it.items {
  1857  		runeMap.AddStringPtr(item)
  1858  	}
  1859  
  1860  	return runeMap
  1861  }
  1862  
  1863  func (it *CollectionPtr) SummaryString(
  1864  	sequence int,
  1865  ) string {
  1866  	header := fmt.Sprintf(
  1867  		summaryOfCharCollectionMapLengthFormat,
  1868  		it,
  1869  		it.Length(),
  1870  		sequence)
  1871  
  1872  	return it.SummaryStringWithHeader(header)
  1873  }
  1874  
  1875  func (it *CollectionPtr) SummaryStringWithHeader(
  1876  	header string,
  1877  ) string {
  1878  	if it.IsEmpty() {
  1879  		return header + commonJoiner + NoElements
  1880  	}
  1881  
  1882  	return header + it.String()
  1883  }
  1884  
  1885  func (it *CollectionPtr) String() string {
  1886  	if it.IsEmpty() {
  1887  		return commonJoiner + NoElements
  1888  	}
  1889  
  1890  	return commonJoiner +
  1891  		strings.Join(
  1892  			*it.SimpleListPtr(),
  1893  			commonJoiner)
  1894  }
  1895  
  1896  func (it *CollectionPtr) StringLock() string {
  1897  	if it.IsEmptyLock() {
  1898  		return commonJoiner + NoElements
  1899  	}
  1900  
  1901  	it.Lock()
  1902  	defer it.Unlock()
  1903  
  1904  	return commonJoiner +
  1905  		strings.Join(
  1906  			*it.SimpleListPtr(),
  1907  			commonJoiner)
  1908  }
  1909  
  1910  func (it *Collection) Join(
  1911  	joiner string,
  1912  ) string {
  1913  	if it.IsEmpty() {
  1914  		return ""
  1915  	}
  1916  
  1917  	return strings.Join(it.items, joiner)
  1918  }
  1919  
  1920  func (it *Collection) JoinWith(
  1921  	joiner string,
  1922  ) string {
  1923  	if it.IsEmpty() {
  1924  		return ""
  1925  	}
  1926  
  1927  	return joiner + strings.Join(it.items, joiner)
  1928  }
  1929  
  1930  func (it *CollectionPtr) AddCapacity(
  1931  	capacities ...int,
  1932  ) *CollectionPtr {
  1933  	if capacities == nil || len(capacities) == 0 {
  1934  		return it
  1935  	}
  1936  
  1937  	currentCapacity := it.Capacity()
  1938  
  1939  	for _, capacity := range capacities {
  1940  		currentCapacity += capacity
  1941  	}
  1942  
  1943  	return it.Resize(currentCapacity)
  1944  }
  1945  
  1946  // Resize Only resize if capacity is bigger than the current one
  1947  // Warning changes current pointer with new one.
  1948  func (it *CollectionPtr) Resize(
  1949  	newCapacity int,
  1950  ) *CollectionPtr {
  1951  	capacity := it.Capacity()
  1952  	if capacity >= newCapacity {
  1953  		return it
  1954  	}
  1955  
  1956  	newItems := make([]*string, it.Length(), newCapacity)
  1957  	copy(newItems, it.items)
  1958  
  1959  	it.items = newItems
  1960  
  1961  	return it
  1962  }
  1963  
  1964  func (it *CollectionPtr) Joins(
  1965  	separator string,
  1966  	items ...string,
  1967  ) string {
  1968  	newItems := make([]string, constants.Zero, it.Length()+len(items))
  1969  
  1970  	for _, item := range it.items {
  1971  		if item == nil {
  1972  			continue
  1973  		}
  1974  
  1975  		newItems = append(newItems, *item)
  1976  	}
  1977  
  1978  	if len(items) == 0 {
  1979  		return strings.Join(newItems, separator)
  1980  	}
  1981  
  1982  	for _, item := range items {
  1983  		newItems = append(newItems, item)
  1984  	}
  1985  
  1986  	return strings.Join(newItems, separator)
  1987  }
  1988  
  1989  func (it *CollectionPtr) JsonModel() *CollectionPtrDataModel {
  1990  	return &CollectionPtrDataModel{
  1991  		Items: it.items,
  1992  	}
  1993  }
  1994  
  1995  func (it *CollectionPtr) JsonModelAny() interface{} {
  1996  	return it.JsonModel()
  1997  }
  1998  
  1999  func (it *CollectionPtr) MarshalJSON() ([]byte, error) {
  2000  	return json.Marshal(*it.JsonModel())
  2001  }
  2002  
  2003  func (it *CollectionPtr) UnmarshalJSON(
  2004  	data []byte,
  2005  ) error {
  2006  	var dataModel CollectionPtrDataModel
  2007  
  2008  	err := json.Unmarshal(data, &dataModel)
  2009  
  2010  	if err == nil {
  2011  		it.items = dataModel.Items
  2012  	}
  2013  
  2014  	return err
  2015  }
  2016  
  2017  func (it CollectionPtr) Json() corejson.Result {
  2018  	return corejson.New(it)
  2019  }
  2020  
  2021  func (it CollectionPtr) JsonPtr() *corejson.Result {
  2022  	return corejson.NewPtr(it)
  2023  }
  2024  
  2025  func (it *CollectionPtr) ParseInjectUsingJson(
  2026  	jsonResult *corejson.Result,
  2027  ) (*CollectionPtr, error) {
  2028  	err := jsonResult.Unmarshal(it)
  2029  
  2030  	if err != nil {
  2031  		return nil, err
  2032  	}
  2033  
  2034  	return it, nil
  2035  }
  2036  
  2037  // ParseInjectUsingJsonMust Panic if error
  2038  func (it *CollectionPtr) ParseInjectUsingJsonMust(
  2039  	jsonResult *corejson.Result,
  2040  ) *CollectionPtr {
  2041  	newUsingJson, err :=
  2042  		it.ParseInjectUsingJson(jsonResult)
  2043  
  2044  	if err != nil {
  2045  		panic(err)
  2046  	}
  2047  
  2048  	return newUsingJson
  2049  }
  2050  
  2051  func (it *CollectionPtr) JsonParseSelfInject(
  2052  	jsonResult *corejson.Result,
  2053  ) error {
  2054  	_, err := it.ParseInjectUsingJson(
  2055  		jsonResult,
  2056  	)
  2057  
  2058  	return err
  2059  }
  2060  
  2061  func (it *CollectionPtr) AsJsoner() corejson.Jsoner {
  2062  	return it
  2063  }
  2064  
  2065  func (it *CollectionPtr) AsJsonParseSelfInjector() corejson.JsonParseSelfInjector {
  2066  	return it
  2067  }
  2068  
  2069  func (it *CollectionPtr) AsJsonMarshaller() corejson.JsonMarshaller {
  2070  	return it
  2071  }
  2072  
  2073  func (it *CollectionPtr) JsonString() (jsonString string, err error) {
  2074  	return it.JsonPtr().JsonString(), nil
  2075  }
  2076  
  2077  func (it *CollectionPtr) JsonStringMust() string {
  2078  	return it.JsonPtr().JsonString()
  2079  }
  2080  
  2081  func (it *CollectionPtr) AsJsonContractsBinder() corejson.JsonContractsBinder {
  2082  	return it
  2083  }