Class Ints
- java.lang.Object
-
- com.google.common.primitives.Ints
-
@GwtCompatible(emulated=true) @Deprecated(since="2022-12-01") public final class Ints extends java.lang.Object
Deprecated.The Google Guava Core Libraries are deprecated and will not be part of the AEM SDK after April 2023Static utility methods pertaining tointprimitives, that are not already found in eitherIntegerorArrays.See the Guava User Guide article on primitive utilities.
- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description static intBYTESDeprecated.The number of bytes required to represent a primitiveintvalue.static intMAX_POWER_OF_TWODeprecated.The largest power of two that can be represented as anint.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.util.List<java.lang.Integer>asList(int... backingArray)Deprecated.Returns a fixed-size list backed by the specified array, similar toArrays.asList(Object[]).static intcheckedCast(long value)Deprecated.Returns theintvalue that is equal tovalue, if possible.static intcompare(int a, int b)Deprecated.Compares the two specifiedintvalues.static int[]concat(int[]... arrays)Deprecated.Returns the values from each provided array combined into a single array.static booleancontains(int[] array, int target)Deprecated.Returnstrueiftargetis present as an element anywhere inarray.static int[]ensureCapacity(int[] array, int minLength, int padding)Deprecated.Returns an array containing the same values asarray, but guaranteed to be of a specified minimum length.static intfromByteArray(byte[] bytes)Deprecated.Returns theintvalue whose big-endian representation is stored in the first 4 bytes ofbytes; equivalent toByteBuffer.wrap(bytes).getInt().static intfromBytes(byte b1, byte b2, byte b3, byte b4)Deprecated.Returns theintvalue whose byte representation is the given 4 bytes, in big-endian order; equivalent toInts.fromByteArray(new byte[] {b1, b2, b3, b4}).static inthashCode(int value)Deprecated.Returns a hash code forvalue; equal to the result of invoking((Integer) value).hashCode().static intindexOf(int[] array, int target)Deprecated.Returns the index of the first appearance of the valuetargetinarray.static intindexOf(int[] array, int[] target)Deprecated.Returns the start position of the first occurrence of the specifiedtargetwithinarray, or-1if there is no such occurrence.static java.lang.Stringjoin(java.lang.String separator, int... array)Deprecated.Returns a string containing the suppliedintvalues separated byseparator.static intlastIndexOf(int[] array, int target)Deprecated.Returns the index of the last appearance of the valuetargetinarray.static java.util.Comparator<int[]>lexicographicalComparator()Deprecated.Returns a comparator that compares twointarrays lexicographically.static intmax(int... array)Deprecated.Returns the greatest value present inarray.static intmin(int... array)Deprecated.Returns the least value present inarray.static intsaturatedCast(long value)Deprecated.Returns theintnearest in value tovalue.static int[]toArray(java.util.Collection<? extends java.lang.Number> collection)Deprecated.Returns an array containing each value ofcollection, converted to aintvalue in the manner ofNumber.intValue().static byte[]toByteArray(int value)Deprecated.Returns a big-endian representation ofvaluein a 4-element byte array; equivalent toByteBuffer.allocate(4).putInt(value).array().static java.lang.IntegertryParse(java.lang.String string)Deprecated.Parses the specified string as a signed decimal integer value.
-
-
-
Field Detail
-
BYTES
public static final int BYTES
Deprecated.The number of bytes required to represent a primitiveintvalue.- See Also:
- Constant Field Values
-
MAX_POWER_OF_TWO
public static final int MAX_POWER_OF_TWO
Deprecated.The largest power of two that can be represented as anint.- Since:
- 10.0
- See Also:
- Constant Field Values
-
-
Method Detail
-
hashCode
public static int hashCode(int value)
Deprecated.Returns a hash code forvalue; equal to the result of invoking((Integer) value).hashCode().- Parameters:
value- a primitiveintvalue- Returns:
- a hash code for the value
-
checkedCast
public static int checkedCast(long value)
Deprecated.Returns theintvalue that is equal tovalue, if possible.- Parameters:
value- any value in the range of theinttype- Returns:
- the
intvalue that equalsvalue - Throws:
java.lang.IllegalArgumentException- ifvalueis greater thanInteger.MAX_VALUEor less thanInteger.MIN_VALUE
-
saturatedCast
public static int saturatedCast(long value)
Deprecated.Returns theintnearest in value tovalue.- Parameters:
value- anylongvalue- Returns:
- the same value cast to
intif it is in the range of theinttype,Integer.MAX_VALUEif it is too large, orInteger.MIN_VALUEif it is too small
-
compare
public static int compare(int a, int b)Deprecated.Compares the two specifiedintvalues. The sign of the value returned is the same as that of((Integer) a).compareTo(b).- Parameters:
a- the firstintto compareb- the secondintto compare- Returns:
- a negative value if
ais less thanb; a positive value ifais greater thanb; or zero if they are equal
-
contains
public static boolean contains(int[] array, int target)Deprecated.Returnstrueiftargetis present as an element anywhere inarray.- Parameters:
array- an array ofintvalues, possibly emptytarget- a primitiveintvalue- Returns:
trueifarray[i] == targetfor some value ofi
-
indexOf
public static int indexOf(int[] array, int target)Deprecated.Returns the index of the first appearance of the valuetargetinarray.- Parameters:
array- an array ofintvalues, possibly emptytarget- a primitiveintvalue- Returns:
- the least index
ifor whicharray[i] == target, or-1if no such index exists.
-
indexOf
public static int indexOf(int[] array, int[] target)Deprecated.Returns the start position of the first occurrence of the specifiedtargetwithinarray, or-1if there is no such occurrence.More formally, returns the lowest index
isuch thatjava.util.Arrays.copyOfRange(array, i, i + target.length)contains exactly the same elements astarget.- Parameters:
array- the array to search for the sequencetargettarget- the array to search for as a sub-sequence ofarray
-
lastIndexOf
public static int lastIndexOf(int[] array, int target)Deprecated.Returns the index of the last appearance of the valuetargetinarray.- Parameters:
array- an array ofintvalues, possibly emptytarget- a primitiveintvalue- Returns:
- the greatest index
ifor whicharray[i] == target, or-1if no such index exists.
-
min
public static int min(int... array)
Deprecated.Returns the least value present inarray.- Parameters:
array- a nonempty array ofintvalues- Returns:
- the value present in
arraythat is less than or equal to every other value in the array - Throws:
java.lang.IllegalArgumentException- ifarrayis empty
-
max
public static int max(int... array)
Deprecated.Returns the greatest value present inarray.- Parameters:
array- a nonempty array ofintvalues- Returns:
- the value present in
arraythat is greater than or equal to every other value in the array - Throws:
java.lang.IllegalArgumentException- ifarrayis empty
-
concat
public static int[] concat(int[]... arrays)
Deprecated.Returns the values from each provided array combined into a single array. For example,concat(new int[] {a, b}, new int[] {}, new int[] {c}returns the array{a, b, c}.- Parameters:
arrays- zero or moreintarrays- Returns:
- a single array containing all the values from the source arrays, in order
-
toByteArray
@GwtIncompatible("doesn\'t work") public static byte[] toByteArray(int value)
Deprecated.Returns a big-endian representation ofvaluein a 4-element byte array; equivalent toByteBuffer.allocate(4).putInt(value).array(). For example, the input value0x12131415would yield the byte array{0x12, 0x13, 0x14, 0x15}.If you need to convert and concatenate several values (possibly even of different types), use a shared
ByteBufferinstance, or useByteStreams.newDataOutput()to get a growable buffer.
-
fromByteArray
@GwtIncompatible("doesn\'t work") public static int fromByteArray(byte[] bytes)
Deprecated.Returns theintvalue whose big-endian representation is stored in the first 4 bytes ofbytes; equivalent toByteBuffer.wrap(bytes).getInt(). For example, the input byte array{0x12, 0x13, 0x14, 0x15, 0x33}would yield theintvalue0x12131415.Arguably, it's preferable to use
ByteBuffer; that library exposes much more flexibility at little cost in readability.- Throws:
java.lang.IllegalArgumentException- ifbyteshas fewer than 4 elements
-
fromBytes
@GwtIncompatible("doesn\'t work") public static int fromBytes(byte b1, byte b2, byte b3, byte b4)
Deprecated.Returns theintvalue whose byte representation is the given 4 bytes, in big-endian order; equivalent toInts.fromByteArray(new byte[] {b1, b2, b3, b4}).- Since:
- 7.0
-
ensureCapacity
public static int[] ensureCapacity(int[] array, int minLength, int padding)Deprecated.Returns an array containing the same values asarray, but guaranteed to be of a specified minimum length. Ifarrayalready has a length of at leastminLength, it is returned directly. Otherwise, a new array of sizeminLength + paddingis 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:
java.lang.IllegalArgumentException- ifminLengthorpaddingis negative
-
join
public static java.lang.String join(java.lang.String separator, int... array)Deprecated.Returns a string containing the suppliedintvalues separated byseparator. For example,join("-", 1, 2, 3)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 ofintvalues, possibly empty
-
lexicographicalComparator
public static java.util.Comparator<int[]> lexicographicalComparator()
Deprecated.Returns a comparator that compares twointarrays lexicographically. That is, it compares, usingcompare(int, int)), 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] < [1, 2] < [2].The returned comparator is inconsistent with
Object.equals(Object)(since arrays support only identity equality), but it is consistent withArrays.equals(int[], int[]).- Since:
- 2.0
- See Also:
- Lexicographical order article at Wikipedia
-
toArray
public static int[] toArray(java.util.Collection<? extends java.lang.Number> collection)
Deprecated.Returns an array containing each value ofcollection, converted to aintvalue in the manner ofNumber.intValue().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 ofNumberinstances- Returns:
- an array containing the same values as
collection, in the same order, converted to primitives - Throws:
java.lang.NullPointerException- ifcollectionor any of its elements is null- Since:
- 1.0 (parameter was
Collection<Integer>before 12.0)
-
asList
public static java.util.List<java.lang.Integer> asList(int... backingArray)
Deprecated.Returns a fixed-size list backed by the specified array, similar toArrays.asList(Object[]). The list supportsList.set(int, Object), but any attempt to set a value tonullwill result in aNullPointerException.The returned list maintains the values, but not the identities, of
Integerobjects written to or read from it. For example, whetherlist.get(0) == list.get(0)is true for the returned list is unspecified.- Parameters:
backingArray- the array to back the list- Returns:
- a list view of the array
-
tryParse
@Beta @CheckForNull @GwtIncompatible("TODO") public static java.lang.Integer tryParse(java.lang.String string)
Deprecated.Parses the specified string as a signed decimal integer value. The ASCII character'-'('\u002D') is recognized as the minus sign.Unlike
Integer.parseInt(String), this method returnsnullinstead of throwing an exception if parsing fails.Note that strings prefixed with ASCII
'+'are rejected, even under JDK 7, despite the change toInteger.parseInt(String)for that version.- Parameters:
string- the string representation of an integer value- Returns:
- the integer value represented by
string, ornullifstringhas a length of zero or cannot be parsed as an integer value - Since:
- 11.0
-
-