Package org.plumelib.util
Class ArraysPlume.ListOrArray<T extends @Nullable Object>
java.lang.Object
org.plumelib.util.ArraysPlume.ListOrArray<T>
- Type Parameters:
T- the type of array or list elements
- Enclosing class:
- ArraysPlume
A wrapper around a list or an array (or null). Avoids code duplication for arrays and lists, at
the cost of object construction and method calls.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionListOrArray(@Nullable List<T> theList) Creates a ListOrArray that wraps a list.ListOrArray(T @Nullable [] theArray) Creates a ListOrArray that wraps an array. -
Method Summary
Modifier and TypeMethodDescription(package private) voidCopy the contents of this into the given array, starting at the given index in the array.(package private) booleanisEmpty()Returns true if this represents an empty collection.(package private) booleanisNull()Returns true if this represents a null value.Returns the least upper bound of the classes of the elements of this.(package private) @org.checkerframework.checker.index.qual.NonNegative intsize()Returns the size of the collection this represents.(package private) T[]toArray()Returns an array with the same contents as this.toString()Returns a verbose representation of this, for debugging.
-
Field Details
-
theArray
The array that this object wraps, or null. -
theList
The list that this object wraps, or null.
-
-
Constructor Details
-
ListOrArray
ListOrArray(T @Nullable [] theArray) Creates a ListOrArray that wraps an array.- Parameters:
theArray- the delegate that will be wrapped
-
ListOrArray
Creates a ListOrArray that wraps a list.- Parameters:
theList- the delegate that will be wrapped
-
-
Method Details
-
isNull
@Pure boolean isNull()Returns true if this represents a null value.- Returns:
- true if this represents a null value
-
size
@Pure @org.checkerframework.checker.index.qual.NonNegative int size()Returns the size of the collection this represents.- Returns:
- the size of the collection this represents
-
isEmpty
@Pure boolean isEmpty()Returns true if this represents an empty collection.- Returns:
- true if this represents an empty collection
-
toArray
Returns an array with the same contents as this.- Returns:
- an array with the same contents as this
-
copyInto
Copy the contents of this into the given array, starting at the given index in the array.- Parameters:
dest- the destination arraydestPos- the index at which to start overwriting elements ofdest
-
leastUpperBound
Returns the least upper bound of the classes of the elements of this.- Returns:
- the least upper bound of the classes of the elements of this
-
toString
-
toStringDebug
Returns a verbose representation of this, for debugging.- Returns:
- a verbose representation of this, for debugging
-