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

public final Class Doubles

extends DoublesMethodsForWeb
Class Inheritance
Annotations
@GwtCompatible
emulated:true
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkElementIndex, .Preconditions.checkNotNull, .Preconditions.checkPositionIndexes, .Strings.lenientFormat, java.lang.Double.NEGATIVE_INFINITY, .Double.POSITIVE_INFINITY

Static utility methods pertaining to double primitives, that are not already found in either Double 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
private static class
private static class
private static enum

Field Summary

Modifier and TypeField and Description
public static final int
BYTES

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

pack-priv static final Pattern
FLOATING_POINT_PATTERN

This is adapted from the regex suggested by Double#valueOf(String) for prevalidating inputs.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static List<Double>

Returns:

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

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

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
(double
the first double to compare
a
,
double
the second double to compare
b
)

Compares the two specified double values.

public static double[]

Returns:

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

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

public static double
constrainToRange(double
the double value to constrain
value
,
double
the lower bound (inclusive) of the range to constrain value to
min
,
double
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
(double[]
an array of double values, possibly empty
array
,
double
a primitive double value
target
)

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

public static double[]

Returns:

an array containing the values of array, with guaranteed minimum length minLength
ensureCapacity
(double[]
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.

private static Pattern
public static int

Returns:

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

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

public static int

Returns:

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

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

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

public static int
indexOf(double[]
the array to search for the sequence target
array
,
double[]
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 boolean
isFinite(double value)

Returns true if value represents a real number.

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
,
double...
an array of double values, possibly empty
array
)

Returns a string containing the supplied double values, converted to strings as specified by Double#toString(double), and separated by separator.

public static int

Returns:

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

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

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

public static Comparator<double[]>
lexicographicalComparator()

Returns a comparator that compares two double arrays lexicographically.

public static double

Returns:

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

Returns the greatest value present in array, using the same rules of comparison as Math#max(double, double).

public static double

Returns:

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

Returns the least value present in array, using the same rules of comparison as Math#min(double, double).

public static void
reverse(double[] array)

Reverses the elements of array.

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

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

public static void
rotate(double[] 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(double[] array, int distance, int fromIndex, int toIndex)

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

public static void
sortDescending(double[] array)

Sorts the elements of array in descending order.

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

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

public static Converter<String, Double>
stringConverter()

Returns a serializable converter object that converts between strings and doubles using Double#valueOf and Double#toString().

public static double[]

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 double value in the manner of Number#doubleValue.

public static Double

Returns:

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

Parses the specified string as a double-precision floating point value.