Class HCollection
- java.lang.Object
-
- com.g2forge.alexandria.java.core.helpers.HCollection
-
public final class HCollection extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <K,C extends Collection<V>,V>
voidadd(Map<K,C> map, Supplier<? extends C> constructor, K key, V value)
static <T> Map<T,Integer>
asIndexMap(List<T> list)
static <T> List<T>
asList(Collection<T> collection)
static <T> List<T>
asList(T... elements)
static <T> List<T>
asListNonNull(T... elements)
static <T> List<T>
asListRepeated(int count, T element)
static <T extends Enum<T>>
EnumSet<T>asSet(Class<T> type, T... elements)
static <T> Set<T>
asSet(T... elements)
static <T> List<T>
concatenate(Collection<? extends T>... collections)
static <T> Set<T>
difference(Collection<? extends T> minuend, Collection<? extends T> subtrahend)
static <T> Collection<T>
difference(Collection<? extends T> minuend, T... subtrahend)
static <T> List<T>
emptyList()
static <T> Set<T>
emptySet()
static <T> Collection<T>
filter(Collection<? extends T> collection, Predicate<? super T> predicate)
static <T> T
get(Iterable<? extends T> collection, int index)
Get the element at the specified index within the specified collection.static <T> T
getAny(Iterable<? extends T> iterable)
static <T> T
getFirst(Iterable<? extends T> iterable)
static <T> T
getLast(Iterable<? extends T> iterable)
static <T> int
getLast(List<? extends T> list, BiPredicate<Integer,? super T> test)
static <T> int
getLast(List<? extends T> list, Predicate<? super T> test)
static <T> T
getOne(Iterable<? extends T> iterable)
Get the single item from aniterable
.static <T> T
getOneOptional(Iterable<? extends T> iterable, ISupplier<? extends T> ifNone)
static <T> Set<T>
intersection(Collection<? extends T>... collections)
static boolean
isOne(Iterable<?> iterable, Object object)
Test if an iterable contains a single, specified, item.static <I,O>
Collection<O>map(Function<? super I,? extends O> map, Collection<? extends I> input)
static <T> T
removeAny(Collection<T> collection)
static <T> List<T>
sort(Collection<? extends T> collection, Comparator<? super T> comparator)
static <T> Collection<T>
toCollection(Iterable<T> iterable)
static <T> List<T>
toList(Iterable<T> iterable)
static int
totalSize(Collection<?>... collections)
static <T> Set<T>
union(Collection<? extends T>... collections)
-
-
-
Method Detail
-
add
public static <K,C extends Collection<V>,V> void add(Map<K,C> map, Supplier<? extends C> constructor, K key, V value)
-
asSet
@SafeVarargs public static <T extends Enum<T>> EnumSet<T> asSet(Class<T> type, T... elements)
-
asList
public static <T> List<T> asList(Collection<T> collection)
-
asList
@SafeVarargs public static <T> List<T> asList(T... elements)
-
asListRepeated
public static <T> List<T> asListRepeated(int count, T element)
-
asListNonNull
@SafeVarargs public static <T> List<T> asListNonNull(T... elements)
-
asSet
@SafeVarargs public static <T> Set<T> asSet(T... elements)
-
concatenate
@SafeVarargs public static <T> List<T> concatenate(Collection<? extends T>... collections)
-
totalSize
public static int totalSize(Collection<?>... collections)
-
union
@SafeVarargs public static <T> Set<T> union(Collection<? extends T>... collections)
-
difference
public static <T> Set<T> difference(Collection<? extends T> minuend, Collection<? extends T> subtrahend)
-
intersection
@SafeVarargs public static <T> Set<T> intersection(Collection<? extends T>... collections)
-
difference
@SafeVarargs public static <T> Collection<T> difference(Collection<? extends T> minuend, T... subtrahend)
-
filter
public static <T> Collection<T> filter(Collection<? extends T> collection, Predicate<? super T> predicate)
-
get
public static <T> T get(Iterable<? extends T> collection, int index)
Get the element at the specified index within the specified collection. Supports negative indices to start from the end of the list.- Type Parameters:
T
- A supertype of the elements of the collection.- Parameters:
collection
- The collection to get an element from.index
- The index of the element to get. Must in the range-size <= index < size
- Returns:
- The element at the specified index.
-
getAny
public static <T> T getAny(Iterable<? extends T> iterable)
-
emptyList
public static <T> List<T> emptyList()
-
emptySet
public static <T> Set<T> emptySet()
-
getFirst
public static <T> T getFirst(Iterable<? extends T> iterable)
-
getLast
public static <T> T getLast(Iterable<? extends T> iterable)
-
getLast
public static <T> int getLast(List<? extends T> list, BiPredicate<Integer,? super T> test)
-
getOne
public static <T> T getOne(Iterable<? extends T> iterable)
Get the single item from aniterable
. Throw an exception if there are either fewer or more than one items.- Type Parameters:
T
- The type of the items- Parameters:
iterable
- The iterable to get the single item from- Returns:
- The single item in the iterable
- Throws:
IllegalArgumentException
- if there are 0, 2 or more items initerable
-
getOneOptional
public static <T> T getOneOptional(Iterable<? extends T> iterable, ISupplier<? extends T> ifNone)
-
isOne
public static boolean isOne(Iterable<?> iterable, Object object)
Test if an iterable contains a single, specified, item.- Parameters:
iterable
- The iterable to search.object
- The object to search for.- Returns:
true
ifiterable
containsobject
and nothing else.
-
map
public static <I,O> Collection<O> map(Function<? super I,? extends O> map, Collection<? extends I> input)
-
removeAny
public static <T> T removeAny(Collection<T> collection)
-
toCollection
public static <T> Collection<T> toCollection(Iterable<T> iterable)
-
sort
public static <T> List<T> sort(Collection<? extends T> collection, Comparator<? super T> comparator)
-
-