Package com.im.commons.base
Class IJCCollections
- java.lang.Object
-
- com.im.commons.base.IJCCollections
-
public final class IJCCollections extends java.lang.ObjectUtility methods related to collections. The prefix IJC is there just for convenience - to not conflict with JDKCollectionsclass. Otherwise this class is completely independent on IJC code-base.- Since:
- 5.12
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Pair<java.util.List<T>,java.util.List<T>>computeDiff(java.util.List<? extends T> listA, java.util.List<? extends T> listB)Gets a symmetric difference of two lists.static <T> java.util.List<? extends T>listFromNullable(T nullableElement)IfnullableElementis non-null, returns a singleton list containing that reference; otherwise returnsCollections.emptyList().static <T> java.util.Set<? extends T>setFromNullable(T nullableElement)IfnullableElementis non-null, returns a singleton set containing that reference; otherwise returnsCollections.emptySet().static <T> java.util.stream.Collector<T,com.google.common.collect.ImmutableList.Builder<T>,com.google.common.collect.ImmutableList<T>>toImmutableList()ProvidesCollectorwhich reduces stream into GuavaImmutableList.static <T,K,V>
java.util.stream.Collector<T,?,com.google.common.collect.ImmutableMap<K,V>>toImmutableMap(java.util.function.Function<? super T,? extends K> keyMapper, java.util.function.Function<? super T,? extends V> valueMapper)ProvidesCollectorwhich reduces stream into GuavaImmutableMap.
-
-
-
Method Detail
-
listFromNullable
public static <T> java.util.List<? extends T> listFromNullable(T nullableElement)
IfnullableElementis non-null, returns a singleton list containing that reference; otherwise returnsCollections.emptyList().- Type Parameters:
T- type of the element- Parameters:
nullableElement- element ornull- Returns:
- the list
-
setFromNullable
public static <T> java.util.Set<? extends T> setFromNullable(T nullableElement)
IfnullableElementis non-null, returns a singleton set containing that reference; otherwise returnsCollections.emptySet().- Type Parameters:
T- type of the element- Parameters:
nullableElement- element ornull- Returns:
- the set
-
computeDiff
public static <T> Pair<java.util.List<T>,java.util.List<T>> computeDiff(java.util.List<? extends T> listA, java.util.List<? extends T> listB)
Gets a symmetric difference of two lists.The symmetric difference of two sets A and B is the set of elements that are in exactly one of A and B.
- Type Parameters:
T- The common type of elements in the lists.- Parameters:
listA- The first list.listB- The second list.- Returns:
- A pair of lists that contain elements found only in
listAand those found only inlistBrespectively. Those two lists together comprise the symmetric difference oflistAandlistB. - Since:
- 6.1
-
toImmutableList
public static <T> java.util.stream.Collector<T,com.google.common.collect.ImmutableList.Builder<T>,com.google.common.collect.ImmutableList<T>> toImmutableList()
ProvidesCollectorwhich reduces stream into GuavaImmutableList. Example usage:List<Integer> list = IntStream.range(0, 7) .boxed() .collect(IJCCollections.toImmutableList()); list.add(42); // fails on runtime- Since:
- 17.9.0
-
toImmutableMap
public static <T,K,V> java.util.stream.Collector<T,?,com.google.common.collect.ImmutableMap<K,V>> toImmutableMap(java.util.function.Function<? super T,? extends K> keyMapper, java.util.function.Function<? super T,? extends V> valueMapper)ProvidesCollectorwhich reduces stream into GuavaImmutableMap. Example usage:Map<Integer, String> map = IntStream.range(0, 7) .boxed() .collect(IJCCollections.toImmutableMap(Integer::intValue, integer -> integer + "asdf "));- Since:
- 19.27.0
-
-