Package net.apartium.cocoabeans
Class CollectionHelpers
java.lang.Object
net.apartium.cocoabeans.CollectionHelpers
Helper class to aid working with java collections
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <E> voidaddElementSorted(List<E> list, E element, Comparator<E> comparator) static booleancontainsStartsWith(Collection<String> collection, String value, String appendToElement) Checks whether given string contains AT LEAST ONE OF the values in given collectionstatic booleanequalsArray(Object[] arr0, Object[] arr1) Checks for array content equality, regardless of orderstatic booleanequalsCollections(Collection<?> a, Collection<?> b) Determines whether two collections are equal, and in the same orderstatic booleanequalsList(List<?> list0, List<?> list1) Checks for list content equality, regardless of orderstatic <T> booleanisSorted(List<T> list, Comparator<? super T> comparator) Determines whether a list is sorted according to provided comparatorstatic <K,V> void Put all entries from other map into map if key is not presentstatic <E> EpickEntry(Collection<E> collection, int index) Attempts to pick entry from Collection by index.static <E> ErandomEntry(Collection<E> collection, Random random) Picks a random entry from collectionrange(double start, double end, double step) Construct a new instance with values consisting of specified rangerange(int start, int end, int step) Construct a new instance with values consisting of specified range
-
Constructor Details
-
CollectionHelpers
public CollectionHelpers()
-
-
Method Details
-
randomEntry
Picks a random entry from collection- Type Parameters:
E- collection element type- Parameters:
collection- collection- Returns:
- null if collection is empty, the first entry if there is only one or a random entry
-
pickEntry
Attempts to pick entry from Collection by index. WARNING: Resulting entry of this object is not guaranteed to be the same across multiple attempts even if given arguments are the same.- Type Parameters:
E- collection type- Parameters:
collection- collectionindex- index to pick- Returns:
- attempt to pick given element from set
-
containsStartsWith
public static boolean containsStartsWith(Collection<String> collection, String value, String appendToElement) Checks whether given string contains AT LEAST ONE OF the values in given collection- Parameters:
collection- collectionvalue- stringappendToElement- string to append to the beginning of each collection element- Returns:
- true if string contains at least one of the values in given collection, else false.
-
equalsArray
Checks for array content equality, regardless of order- Parameters:
arr0- first arrayarr1- second array- Returns:
- true if equals, else false
-
equalsList
Checks for list content equality, regardless of order- Parameters:
list0- first listlist1- second list- Returns:
- true if equals, else false
-
equalsCollections
Determines whether two collections are equal, and in the same order- Parameters:
a- the first collectionb- the second collection- Returns:
- true if equals, otherwise false
-
range
Construct a new instance with values consisting of specified range- Parameters:
start- range startend- range endstep- amount to step each time- Returns:
- a new linked list instance
-
range
Construct a new instance with values consisting of specified range- Parameters:
start- range startend- range endstep- amount to step each time- Returns:
- a new instance of list that has elements from start to end with jumps of step
-
addElementSorted
-
mergeInto
Put all entries from other map into map if key is not present- Type Parameters:
K- key typeV- value type- Parameters:
map- map to put intoother- map to get entries from
-
isSorted
@AvailableSince("0.0.39") public static <T> boolean isSorted(List<T> list, Comparator<? super T> comparator) Determines whether a list is sorted according to provided comparator- Type Parameters:
T- list element type- Parameters:
list- list to check againstcomparator- comparator- Returns:
- true if sorted, else false
-