javadoc.com.google.common.primitives.Floats.html Maven / Gradle / Ivy
Floats (Guava: Google Core Libraries for Java 11.0.1 API)
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
com.google.common.primitives
Class Floats
java.lang.Object
com.google.common.primitives.Floats
@GwtCompatible
public final class Floats
- extends Object
Static utility methods pertaining to float
primitives, that are not
already found in either Float
or Arrays
.
- Since:
- 1.0
- Author:
- Kevin Bourrillion
Field Summary | |
---|---|
static int |
BYTES
The number of bytes required to represent a primitive float
value. |
Method Summary | |
---|---|
static List<Float> |
asList(float... backingArray)
Returns a fixed-size list backed by the specified array, similar to Arrays.asList(Object[]) . |
static int |
compare(float a,
float b)
Compares the two specified float values using Float.compare(float, float) . |
static float[] |
concat(float[]... arrays)
Returns the values from each provided array combined into a single array. |
static boolean |
contains(float[] array,
float target)
Returns true if target is present as an element anywhere in
array . |
static float[] |
ensureCapacity(float[] array,
int minLength,
int padding)
Returns an array containing the same values as array , but
guaranteed to be of a specified minimum length. |
static int |
hashCode(float value)
Returns a hash code for value ; equal to the result of invoking
((Float) value).hashCode() . |
static int |
indexOf(float[] array,
float target)
Returns the index of the first appearance of the value target in
array . |
static int |
indexOf(float[] array,
float[] target)
Returns the start position of the first occurrence of the specified target within array , or -1 if there is no such occurrence. |
static boolean |
isFinite(float value)
Returns true if value represents a real number. |
static String |
join(String separator,
float... array)
Returns a string containing the supplied float values, converted
to strings as specified by Float.toString(float) , and separated by
separator . |
static int |
lastIndexOf(float[] array,
float target)
Returns the index of the last appearance of the value target in
array . |
static Comparator<float[]> |
lexicographicalComparator()
Returns a comparator that compares two float arrays
lexicographically. |
static float |
max(float... array)
Returns the greatest value present in array , using the same rules
of comparison as Math.min(float, float) . |
static float |
min(float... array)
Returns the least value present in array , using the same rules of
comparison as Math.min(float, float) . |
static float[] |
toArray(Collection<Float> collection)
Copies a collection of Float instances into a new array of
primitive float values. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
BYTES
public static final int BYTES
- The number of bytes required to represent a primitive
float
value.- Since:
- 10.0
- See Also:
- Constant Field Values
Method Detail |
---|
hashCode
public static int hashCode(float value)
- Returns a hash code for
value
; equal to the result of invoking((Float) value).hashCode()
.- Parameters:
value
- a primitivefloat
value- Returns:
- a hash code for the value
compare
public static int compare(float a, float b)
- Compares the two specified
float
values usingFloat.compare(float, float)
. You may prefer to invoke that method directly; this method exists only for consistency with the other utilities in this package.- Parameters:
a
- the firstfloat
to compareb
- the secondfloat
to compare- Returns:
- the result of invoking
Float.compare(float, float)
isFinite
public static boolean isFinite(float value)
- Returns
true
ifvalue
represents a real number. This is equivalent to, but not necessarily implemented as,!(Float.isInfinite(value) || Float.isNaN(value))
.- Since:
- 10.0
contains
public static boolean contains(float[] array, float target)
- Returns
true
iftarget
is present as an element anywhere inarray
. Note that this always returnsfalse
whentarget
isNaN
.- Parameters:
array
- an array offloat
values, possibly emptytarget
- a primitivefloat
value- Returns:
true
ifarray[i] == target
for some value ofi
indexOf
public static int indexOf(float[] array, float target)
- Returns the index of the first appearance of the value
target
inarray
. Note that this always returns-1
whentarget
isNaN
.- Parameters:
array
- an array offloat
values, possibly emptytarget
- a primitivefloat
value- Returns:
- the least index
i
for whicharray[i] == target
, or-1
if no such index exists.
indexOf
public static int indexOf(float[] array, float[] target)
- Returns the start position of the first occurrence of the specified
target
withinarray
, or-1
if there is no such occurrence.More formally, returns the lowest index
i
such thatjava.util.Arrays.copyOfRange(array, i, i + target.length)
contains exactly the same elements astarget
.Note that this always returns
-1
whentarget
containsNaN
.- Parameters:
array
- the array to search for the sequencetarget
target
- the array to search for as a sub-sequence ofarray
lastIndexOf
public static int lastIndexOf(float[] array, float target)
- Returns the index of the last appearance of the value
target
inarray
. Note that this always returns-1
whentarget
isNaN
.- Parameters:
array
- an array offloat
values, possibly emptytarget
- a primitivefloat
value- Returns:
- the greatest index
i
for whicharray[i] == target
, or-1
if no such index exists.
min
public static float min(float... array)
- Returns the least value present in
array
, using the same rules of comparison asMath.min(float, float)
.- Parameters:
array
- a nonempty array offloat
values- Returns:
- the value present in
array
that is less than or equal to every other value in the array - Throws:
IllegalArgumentException
- ifarray
is empty
max
public static float max(float... array)
- Returns the greatest value present in
array
, using the same rules of comparison asMath.min(float, float)
.- Parameters:
array
- a nonempty array offloat
values- Returns:
- the value present in
array
that is greater than or equal to every other value in the array - Throws:
IllegalArgumentException
- ifarray
is empty
concat
public static float[] concat(float[]... arrays)
- Returns the values from each provided array combined into a single array.
For example,
concat(new float[] {a, b}, new float[] {}, new float[] {c}
returns the array{a, b, c}
.- Parameters:
arrays
- zero or morefloat
arrays- Returns:
- a single array containing all the values from the source arrays, in order
ensureCapacity
public static float[] ensureCapacity(float[] array, int minLength, int padding)
- Returns an array containing the same values as
array
, but guaranteed to be of a specified minimum length. Ifarray
already has a length of at leastminLength
, it is returned directly. Otherwise, a new array of sizeminLength + padding
is returned, containing the values ofarray
, and zeroes in the remaining places.- Parameters:
array
- the source arrayminLength
- the minimum length the returned array must guaranteepadding
- an extra amount to "grow" the array by if growth is necessary- Returns:
- an array containing the values of
array
, with guaranteed minimum lengthminLength
- Throws:
IllegalArgumentException
- ifminLength
orpadding
is negative
join
public static String join(String separator, float... array)
- Returns a string containing the supplied
float
values, converted to strings as specified byFloat.toString(float)
, and separated byseparator
. For example,join("-", 1.0f, 2.0f, 3.0f)
returns the string"1.0-2.0-3.0"
.Note that
Float.toString(float)
formatsfloat
differently in GWT. In the previous example, it returns the string"1-2-3"
.- Parameters:
separator
- the text that should appear between consecutive values in the resulting string (but not at the start or end)array
- an array offloat
values, possibly empty
lexicographicalComparator
public static Comparator<float[]> lexicographicalComparator()
- Returns a comparator that compares two
float
arrays lexicographically. That is, it compares, usingcompare(float, float)
), the first pair of values that follow any common prefix, or when one array is a prefix of the other, treats the shorter array as the lesser. For example,[] < [1.0f] < [1.0f, 2.0f] < [2.0f]
.The returned comparator is inconsistent with
Object.equals(Object)
(since arrays support only identity equality), but it is consistent withArrays.equals(float[], float[])
.- Since:
- 2.0
- See Also:
- Lexicographical order article at Wikipedia
toArray
public static float[] toArray(Collection<Float> collection)
- Copies a collection of
Float
instances into a new array of primitivefloat
values.Elements are copied from the argument collection as if by
collection.toArray()
. Calling this method is as thread-safe as calling that method.- Parameters:
collection
- a collection ofFloat
objects- Returns:
- an array containing the same values as
collection
, in the same order, converted to primitives - Throws:
NullPointerException
- ifcollection
or any of its elements is null
asList
public static List<Float> asList(float... backingArray)
- Returns a fixed-size list backed by the specified array, similar to
Arrays.asList(Object[])
. The list supportsList.set(int, Object)
, but any attempt to set a value tonull
will result in aNullPointerException
.The returned list maintains the values, but not the identities, of
Float
objects written to or read from it. For example, whetherlist.get(0) == list.get(0)
is true for the returned list is unspecified.The returned list may have unexpected behavior if it contains
NaN
, or ifNaN
is used as a parameter to any of its methods.- Parameters:
backingArray
- the array to back the list- Returns:
- a list view of the array
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2010-2012. All Rights Reserved.