long values, with an API resembling List.
Advantages compared to long[]:
equals, hashCode, and toString behavior you expect.
get and length, so you don't have to
hunt through classes like Arrays and Longs for them.
subArray view, so methods that accept this type don't need to
add overloads that accept start and end indexes.
foo.getBarLongs().stream()....
asList (though at the cost of
allocating garbage).
Disadvantages compared to long[]:
long[] (though the most common
utilities do have replacements here).
com.google.common / Guava.
Advantages compared to ImmutableList<Long>:
LongStream features (like LongStream#sum) using stream()
instead of the awkward stream().mapToLong(v -> v).
Disadvantages compared to ImmutableList<Long>:
Iterable, Collection, or
List (though the most common utilities do have replacements here, and there is a
lazy asList view).
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | |
| public static class | ImmutableLongArray.
A builder for |
| Modifier and Type | Field and Description |
|---|---|
| private final long[] | |
| private static final ImmutableLongArray | |
| private final int | |
| private final transient int |
| Access | Constructor and Description |
|---|---|
| private | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| public List | |
| public static ImmutableLongArray. | builder(int initialCapacity)
Returns a new, empty builder for |
| public static ImmutableLongArray. | builder()
Returns a new, empty builder for |
| public boolean | |
| public static ImmutableLongArray | |
| public static ImmutableLongArray | |
| public static ImmutableLongArray | |
| public static ImmutableLongArray | copyOf(LongStream stream)
Returns an immutable array containing all the values from |
| public boolean | equals(Object
the reference object with which to compare. object)Overrides java. true if object is an ImmutableLongArray containing the same
values as this one, in the same order.
|
| public void | |
| public long | |
| public int | hashCode()
Overrides java. |
| public int | |
| public boolean | |
| private boolean | |
| public int | lastIndexOf(long target)
Returns the largest index for which |
| public int | |
| public static ImmutableLongArray | |
| public static ImmutableLongArray | |
| public static ImmutableLongArray | |
| public static ImmutableLongArray | |
| public static ImmutableLongArray | of(long e0, long e1, long e2, long e3)
Returns an immutable array containing the given values, in order. |
| public static ImmutableLongArray | of(long e0, long e1, long e2, long e3, long e4)
Returns an immutable array containing the given values, in order. |
| public static ImmutableLongArray | of(long e0, long e1, long e2, long e3, long e4, long e5)
Returns an immutable array containing the given values, in order. |
| public static ImmutableLongArray | |
| pack-priv Object | |
| private Spliterator. | |
| public LongStream | |
| public ImmutableLongArray | subArray(int startIndex, int endIndex)
Returns a new immutable array containing the values in the specified range. |
| public long[] | |
| public String | toString()
Overrides java. Arrays#toString(long[]), for example "[1, 2, 3]".
|
| public ImmutableLongArray | |
| pack-priv Object |
| array | back to summary |
|---|---|
private final long[] array
| |
| EMPTY | back to summary |
|---|---|
| private static final ImmutableLongArray EMPTY | |
| end | back to summary |
|---|---|
| private final int end | |
| start | back to summary |
|---|---|
| private final transient int start | |
| ImmutableLongArray | back to summary |
|---|---|
| private ImmutableLongArray(long[] array) | |
| ImmutableLongArray | back to summary |
|---|---|
| private ImmutableLongArray(long[] array, int start, int end) | |
| asList | back to summary |
|---|---|
| public List Returns an immutable view of this array's values as a | |
| builder | back to summary |
|---|---|
| public static ImmutableLongArray. Returns a new, empty builder for Performance note: When feasible, | |
| builder | back to summary |
|---|---|
| public static ImmutableLongArray. Returns a new, empty builder for Performance note: The | |
| contains | back to summary |
|---|---|
| public boolean contains(long target) Returns | |
| copyOf | back to summary |
|---|---|
| public static ImmutableLongArray copyOf(long[] values) Returns an immutable array containing the given values, in order. | |
| copyOf | back to summary |
|---|---|
| public static ImmutableLongArray copyOf(Collection<Long> values) Returns an immutable array containing the given values, in order. | |
| copyOf | back to summary |
|---|---|
| public static ImmutableLongArray copyOf(Iterable<Long> values) Returns an immutable array containing the given values, in order. Performance note: this method delegates to | |
| copyOf | back to summary |
|---|---|
| public static ImmutableLongArray copyOf(LongStream stream) Returns an immutable array containing all the values from | |
| equals | back to summary |
|---|---|
| public boolean equals(Object object) Overrides java. Returns
| |
| forEach | back to summary |
|---|---|
| public void forEach(LongConsumer consumer) Invokes | |
| get | back to summary |
|---|---|
| public long get(int index) Returns the
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Returns an unspecified hash code for the contents of this immutable array.
| |
| indexOf | back to summary |
|---|---|
| public int indexOf(long target) Returns the smallest index for which | |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Returns | |
| isPartialView | back to summary |
|---|---|
| private boolean isPartialView() | |
| lastIndexOf | back to summary |
|---|---|
| public int lastIndexOf(long target) Returns the largest index for which | |
| length | back to summary |
|---|---|
| public int length() Returns the number of values in this array. | |
| of | back to summary |
|---|---|
| public static ImmutableLongArray of() Returns the empty array. | |
| of | back to summary |
|---|---|
| public static ImmutableLongArray of(long e0) Returns an immutable array containing a single value. | |
| of | back to summary |
|---|---|
| public static ImmutableLongArray of(long e0, long e1) Returns an immutable array containing the given values, in order. | |
| of | back to summary |
|---|---|
| public static ImmutableLongArray of(long e0, long e1, long e2) Returns an immutable array containing the given values, in order. | |
| of | back to summary |
|---|---|
| public static ImmutableLongArray of(long e0, long e1, long e2, long e3) Returns an immutable array containing the given values, in order. | |
| of | back to summary |
|---|---|
| public static ImmutableLongArray of(long e0, long e1, long e2, long e3, long e4) Returns an immutable array containing the given values, in order. | |
| of | back to summary |
|---|---|
| public static ImmutableLongArray of(long e0, long e1, long e2, long e3, long e4, long e5) Returns an immutable array containing the given values, in order. | |
| of | back to summary |
|---|---|
| public static ImmutableLongArray of(long first, long... rest) Returns an immutable array containing the given values, in order. The array | |
| readResolve | back to summary |
|---|---|
| pack-priv Object readResolve() | |
| spliterator | back to summary |
|---|---|
| private Spliterator. | |
| stream | back to summary |
|---|---|
| public LongStream stream() Returns a stream over the values in this array, in order. | |
| subArray | back to summary |
|---|---|
| public ImmutableLongArray subArray(int startIndex, int endIndex) Returns a new immutable array containing the values in the specified range. Performance note: The returned array has the same full memory footprint as this one
does (no actual copying is performed). To reduce memory usage, use | |
| toArray | back to summary |
|---|---|
| public long[] toArray() Returns a new, mutable copy of this array's values, as a primitive | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string representation of this array in the same form as
| |
| trimmed | back to summary |
|---|---|
| public ImmutableLongArray trimmed() Returns an immutable array containing the same values as | |
| writeReplace | back to summary |
|---|---|
| pack-priv Object writeReplace() | |
| Modifier and Type | Field and Description |
|---|---|
| private final ImmutableLongArray |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | contains(Object
element whose presence in this list is to be tested target)Overrides java. Implements java. true if this list contains the specified element.
|
| public boolean | equals(Object
the object to be compared for equality with this list object)Overrides java. Implements java. |
| public Long | get(int
index of the element to return index)Implements abstract java. Implements java. |
| public int | hashCode()
Overrides java. Implements java. |
| public int | indexOf(Object
element to search for target)Overrides java. Implements java. |
| public int | lastIndexOf(Object
element to search for target)Overrides java. Implements java. |
| public int | size()
Implements abstract java. Implements java. |
| public Spliterator | spliterator()
Overrides default java. Spliterator over the elements in this list.
|
| public List | subList(int
low endpoint (inclusive) of the subList fromIndex, int high endpoint (exclusive) of the subList toIndex)Overrides java. Implements java. fromIndex, inclusive, and toIndex, exclusive.
|
| public String | toString()
Overrides java. |
| parent | back to summary |
|---|---|
| private final ImmutableLongArray parent | |
| AsList | back to summary |
|---|---|
| private AsList(ImmutableLongArray parent) | |
| contains | back to summary |
|---|---|
| public boolean contains(Object target) Overrides java. Implements java. Doc from java. Returns | |
| equals | back to summary |
|---|---|
| public boolean equals(Object object) Overrides java. Implements java. Doc from java. Compares the specified object with this list for equality. Returns
| |
| get | back to summary |
|---|---|
| public Long get(int index) Implements abstract java. Implements java. Doc from java. Returns the element at the specified position in this list.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Implements java. Doc from java. Returns the hash code value for this list.
| |
| indexOf | back to summary |
|---|---|
| public int indexOf(Object target) Overrides java. Implements java. Doc from java. Returns the index of the first occurrence of the specified element
in this list, or -1 if this list does not contain the element.
More formally, returns the lowest index
| |
| lastIndexOf | back to summary |
|---|---|
| public int lastIndexOf(Object target) Overrides java. Implements java. Doc from java. Returns the index of the last occurrence of the specified element
in this list, or -1 if this list does not contain the element.
More formally, returns the highest index
| |
| size | back to summary |
|---|---|
| public int size() Implements abstract java. Implements java. Doc from java. Returns the number of elements in this list. If this list contains
more than
| |
| spliterator | back to summary |
|---|---|
| public Spliterator Overrides default java. Doc from java. Creates a The
| |
| subList | back to summary |
|---|---|
| public List Overrides java. Implements java. Doc from java. Returns a view of the portion of this list between the specified
This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by passing a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list:
Similar idioms may be constructed for indexOf and
lastIndexOf, and all of the algorithms in the
Collections class can be applied to a subList.The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of this collection. The string
representation consists of a list of the collection's elements in the
order they are returned by its iterator, enclosed in square brackets
( | |
ImmutableLongArray instances; obtained using ImmutableLongArray#builder.
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public ImmutableLongArray. | |
| public ImmutableLongArray. | addAll(long[] values)
Appends |
| public ImmutableLongArray. | addAll(Iterable<Long> values)
Appends |
| public ImmutableLongArray. | addAll(Collection<Long> values)
Appends |
| public ImmutableLongArray. | addAll(LongStream stream)
Appends all values from |
| public ImmutableLongArray. | addAll(ImmutableLongArray values)
Appends |
| public ImmutableLongArray | |
| private void | |
| private static int |
| Builder | back to summary |
|---|---|
| pack-priv Builder(int initialCapacity) | |
| add | back to summary |
|---|---|
| public ImmutableLongArray. Appends
| |
| addAll | back to summary |
|---|---|
| public ImmutableLongArray. Appends
| |
| addAll | back to summary |
|---|---|
| public ImmutableLongArray. Appends
| |
| addAll | back to summary |
|---|---|
| public ImmutableLongArray. Appends
| |
| addAll | back to summary |
|---|---|
| public ImmutableLongArray. Appends all values from
| |
| addAll | back to summary |
|---|---|
| public ImmutableLongArray. Appends
| |
| build | back to summary |
|---|---|
| public ImmutableLongArray build() Returns a new immutable array. The builder can continue to be used after this call, to append more values and build again. Performance note: the returned array is backed by the same array as the builder, so
no data is copied as part of this step, but this may occupy more memory than strictly
necessary. To copy the data to a right-sized backing array, use | |
| ensureRoomFor | back to summary |
|---|---|
| private void ensureRoomFor(int numberToAdd) | |
| expandedCapacity | back to summary |
|---|---|
| private static int expandedCapacity(int oldCapacity, int minCapacity) | |