Class ContainerUtil
java.lang.Object
com.kamikazejam.kamicommon.util.collections.ContainerUtil
The ContainerUtil provides an imaginary super class to Collection and Map.
In Java they do not have a common interface yet many methods are similar and exists in both.
This some times results in twice the amount of source code, which we aim to remedy with this utility class.
We take an approach where we largely see a Map as a Collection of entries. The "Container" class is simply an Object. The return values are auto cast generics.
We have also added some information gatherers related to sorting and order.
We take an approach where we largely see a Map as a Collection of entries. The "Container" class is simply an Object. The return values are auto cast generics.
We have also added some information gatherers related to sorting and order.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
addElement
(Object container, Object element) static void
addElements
(Object container, Iterable<?> elements) static <C extends Collection<?>>
CasCollection
(@Nullable Object container) static <L extends List<?>>
Lstatic <M extends Map<?,
?>>
Mstatic <S extends Set<?>>
Sstatic void
static <E> @NotNull Collection
<E> getAdditions
(@NotNull Object before, @NotNull Object after) static <V> V
getCopy
(V container) static <E> @NotNull Collection
<E> getDeletions
(@NotNull Object before, @NotNull Object after) static <E> @NotNull Collection
<E> getElements
(Object container) static boolean
isCollection
(Object container) static boolean
isContainer
(Object container) static boolean
static boolean
static boolean
static boolean
static boolean
static boolean
static boolean
static void
setElements
(@NotNull Object container, @NotNull Iterable<?> elements) static @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int
-
Constructor Details
-
ContainerUtil
public ContainerUtil()
-
-
Method Details
-
isContainer
-
isCollection
-
isMap
-
isList
-
isSet
-
isIndexed
-
isOrdered
-
isSorted
-
asCollection
@Contract(pure=true) @Nullable public static <C extends Collection<?>> C asCollection(@Nullable @Nullable Object container) -
asMap
-
asSet
-
asList
-
isEmpty
-
size
@Contract("null -> fail") public static @org.jetbrains.annotations.Range(from=0L, to=2147483647L) int size(Object container) -
getElements
@Contract("null -> fail") @NotNull public static <E> @NotNull Collection<E> getElements(Object container) -
clear
-
setElements
-
addElement
-
addElements
-
getAdditions
@NotNull public static <E> @NotNull Collection<E> getAdditions(@NotNull @NotNull Object before, @NotNull @NotNull Object after) -
getDeletions
@NotNull public static <E> @NotNull Collection<E> getDeletions(@NotNull @NotNull Object before, @NotNull @NotNull Object after) -
getCopy
@Nullable public static <V> V getCopy(@Nullable V container)
-