Package com.google.common.primitives
Class UnsignedBytes
java.lang.Object
com.google.common.primitives.UnsignedBytes
Deprecated.
The Google Guava Core Libraries are deprecated and will not be part of the AEM SDK after April 2023
Static utility methods pertaining to
byte
primitives that interpret
values as unsigned (that is, any negative value b
is treated
as the positive value 256 + b
). The corresponding methods that treat
the values as signed are found in SignedBytes
, and the methods for
which signedness is not an issue are in Bytes
.
See the Guava User Guide article on primitive utilities.
- Since:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byte
Deprecated.The largest power of two that can be represented as an unsignedbyte
.static final byte
Deprecated.The largest value that fits into an unsigned byte. -
Method Summary
Modifier and TypeMethodDescriptionstatic byte
checkedCast
(long value) Deprecated.Returns thebyte
value that, when treated as unsigned, is equal tovalue
, if possible.static int
compare
(byte a, byte b) Deprecated.Compares the two specifiedbyte
values, treating them as unsigned values between 0 and 255 inclusive.static String
Deprecated.Returns a string containing the suppliedbyte
values separated byseparator
.static Comparator
<byte[]> Deprecated.Returns a comparator that compares twobyte
arrays lexicographically.static byte
max
(byte... array) Deprecated.Returns the greatest value present inarray
.static byte
min
(byte... array) Deprecated.Returns the least value present inarray
.static byte
parseUnsignedByte
(String string) Deprecated.Returns the unsignedbyte
value represented by the given decimal string.static byte
parseUnsignedByte
(String string, int radix) Deprecated.Returns the unsignedbyte
value represented by a string with the given radix.static byte
saturatedCast
(long value) Deprecated.Returns thebyte
value that, when treated as unsigned, is nearest in value tovalue
.static int
toInt
(byte value) Deprecated.Returns the value of the given byte as an integer, when treated as unsigned.static String
toString
(byte x) Deprecated.Returns a string representation of x, where x is treated as unsigned.static String
toString
(byte x, int radix) Deprecated.Returns a string representation ofx
for the given radix, wherex
is treated as unsigned.
-
Field Details
-
MAX_POWER_OF_TWO
public static final byte MAX_POWER_OF_TWODeprecated.The largest power of two that can be represented as an unsignedbyte
.- Since:
- 10.0
- See Also:
-
MAX_VALUE
public static final byte MAX_VALUEDeprecated.The largest value that fits into an unsigned byte.- Since:
- 13.0
- See Also:
-
-
Method Details
-
toInt
public static int toInt(byte value) Deprecated.Returns the value of the given byte as an integer, when treated as unsigned. That is, returnsvalue + 256
ifvalue
is negative;value
itself otherwise.- Since:
- 6.0
-
checkedCast
public static byte checkedCast(long value) Deprecated.Returns thebyte
value that, when treated as unsigned, is equal tovalue
, if possible.- Parameters:
value
- a value between 0 and 255 inclusive- Returns:
- the
byte
value that, when treated as unsigned, equalsvalue
- Throws:
IllegalArgumentException
- ifvalue
is negative or greater than 255
-
saturatedCast
public static byte saturatedCast(long value) Deprecated.Returns thebyte
value that, when treated as unsigned, is nearest in value tovalue
.- Parameters:
value
- anylong
value- Returns:
(byte) 255
ifvalue >= 255
,(byte) 0
ifvalue <= 0
, andvalue
cast tobyte
otherwise
-
compare
public static int compare(byte a, byte b) Deprecated.Compares the two specifiedbyte
values, treating them as unsigned values between 0 and 255 inclusive. For example,(byte) -127
is considered greater than(byte) 127
because it is seen as having the value of positive129
.- Parameters:
a
- the firstbyte
to compareb
- the secondbyte
to compare- Returns:
- a negative value if
a
is less thanb
; a positive value ifa
is greater thanb
; or zero if they are equal
-
min
public static byte min(byte... array) Deprecated.Returns the least value present inarray
.- Parameters:
array
- a nonempty array ofbyte
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 byte max(byte... array) Deprecated.Returns the greatest value present inarray
.- Parameters:
array
- a nonempty array ofbyte
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
-
toString
Deprecated.Returns a string representation of x, where x is treated as unsigned.- Since:
- 13.0
-
toString
Deprecated.Returns a string representation ofx
for the given radix, wherex
is treated as unsigned.- Parameters:
x
- the value to convert to a string.radix
- the radix to use while working withx
- Throws:
IllegalArgumentException
- ifradix
is not betweenCharacter.MIN_RADIX
andCharacter.MAX_RADIX
.- Since:
- 13.0
-
parseUnsignedByte
Deprecated.Returns the unsignedbyte
value represented by the given decimal string.- Throws:
NumberFormatException
- if the string does not contain a valid unsignedbyte
valueNullPointerException
- ifs
is null (in contrast toByte.parseByte(String)
)- Since:
- 13.0
-
parseUnsignedByte
Deprecated.Returns the unsignedbyte
value represented by a string with the given radix.- Parameters:
string
- the string containing the unsignedbyte
representation to be parsed.radix
- the radix to use while parsingstring
- Throws:
NumberFormatException
- if the string does not contain a valid unsignedbyte
with the given radix, or ifradix
is not betweenCharacter.MIN_RADIX
andCharacter.MAX_RADIX
.NullPointerException
- ifs
is null (in contrast toByte.parseByte(String)
)- Since:
- 13.0
-
join
Deprecated.Returns a string containing the suppliedbyte
values separated byseparator
. For example,join(":", (byte) 1, (byte) 2, (byte) 255)
returns the string"1:2:255"
.- Parameters:
separator
- the text that should appear between consecutive values in the resulting string (but not at the start or end)array
- an array ofbyte
values, possibly empty
-
lexicographicalComparator
Deprecated.Returns a comparator that compares twobyte
arrays lexicographically. That is, it compares, usingcompare(byte, byte)
), 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,[] < [0x01] < [0x01, 0x7F] < [0x01, 0x80] < [0x02]
. Values are treated as unsigned.The returned comparator is inconsistent with
Object.equals(Object)
(since arrays support only identity equality), but it is consistent withArrays.equals(byte[], byte[])
.- Since:
- 2.0
- See Also:
-