Package com.globalmentor.java
Class Longs
- java.lang.Object
-
- com.globalmentor.java.Longs
-
public class Longs extends java.lang.Object
Utilities for manipulating long objects.- Author:
- Garret Wilson
-
-
Field Summary
Fields Modifier and Type Field Description static long[]
NO_LONGS
The shared empty array of longs.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
compare(long l1, long l2)
Compares two longs for order.static int
hashCode(long value)
Returns a hash code for a long value.static java.lang.String
toHexString(long value, int length)
Converts a long into a hex string with the specified number of digits.static int
toInt(long value)
Converts a long value to an integer, checking for overflow.
-
-
-
Method Detail
-
hashCode
public static int hashCode(long value)
Returns a hash code for a long value. This implementation returns the same value used byLong.hashCode()
.- Parameters:
value
- The value for which a hash code should be returned.- Returns:
- The hash code of the long value.
-
toHexString
public static java.lang.String toHexString(long value, int length)
Converts a long into a hex string with the specified number of digits.- Parameters:
value
- The value to convert.length
- The number of digits the returned string should have.- Returns:
- Lowercase hex version of the given value with the correct number of digits, using zeros to pad the left of the string to the correct length.
-
toInt
public static int toInt(long value)
Converts a long value to an integer, checking for overflow.- Parameters:
value
- The value to convert.- Returns:
- The long value as an integer.
- Throws:
java.lang.IllegalArgumentException
- if the given value is smaller thanInteger.MIN_VALUE
or greater thanInteger.MAX_VALUE
.
-
compare
public static int compare(long l1, long l2)
Compares two longs for order.- Parameters:
l1
- The first long to compare.l2
- The second long to compare.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
-
-