public final class Immutables
extends java.lang.Object
ImmutableSet
s and ImmutableList
s.
This class cannot be instantiated.Modifier | Constructor and Description |
---|---|
private |
Immutables() |
Modifier and Type | Method and Description |
---|---|
static <T> ImmutableList<T> |
concatDuplicateFreeLists(ImmutableList<T> l1,
ImmutableList<? extends T> l2) |
static <T> ImmutableList<T> |
createListFrom(java.lang.Iterable<T> iterable) |
static <T> ImmutableSet<T> |
createSetFrom(java.lang.Iterable<T> iterable) |
static <T> boolean |
isDuplicateFree(ImmutableList<T> list)
Checks whether an immutable list is free of duplicates.
|
static <T> ImmutableList<T> |
removeDuplicates(ImmutableList<T> list)
Removes duplicate entries from an immutable list.
|
public static <T> boolean isDuplicateFree(ImmutableList<T> list)
o1==null ? o2 == null : o1.equals(o2)
is true.
null
may appear in the list.
The implementation uses a hash set internally and thus runs in O(n).list
- any list, must not be null
public static <T> ImmutableList<T> removeDuplicates(ImmutableList<T> list)
o1==null ? o2 == null : o1.equals(o2)
is
true. null
may appear in the list.
If an element occurs duplicated, its first (in order of iteration)
occurrence is kept, while later occurrences are removeed.
If a list iterates "a", "b", "a" in this order, removeDuplicates returns
a list iterating "a", "b".
The implementation uses a hash set internally and thus runs in O(n).
It reuses as much created datastructure as possible. In particular, if
the list is already duplicate-fre, it does not allocate new memory (well,
only temporarily) and returns the argument.
Sidenote: Would that not make a nice KeY-Verification condition? Eat your
own dogfood.list
- any list, must not be null
null
public static <T> ImmutableList<T> concatDuplicateFreeLists(ImmutableList<T> l1, ImmutableList<? extends T> l2)
public static <T> ImmutableSet<T> createSetFrom(java.lang.Iterable<T> iterable)
public static <T> ImmutableList<T> createListFrom(java.lang.Iterable<T> iterable)