Package org.plumelib.util
Class SIList<E>
java.lang.Object
org.plumelib.util.SIList<E>
- Type Parameters:
E
- the type of elements of the list
- All Implemented Interfaces:
Serializable
,Iterable<E>
An immutable list. Different lists may share structure, making the representation space-efficient
and making construction time-efficient. Use this only if you will be creating many lists that
share structure. Examples are when one list is the concatenation of other lists, or one list is
just like another with a single element added.
"SIList" stands for "Shared Immutable List".
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionReturns a new list that consists of this one plus one more element.static <E2> SIList
<E2> Create a SIList from a list of SILists.static <E2> SIList
<E2> Concatenate an array of SILists.static <E2> SIList
<E2> empty()
Returns an empty list.static <E2> SIList
<E2> fromList
(Collection<E2> list) Create a SIList from a JDK list.abstract E
get
(@org.checkerframework.checker.index.qual.IndexFor({"this"}) int index) Returns the element at the given position of this list.getSublistContaining
(@org.checkerframework.checker.index.qual.IndexFor({"this"}) int index) Returns an arbitrary sublist of this list that contains the index.abstract boolean
isEmpty()
Returns true if this list is empty.static <E2> SIList
<E2> singleton
(E2 elt) Returns a new list containing one element.static <E2> SIList
<E2> singletonOrEmpty
(@Nullable E2 elt) Returns a new list containing zero or one element.abstract @org.checkerframework.checker.index.qual.LengthOf({"this"}) int
size()
Returns the number of elements in this list.subList
(@org.checkerframework.checker.index.qual.IndexFor({"this"}) int fromIndex, @org.checkerframework.checker.index.qual.IndexOrHigh({"this"}) int toIndex) Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
fromList
Create a SIList from a JDK list.- Type Parameters:
E2
- the type of list elements- Parameters:
list
- the elements of the new list- Returns:
- the list
-
empty
Returns an empty list.- Type Parameters:
E2
- the type of elements of the list- Returns:
- an empty list
-
singleton
Returns a new list containing one element.- Type Parameters:
E2
- the type of elements of the list- Parameters:
elt
- the element- Returns:
- a new list containing one element
-
singletonOrEmpty
Returns a new list containing zero or one element.- Type Parameters:
E2
- the type of elements of the list- Parameters:
elt
- the element- Returns:
- a new list containing the element if it is non-null; if the element is null, returns an empty list
-
add
Returns a new list that consists of this one plus one more element. Does not modify this object.- Parameters:
element
- the additional element- Returns:
- a new list that consists of this one plus one more element
-
concat
Concatenate an array of SILists.- Type Parameters:
E2
- the type of list elements- Parameters:
lists
- the lists that will compose the newly-created ListOfLists- Returns:
- the concatenated list
-
concat
Create a SIList from a list of SILists.- Type Parameters:
E2
- the type of list elements- Parameters:
lists
- the lists that will compose the newly-created ListOfLists- Returns:
- the concatenated list
-
size
@LengthOf("this") public abstract @org.checkerframework.checker.index.qual.LengthOf({"this"}) int size()Returns the number of elements in this list.- Returns:
- the number of elements in this list
-
isEmpty
public abstract boolean isEmpty()Returns true if this list is empty.- Returns:
- true if this list is empty, false otherwise
-
get
Returns the element at the given position of this list.- Parameters:
index
- a position in the list- Returns:
- the element at the index
-
subList
public SIList<E> subList(@org.checkerframework.checker.index.qual.IndexFor({"this"}) int fromIndex, @org.checkerframework.checker.index.qual.IndexOrHigh({"this"}) int toIndex) Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.- Parameters:
fromIndex
- low endpoint (inclusive) of the subListtoIndex
- high endpoint (exclusive) of the subList- Returns:
- a view of part of this list
-
getSublistContaining
public abstract SIList<E> getSublistContaining(@org.checkerframework.checker.index.qual.IndexFor({"this"}) int index) Returns an arbitrary sublist of this list that contains the index. The result does not necessarily contain the first or last element of this.- Parameters:
index
- the index into this list- Returns:
- a sublist containing this index
-
toString
-