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

public final Class Longs

extends Object
Class Inheritance
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkElementIndex, .Preconditions.checkNotNull, .Preconditions.checkPositionIndexes

Static utility methods pertaining to long primitives, that are not already found in either Long or Arrays.

See the Guava User Guide article on primitive utilities.

Author
Kevin Bourrillion
Since
1.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
private static enum
private static class
private static class

Field Summary

Modifier and TypeField and Description
public static final int
BYTES

The number of bytes required to represent a primitive long value.

public static final long
MAX_POWER_OF_TWO

The largest power of two that can be represented as a long.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static List<Long>

Returns:

a list view of the array
asList
(long...
the array to back the list
backingArray
)

Returns a fixed-size list backed by the specified array, similar to Arrays#asList(Object[]).

private static int
checkNoOverflow(long result)

public static int

Returns:

a negative value if a is less than b; a positive value if a is greater than b; or zero if they are equal
compare
(long
the first long to compare
a
,
long
the second long to compare
b
)

Compares the two specified long values.

public static long[]

Returns:

a single array containing all the values from the source arrays, in order
concat
(long[]...
zero or more long arrays
arrays
)

Returns the values from each provided array combined into a single array.

public static long
constrainToRange(long
the long value to constrain
value
,
long
the lower bound (inclusive) of the range to constrain value to
min
,
long
the upper bound (inclusive) of the range to constrain value to
max
)

Returns the value nearest to value which is within the closed range [min..max].

public static boolean

Returns:

true if array[i] == target for some value of i
contains
(long[]
an array of long values, possibly empty
array
,
long
a primitive long value
target
)

Returns true if target is present as an element anywhere in array.

public static long[]

Returns:

an array containing the values of array, with guaranteed minimum length minLength
ensureCapacity
(long[]
the source array
array
,
int
the minimum length the returned array must guarantee
minLength
,
int
an extra amount to "grow" the array by if growth is necessary
padding
)

Returns an array containing the same values as array, but guaranteed to be of a specified minimum length.

public static long
fromByteArray(byte[] bytes)

Returns the long value whose big-endian representation is stored in the first 8 bytes of bytes; equivalent to ByteBuffer.wrap(bytes).getLong().

public static long
fromBytes(byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7, byte b8)

Returns the long value whose byte representation is the given 8 bytes, in big-endian order; equivalent to Longs.fromByteArray(new byte[] {b1, b2, b3, b4, b5, b6, b7, b8}).

public static int

Returns:

a hash code for the value
hashCode
(long
a primitive long value
value
)

Returns a hash code for value; equal to the result of invoking ((Long) value).hashCode().

public static int

Returns:

the least index i for which array[i] == target, or -1 if no such index exists.
indexOf
(long[]
an array of long values, possibly empty
array
,
long
a primitive long value
target
)

Returns the index of the first appearance of the value target in array.

private static int
indexOf(long[] array, long target, int start, int end)

public static int
indexOf(long[]
the array to search for the sequence target
array
,
long[]
the array to search for as a sub-sequence of array
target
)

Returns the start position of the first occurrence of the specified target within array, or -1 if there is no such occurrence.

public static String
join(String
the text that should appear between consecutive values in the resulting string (but not at the start or end)
separator
,
long...
an array of long values, possibly empty
array
)

Returns a string containing the supplied long values separated by separator.

public static int

Returns:

the greatest index i for which array[i] == target, or -1 if no such index exists.
lastIndexOf
(long[]
an array of long values, possibly empty
array
,
long
a primitive long value
target
)

Returns the index of the last appearance of the value target in array.

private static int
lastIndexOf(long[] array, long target, int start, int end)

public static Comparator<long[]>
lexicographicalComparator()

Returns a comparator that compares two long arrays lexicographically.

public static long

Returns:

the value present in array that is greater than or equal to every other value in the array
max
(long...
a nonempty array of long values
array
)

Returns the greatest value present in array.

public static long

Returns:

the value present in array that is less than or equal to every other value in the array
min
(long...
a nonempty array of long values
array
)

Returns the least value present in array.

public static void
reverse(long[] array)

Reverses the elements of array.

public static void
reverse(long[] array, int fromIndex, int toIndex)

Reverses the elements of array between fromIndex inclusive and toIndex exclusive.

public static void
rotate(long[] array, int distance)

Performs a right rotation of array of "distance" places, so that the first element is moved to index "distance", and the element at index i ends up at index (distance + i) mod array.length.

public static void
rotate(long[] array, int distance, int fromIndex, int toIndex)

Performs a right rotation of array between fromIndex inclusive and toIndex exclusive.

public static void
sortDescending(long[] array)

Sorts the elements of array in descending order.

public static void
sortDescending(long[] array, int fromIndex, int toIndex)

Sorts the elements of array between fromIndex inclusive and toIndex exclusive in descending order.

public static Converter<String, Long>
stringConverter()

Returns a serializable converter object that converts between strings and longs using Long#decode and Long#toString().

public static long[]

Returns:

an array containing the same values as collection, in the same order, converted to primitives
toArray
(Collection<? extends Number>
a collection of Number instances
collection
)

Returns an array containing each value of collection, converted to a long value in the manner of Number#longValue.

public static byte[]
toByteArray(long value)

Returns a big-endian representation of value in an 8-element byte array; equivalent to ByteBuffer.allocate(8).putLong(value).array().

public static Long

Returns:

the long value represented by string, or null if string has a length of zero or cannot be parsed as a long value
tryParse
(String
the string representation of a long value
string
)

Parses the specified string as a signed decimal long value.

public static Long

Returns:

the long value represented by string using radix, or null if string has a length of zero or cannot be parsed as a long value
tryParse
(String
the string representation of a long value
string
,
int
the radix to use when parsing
radix
)

Parses the specified string as a signed long value using the specified radix.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait