Top Description Inners Fields Constructors Methods
com.google.common.primitives

public final Class ImmutableLongArray

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Annotations
@GwtCompatible
@Immutable
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkNotNull

An immutable array of long values, with an API resembling List.

Advantages compared to long[]:

Disadvantages compared to long[]:

Advantages compared to ImmutableList<Long>:

Disadvantages compared to ImmutableList<Long>:

Since
22.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
public static class

Field Summary

Modifier and TypeField and Description
private final long[]
private static final ImmutableLongArray
private final int
private final transient int

Constructor Summary

AccessConstructor and Description
private
ImmutableLongArray(long[] array)

private
ImmutableLongArray(long[] array, int start, int end)

Method Summary

Modifier and TypeMethod and Description
public List<Long>
asList()

Returns an immutable view of this array's values as a List; note that long values are boxed into Long instances on demand, which can be very expensive.

public static ImmutableLongArray.Builder
builder(int initialCapacity)

Returns a new, empty builder for ImmutableLongArray instances, sized to hold up to initialCapacity values without resizing.

public static ImmutableLongArray.Builder
builder()

Returns a new, empty builder for ImmutableLongArray instances, with a default initial capacity.

public boolean
contains(long target)

Returns true if target is present at any index in this array.

public static ImmutableLongArray
copyOf(long[] values)

Returns an immutable array containing the given values, in order.

public static ImmutableLongArray
copyOf(Collection<Long> values)

Returns an immutable array containing the given values, in order.

public static ImmutableLongArray
copyOf(Iterable<Long> values)

Returns an immutable array containing the given values, in order.

public static ImmutableLongArray
copyOf(LongStream stream)

Returns an immutable array containing all the values from stream, in order.

public boolean
equals(Object
the reference object with which to compare.
object
)

Overrides java.lang.Object.equals.

Returns true if object is an ImmutableLongArray containing the same values as this one, in the same order.
public void
forEach(LongConsumer consumer)

Invokes consumer for each value contained in this array, in order.

public long
get(int index)

Returns the long value present at the given index.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns an unspecified hash code for the contents of this immutable array.
public int
indexOf(long target)

Returns the smallest index for which get returns target, or -1 if no such index exists.

public boolean
isEmpty()

Returns true if there are no values in this array (length is zero).

private boolean
public int
lastIndexOf(long target)

Returns the largest index for which get returns target, or -1 if no such index exists.

public int
length()

Returns the number of values in this array.

public static ImmutableLongArray
of()

Returns the empty array.

public static ImmutableLongArray
of(long e0)

Returns an immutable array containing a single value.

public static ImmutableLongArray
of(long e0, long e1)

Returns an immutable array containing the given values, in order.

public static ImmutableLongArray
of(long e0, long e1, long e2)

Returns an immutable array containing the given values, in order.

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
of(long first, long... rest)

Returns an immutable array containing the given values, in order.

pack-priv Object
private Spliterator.OfLong
public LongStream
stream()

Returns a stream over the values in this array, in order.

public ImmutableLongArray
subArray(int startIndex, int endIndex)

Returns a new immutable array containing the values in the specified range.

public long[]
toArray()

Returns a new, mutable copy of this array's values, as a primitive long[].

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of this array in the same form as Arrays#toString(long[]), for example "[1, 2, 3]".
public ImmutableLongArray
trimmed()

Returns an immutable array containing the same values as this array.

pack-priv Object
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

arrayback to summary
private final long[] array
Annotations
@SuppressWarnings:Immutable
EMPTYback to summary
private static final ImmutableLongArray EMPTY
endback to summary
private final int end
startback to summary
private final transient int start

Constructor Detail

ImmutableLongArrayback to summary
private ImmutableLongArray(long[] array)
ImmutableLongArrayback to summary
private ImmutableLongArray(long[] array, int start, int end)

Method Detail

asListback to summary
public List<Long> asList()

Returns an immutable view of this array's values as a List; note that long values are boxed into Long instances on demand, which can be very expensive. The returned list should be used once and discarded. For any usages beyond that, pass the returned list to ImmutableList.copyOf and use that list instead.

builderback to summary
public static ImmutableLongArray.Builder builder(int initialCapacity)

Returns a new, empty builder for ImmutableLongArray instances, sized to hold up to initialCapacity values without resizing. The returned builder is not thread-safe.

Performance note: When feasible, initialCapacity should be the exact number of values that will be added, if that knowledge is readily available. It is better to guess a value slightly too high than slightly too low. If the value is not exact, the ImmutableLongArray that is built will very likely occupy more memory than strictly necessary; to trim memory usage, build using builder.build().trimmed().

builderback to summary
public static ImmutableLongArray.Builder builder()

Returns a new, empty builder for ImmutableLongArray instances, with a default initial capacity. The returned builder is not thread-safe.

Performance note: The ImmutableLongArray that is built will very likely occupy more memory than necessary; to trim memory usage, build using builder.build().trimmed().

containsback to summary
public boolean contains(long target)

Returns true if target is present at any index in this array. Equivalent to asList().contains(target).

copyOfback to summary
public static ImmutableLongArray copyOf(long[] values)

Returns an immutable array containing the given values, in order.

copyOfback to summary
public static ImmutableLongArray copyOf(Collection<Long> values)

Returns an immutable array containing the given values, in order.

copyOfback 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(Collection) if values is a Collection. Otherwise it creates a builder and uses Builder#addAll(Iterable), with all the performance implications associated with that.

copyOfback to summary
public static ImmutableLongArray copyOf(LongStream stream)

Returns an immutable array containing all the values from stream, in order.

equalsback to summary
public boolean equals(Object object)

Overrides java.lang.Object.equals.

Returns true if object is an ImmutableLongArray containing the same values as this one, in the same order.

Parameters
object:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
forEachback to summary
public void forEach(LongConsumer consumer)

Invokes consumer for each value contained in this array, in order.

getback to summary
public long get(int index)

Returns the long value present at the given index.

Exceptions
IndexOutOfBoundsException:
if index is negative, or greater than or equal to length
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns an unspecified hash code for the contents of this immutable array.

Returns:int

Doc from java.lang.Object.hashCode.

a hash code value for this object.

Annotations
@Override
indexOfback to summary
public int indexOf(long target)

Returns the smallest index for which get returns target, or -1 if no such index exists. Equivalent to asList().indexOf(target).

isEmptyback to summary
public boolean isEmpty()

Returns true if there are no values in this array (length is zero).

isPartialViewback to summary
private boolean isPartialView()
lastIndexOfback to summary
public int lastIndexOf(long target)

Returns the largest index for which get returns target, or -1 if no such index exists. Equivalent to asList().lastIndexOf(target).

lengthback to summary
public int length()

Returns the number of values in this array.

ofback to summary
public static ImmutableLongArray of()

Returns the empty array.

ofback to summary
public static ImmutableLongArray of(long e0)

Returns an immutable array containing a single value.

ofback to summary
public static ImmutableLongArray of(long e0, long e1)

Returns an immutable array containing the given values, in order.

ofback to summary
public static ImmutableLongArray of(long e0, long e1, long e2)

Returns an immutable array containing the given values, in order.

ofback to summary
public static ImmutableLongArray of(long e0, long e1, long e2, long e3)

Returns an immutable array containing the given values, in order.

ofback 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.

ofback 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.

ofback to summary
public static ImmutableLongArray of(long first, long... rest)

Returns an immutable array containing the given values, in order.

The array rest must not be longer than Integer.MAX_VALUE - 1.

readResolveback to summary
pack-priv Object readResolve()
spliteratorback to summary
private Spliterator.OfLong spliterator()
streamback to summary
public LongStream stream()

Returns a stream over the values in this array, in order.

subArrayback 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 subArray(start, end).trimmed().

toArrayback to summary
public long[] toArray()

Returns a new, mutable copy of this array's values, as a primitive long[].

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of this array in the same form as Arrays#toString(long[]), for example "[1, 2, 3]".

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override
trimmedback to summary
public ImmutableLongArray trimmed()

Returns an immutable array containing the same values as this array. This is logically a no-op, and in some circumstances this itself is returned. However, if this instance is a subArray view of a larger array, this method will copy only the appropriate range of values, resulting in an equivalent array with a smaller memory footprint.

writeReplaceback to summary
pack-priv Object writeReplace()
com.google.common.primitives back to summary

pack-priv Class ImmutableLongArray.AsList

extends AbstractList<Long>
implements RandomAccess, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.util.RandomAccess

Field Summary

Modifier and TypeField and Description
private final ImmutableLongArray
Inherited from java.util.AbstractList:
modCount

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
contains(Object
element whose presence in this list is to be tested
target
)

Overrides java.util.AbstractCollection.contains.

Implements java.util.List.contains, java.util.Collection.contains.

Returns 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.util.AbstractList.equals.

Implements java.util.List.equals, java.util.Collection.equals.

Compares the specified object with this list for equality.
public Long
get(int
index of the element to return
index
)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Returns the element at the specified position in this list.
public int
hashCode()

Overrides java.util.AbstractList.hashCode.

Implements java.util.List.hashCode, java.util.Collection.hashCode.

Returns the hash code value for this list.
public int
indexOf(Object
element to search for
target
)

Overrides java.util.AbstractList.indexOf.

Implements java.util.List.indexOf.

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
public int
lastIndexOf(Object
element to search for
target
)

Overrides java.util.AbstractList.lastIndexOf.

Implements java.util.List.lastIndexOf.

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.
public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Returns the number of elements in this list.
public Spliterator<Long>
spliterator()

Overrides default java.util.List.spliterator, java.util.Collection.spliterator.

Creates a Spliterator over the elements in this list.
public List<Long>
subList(int
low endpoint (inclusive) of the subList
fromIndex
,
int
high endpoint (exclusive) of the subList
toIndex
)

Overrides java.util.AbstractList.subList.

Implements java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
public String
toString()

Overrides java.util.AbstractCollection.toString.

Returns a string representation of this collection.
Inherited from java.util.AbstractList:
addaddaddAllcleariteratorlistIteratorlistIteratorremoveremoveRangeset

Field Detail

parentback to summary
private final ImmutableLongArray parent

Constructor Detail

AsListback to summary
private AsList(ImmutableLongArray parent)

Method Detail

containsback to summary
public boolean contains(Object target)

Overrides java.util.AbstractCollection.contains.

Implements java.util.List.contains, java.util.Collection.contains.

Doc from java.util.List.contains.

Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that Objects.equals(o, e).

Parameters
target:Object

element whose presence in this list is to be tested

Returns:boolean

true if this list contains the specified element

Annotations
@Override
equalsback to summary
public boolean equals(Object object)

Overrides java.util.AbstractList.equals.

Implements java.util.List.equals, java.util.Collection.equals.

Doc from java.util.AbstractList.equals.

Compares the specified object with this list for equality. Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) In other words, two lists are defined to be equal if they contain the same elements in the same order.

Parameters
object:Object

the object to be compared for equality with this list

Returns:boolean

true if the specified object is equal to this list

Annotations
@Override
getback to summary
public Long get(int index)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Doc from java.util.AbstractList.get.

Returns the element at the specified position in this list.

Parameters
index:int

Doc from java.util.List.get.

index of the element to return

Returns:Long

Doc from java.util.List.get.

the element at the specified position in this list

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.util.AbstractList.hashCode.

Implements java.util.List.hashCode, java.util.Collection.hashCode.

Doc from java.util.AbstractList.hashCode.

Returns the hash code value for this list.

Returns:int

the hash code value for this list

Annotations
@Override
indexOfback to summary
public int indexOf(Object target)

Overrides java.util.AbstractList.indexOf.

Implements java.util.List.indexOf.

Doc from java.util.AbstractList.indexOf.

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 i such that Objects.equals(o, get(i)), or -1 if there is no such index.

Parameters
target:Object

Doc from java.util.List.indexOf.

element to search for

Returns:int

Doc from java.util.List.indexOf.

the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element

Annotations
@Override
lastIndexOfback to summary
public int lastIndexOf(Object target)

Overrides java.util.AbstractList.lastIndexOf.

Implements java.util.List.lastIndexOf.

Doc from java.util.AbstractList.lastIndexOf.

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 i such that Objects.equals(o, get(i)), or -1 if there is no such index.

Parameters
target:Object

Doc from java.util.List.lastIndexOf.

element to search for

Returns:int

Doc from java.util.List.lastIndexOf.

the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element

Annotations
@Override
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Doc from java.util.List.size.

Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this list

Annotations
@Override
spliteratorback to summary
public Spliterator<Long> spliterator()

Overrides default java.util.List.spliterator, java.util.Collection.spliterator.

Doc from java.util.List.spliterator.

Creates a Spliterator over the elements in this list.

The Spliterator reports Spliterator#SIZED and Spliterator#ORDERED. Implementations should document the reporting of additional characteristic values.

Returns:Spliterator<Long>

a Spliterator over the elements in this list

Annotations
@Override
subListback to summary
public List<Long> subList(int fromIndex, int toIndex)

Overrides java.util.AbstractList.subList.

Implements java.util.List.subList.

Doc from java.util.AbstractList.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations supported by this list.

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:

list.subList(from, to).clear();
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.)

Parameters
fromIndex:int

Doc from java.util.List.subList.

low endpoint (inclusive) of the subList

toIndex:int

Doc from java.util.List.subList.

high endpoint (exclusive) of the subList

Returns:List<Long>

Doc from java.util.List.subList.

a view of the specified range within this list

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.util.AbstractCollection.toString.

Doc from java.util.AbstractCollection.toString.

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 ("[]"). Adjacent elements are separated by the characters ", " (comma and space). Elements are converted to strings as by String#valueOf(Object).

Returns:String

a string representation of this collection

Annotations
@Override
com.google.common.primitives back to summary

public final Class ImmutableLongArray.Builder

extends Object
Class Inheritance

A builder for ImmutableLongArray instances; obtained using ImmutableLongArray#builder.

Field Summary

Modifier and TypeField and Description
private long[]
private int

Constructor Summary

AccessConstructor and Description
pack-priv
Builder(int initialCapacity)

Method Summary

Modifier and TypeMethod and Description
public ImmutableLongArray.Builder
add(long value)

Appends value to the end of the values the built ImmutableLongArray will contain.

public ImmutableLongArray.Builder
addAll(long[] values)

Appends values, in order, to the end of the values the built ImmutableLongArray will contain.

public ImmutableLongArray.Builder
addAll(Iterable<Long> values)

Appends values, in order, to the end of the values the built ImmutableLongArray will contain.

public ImmutableLongArray.Builder
addAll(Collection<Long> values)

Appends values, in order, to the end of the values the built ImmutableLongArray will contain.

public ImmutableLongArray.Builder
addAll(LongStream stream)

Appends all values from stream, in order, to the end of the values the built ImmutableLongArray will contain.

public ImmutableLongArray.Builder
addAll(ImmutableLongArray values)

Appends values, in order, to the end of the values the built ImmutableLongArray will contain.

public ImmutableLongArray
build()

Returns a new immutable array.

private void
ensureRoomFor(int numberToAdd)

private static int
expandedCapacity(int oldCapacity, int minCapacity)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

arrayback to summary
private long[] array
countback to summary
private int count

Constructor Detail

Builderback to summary
pack-priv Builder(int initialCapacity)

Method Detail

addback to summary
public ImmutableLongArray.Builder add(long value)

Appends value to the end of the values the built ImmutableLongArray will contain.

Annotations
@CanIgnoreReturnValue
addAllback to summary
public ImmutableLongArray.Builder addAll(long[] values)

Appends values, in order, to the end of the values the built ImmutableLongArray will contain.

Annotations
@CanIgnoreReturnValue
addAllback to summary
public ImmutableLongArray.Builder addAll(Iterable<Long> values)

Appends values, in order, to the end of the values the built ImmutableLongArray will contain.

Annotations
@CanIgnoreReturnValue
addAllback to summary
public ImmutableLongArray.Builder addAll(Collection<Long> values)

Appends values, in order, to the end of the values the built ImmutableLongArray will contain.

Annotations
@CanIgnoreReturnValue
addAllback to summary
public ImmutableLongArray.Builder addAll(LongStream stream)

Appends all values from stream, in order, to the end of the values the built ImmutableLongArray will contain.

Annotations
@CanIgnoreReturnValue
addAllback to summary
public ImmutableLongArray.Builder addAll(ImmutableLongArray values)

Appends values, in order, to the end of the values the built ImmutableLongArray will contain.

Annotations
@CanIgnoreReturnValue
buildback 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 .build().trimmed().

ensureRoomForback to summary
private void ensureRoomFor(int numberToAdd)
expandedCapacityback to summary
private static int expandedCapacity(int oldCapacity, int minCapacity)