Package de.alpharogroup.collections.list
Class ListExtensions
- java.lang.Object
-
- de.alpharogroup.collections.list.ListExtensions
-
public final class ListExtensions extends java.lang.ObjectExtensions class for use withListobjects.
-
-
Constructor Summary
Constructors Constructor Description ListExtensions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> booleancontainAtleastOneObject(java.util.List<T> toSearch, java.util.List<T> search)This Method look in the List toSearch if at least one Object exists in the List search.static java.util.List<java.util.List<java.lang.Integer>>getAllCombinations(@NonNull java.util.List<java.lang.Integer> possibleNumbers, int combinationSize)Gets all possible combinations from the given list ofIntegerobjectsstatic <T> java.util.List<java.util.List<T>>getCombinations(@NonNull java.util.List<T> possibleValues, int combinationSize)Gets all possible combinations from the given liststatic <T> TgetFirst(java.util.List<T> list)Gets the first object from the given List.static <T> TgetLast(java.util.List<T> list)Gets the last object from the given List.static <T> ModifiedCollections<T>getModifiedCollections(java.util.Collection<T> previous, java.util.Collection<T> next)Gets the modified lists. finding from an old list which elements have been removed and which have been added.static <T> java.util.List<T>getSameElementsFromLists(java.util.List<T> toSearch, java.util.List<T> search)This method decorates the retainAll method and returns the result in a new liststatic <T> booleanhasNext(@NonNull java.util.List<T> list, T element)Checks if the givenListhas a next element from the given elementstatic <T> booleanhasPrevious(@NonNull java.util.List<T> list, T element)Checks if the givenListhas a next element from the given elementstatic <T> booleanisEqualListOfArrays(java.util.List<T[]> one, java.util.List<T[]> other)Compare the given twoCollectionobjects in equality.static <T> booleanisFirst(java.util.List<T> list, T element)Checks if the given element is the first in the given list.static <T> booleanisLast(java.util.List<T> list, T element)Checks if the given element is the last in the given list.static <T> java.util.List<T>rearrange(T element, @NonNull java.util.List<T> listToResort, int rearrangeToIndex)Rearrange the order from the givenListto the given rearranged indexstatic <T> TremoveFirst(java.util.List<T> list)Removes the first object from the given List.static <T> TremoveLast(java.util.List<T> list)Removes the last object from the given List.static <T> java.util.List<T>removeLastValues(java.util.List<T> v, int remove)The Method removeLastValues(ArrayList, int) remove the last Values.static <T> java.util.List<T>revertOrder(java.util.List<T> listToRevert)Reverts the order from the given List.static <T> voidshuffle(java.util.List<T> source, java.util.List<T> destination, int[] selectedElements)Shuffle selected elements in the source list to the destination list from the given indexes in the array selectedElements.static <T> voidsortByProperty(java.util.List<T> list, java.lang.String property, boolean ascending)Sort over the given property.static <T> java.util.List<java.util.List<T>>splitToParts(java.util.Collection<T> collection, int size)Splits the givenCollectionto parts to the specified size and returns a list with the parts.static <T> T[]toArray(@NonNull java.util.List<T> list)To array.static <T> T[]toArray(T... elements)To array.static <T> java.util.List<T>toList(java.util.Enumeration<T> enumaration)Converts the given enumaration to a Vector.static <T> java.util.List<T>toList(java.util.Set<T> set)Converts the givenSetto a list.static <T> java.lang.Object[]toObjectArray(T... elements)Converts the given parameter elements to an object array.
-
-
-
Method Detail
-
containAtleastOneObject
public static <T> boolean containAtleastOneObject(java.util.List<T> toSearch, java.util.List<T> search)This Method look in the List toSearch if at least one Object exists in the List search.- Type Parameters:
T- the generic type- Parameters:
toSearch- The List to search.search- The List to inspect.- Returns:
- Returns true if there is at least one Object equal from the two List otherwise false.
-
getFirst
public static <T> T getFirst(java.util.List<T> list)
Gets the first object from the given List.- Type Parameters:
T- the generic type- Parameters:
list- the List.- Returns:
- Returns the first object from the given List or null if the List is empty or null.
-
getLast
public static <T> T getLast(java.util.List<T> list)
Gets the last object from the given List.- Type Parameters:
T- the generic type- Parameters:
list- the List.- Returns:
- Returns the last object from the given List or null if the List is empty or null.
-
getModifiedCollections
public static <T> ModifiedCollections<T> getModifiedCollections(java.util.Collection<T> previous, java.util.Collection<T> next)
Gets the modified lists. finding from an old list which elements have been removed and which have been added.- Type Parameters:
T- the generic type- Parameters:
previous- the previous collection i.e. the collection from database.next- the next collection i.e. the current collection in the view.- Returns:
- 's the ModifiedLists in which the lists are keeped.
-
getSameElementsFromLists
public static <T> java.util.List<T> getSameElementsFromLists(java.util.List<T> toSearch, java.util.List<T> search)This method decorates the retainAll method and returns the result in a new list- Type Parameters:
T- the generic type- Parameters:
toSearch- The list to searchsearch- the list to inspect- Returns:
- the new list with the intersection of the objects
-
isEqualListOfArrays
public static <T> boolean isEqualListOfArrays(java.util.List<T[]> one, java.util.List<T[]> other)Compare the given twoCollectionobjects in equality.- Type Parameters:
T- the generic type of the elements- Parameters:
one- the oneother- the other- Returns:
- true, if the given two
Collectionobjects are equal otherwise false
-
isFirst
public static <T> boolean isFirst(java.util.List<T> list, T element)Checks if the given element is the first in the given list.- Type Parameters:
T- the generic type- Parameters:
list- the listelement- the element- Returns:
- true if the given element is the first otherwise false
-
isLast
public static <T> boolean isLast(java.util.List<T> list, T element)Checks if the given element is the last in the given list.- Type Parameters:
T- the generic type- Parameters:
list- the listelement- the element- Returns:
- true if the given element is the last otherwise false
-
hasNext
public static <T> boolean hasNext(@NonNull @NonNull java.util.List<T> list, T element)Checks if the givenListhas a next element from the given element- Type Parameters:
T- the generic type- Parameters:
list- the listelement- the element- Returns:
- true, if successful
-
hasPrevious
public static <T> boolean hasPrevious(@NonNull @NonNull java.util.List<T> list, T element)Checks if the givenListhas a next element from the given element- Type Parameters:
T- the generic type- Parameters:
list- the listelement- the element- Returns:
- true, if successful
-
rearrange
public static <T> java.util.List<T> rearrange(@NonNull T element, @NonNull @NonNull java.util.List<T> listToResort, int rearrangeToIndex)Rearrange the order from the givenListto the given rearranged index- Type Parameters:
T- the generic type of the elements- Parameters:
listToResort- the list to resortelement- the element to rearrangerearrangeToIndex- the rearrange to index- Returns:
- the rearranged
List
-
removeFirst
public static <T> T removeFirst(java.util.List<T> list)
Removes the first object from the given List.- Type Parameters:
T- the generic type- Parameters:
list- the List.- Returns:
- Removes and returns the first object from the given List or null if the List is empty or null.
-
removeLast
public static <T> T removeLast(java.util.List<T> list)
Removes the last object from the given List.- Type Parameters:
T- the generic type- Parameters:
list- the List.- Returns:
- Removes and returns the last object from the given List or null if the List is empty or null.
-
removeLastValues
public static <T> java.util.List<T> removeLastValues(java.util.List<T> v, int remove)The Method removeLastValues(ArrayList, int) remove the last Values.- Type Parameters:
T- the generic type- Parameters:
v- The Vector with the received Messages.remove- How much to remove.- Returns:
- the list
-
revertOrder
public static <T> java.util.List<T> revertOrder(java.util.List<T> listToRevert)
Reverts the order from the given List.- Type Parameters:
T- the generic type- Parameters:
listToRevert- The List to revert.- Returns:
- The reverted List.
-
shuffle
public static <T> void shuffle(java.util.List<T> source, java.util.List<T> destination, int[] selectedElements)Shuffle selected elements in the source list to the destination list from the given indexes in the array selectedElements.- Type Parameters:
T- the generic type- Parameters:
source- the sourcedestination- the destinationselectedElements- the selected elements
-
sortByProperty
public static <T> void sortByProperty(java.util.List<T> list, java.lang.String property, boolean ascending)Sort over the given property. Note: the property should be implement the Comparable interface.- Type Parameters:
T- the generic type of the list- Parameters:
list- the list to sort.property- the property to sort.ascending- if true the sort will be ascending ohterwise descending.
-
splitToParts
public static <T> java.util.List<java.util.List<T>> splitToParts(java.util.Collection<T> collection, int size)Splits the givenCollectionto parts to the specified size and returns a list with the parts.- Type Parameters:
T- the generic type- Parameters:
collection- The collection to splitsize- How to split.- Returns:
- a List with the splited Parts
-
toArray
@SafeVarargs public static <T> T[] toArray(T... elements)
To array.- Type Parameters:
T- the generic type- Parameters:
elements- the elements- Returns:
- the t[]
-
toArray
public static <T> T[] toArray(@NonNull @NonNull java.util.List<T> list)To array.- Type Parameters:
T- the generic type- Parameters:
list- the list- Returns:
- the array or null if the list is empty
-
toList
public static <T> java.util.List<T> toList(java.util.Enumeration<T> enumaration)
Converts the given enumaration to a Vector.- Type Parameters:
T- the generic type- Parameters:
enumaration- The Enumeration to convert.- Returns:
- A new Vector with the content of the given Enumeration.
-
toList
public static <T> java.util.List<T> toList(java.util.Set<T> set)
Converts the givenSetto a list.- Type Parameters:
T- the generic type of the elements- Parameters:
set- the set- Returns:
- A new list
-
toObjectArray
@SafeVarargs public static <T> java.lang.Object[] toObjectArray(T... elements)
Converts the given parameter elements to an object array.- Type Parameters:
T- the generic type- Parameters:
elements- The elements that will be in the returned object array- Returns:
- An Object array.
-
getAllCombinations
public static java.util.List<java.util.List<java.lang.Integer>> getAllCombinations(@NonNull @NonNull java.util.List<java.lang.Integer> possibleNumbers, int combinationSize)Gets all possible combinations from the given list ofIntegerobjects- Parameters:
possibleNumbers- the possible numberscombinationSize- the size of the combination to generate- Returns:
- all possible combinations from the given list of
Integerobjects
-
getCombinations
public static <T> java.util.List<java.util.List<T>> getCombinations(@NonNull @NonNull java.util.List<T> possibleValues, int combinationSize)Gets all possible combinations from the given list- Type Parameters:
T- the generic type of the elements in the list- Parameters:
combinationSize- the size of the elements of the combinations to generatepossibleValues- the list with the element values- Returns:
- all possible combinations from the given list
-
-