Class Longs
java.lang.Object
com.pnfsoftware.jeb.util.primitives.Longs
Utility methods for
longs.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcompareUnsigned(long x, long y) Compare two longs as unsigned.static longdivUnsigned(long dividend, long divisor) Divide two longs treated as unsigned.static booleanSafe equality.static booleanSafe equality.static booleanSafe equality.static StringformatHexCollection(Collection<Long> list) Uses a "0x" prefix, ", " separator.static StringformatLongCollection(Collection<Long> collection, Integer radix, String pfx, String sfx, String separator) Format a collection of longs.static longfromInts(int v0, int v1) Create a long from two ints.static longmaxUnsigned(long x, long y) Retrieve the max of two longs treated as unsigned.static longminUnsigned(long x, long y) Retrieve the min of two longs treated as unsigned.range(long cnt) Generate an incremental range of integers from 0 to the provided count.range(long start, long end) Generate an incremental range of integers.range(long start, long end, long step) Generate an iterable range of integers.static longremUnsigned(long dividend, long divisor) Get the division remainder of two longs treated as unsigned.static int[]toInts(long v) Create two ints from a long.static BigIntegertoUnsignedBigInteger(long v) Convert a long treated as unsigned to a big integer.static StringtoUnsignedString(long value) Convert a long to its unsigned decimal string representation.
-
Constructor Details
-
Longs
public Longs()
-
-
Method Details
-
fromInts
public static long fromInts(int v0, int v1) Create a long from two ints. SeetoInts(long)for the reverse operation.- Parameters:
v0- low 32 bitsv1- high 32 bits- Returns:
- the composed long value
-
toInts
public static int[] toInts(long v) Create two ints from a long. SeefromInts(int, int)for the reverse operation.- Parameters:
v- long value- Returns:
- an array of two ints.
-
toUnsignedString
Convert a long to its unsigned decimal string representation.- Parameters:
value- long value- Returns:
- the unsigned decimal representation of
value
-
toUnsignedBigInteger
Convert a long treated as unsigned to a big integer.- Parameters:
v- long value- Returns:
- the unsigned value as a positive big integer
-
compareUnsigned
public static int compareUnsigned(long x, long y) Compare two longs as unsigned.- Parameters:
x- first valuey- second value- Returns:
- a negative value, zero, or a positive value if
xis respectively below, equal to, or aboveyin unsigned order
-
maxUnsigned
public static long maxUnsigned(long x, long y) Retrieve the max of two longs treated as unsigned.- Parameters:
x- first valuey- second value- Returns:
- the greater unsigned value
-
minUnsigned
public static long minUnsigned(long x, long y) Retrieve the min of two longs treated as unsigned.- Parameters:
x- first valuey- second value- Returns:
- the smaller unsigned value
-
divUnsigned
public static long divUnsigned(long dividend, long divisor) Divide two longs treated as unsigned.- Parameters:
dividend- dividend treated as unsigneddivisor- divisor treated as unsigned- Returns:
- the unsigned quotient
-
remUnsigned
public static long remUnsigned(long dividend, long divisor) Get the division remainder of two longs treated as unsigned.- Parameters:
dividend- dividend treated as unsigneddivisor- divisor treated as unsigned- Returns:
- the unsigned remainder
-
formatHexCollection
Uses a "0x" prefix, ", " separator.- Parameters:
list- collection of longs- Returns:
- the formatted hexadecimal collection
-
formatLongCollection
public static String formatLongCollection(Collection<Long> collection, Integer radix, String pfx, String sfx, String separator) Format a collection of longs.- Parameters:
collection- collection of longsradix- optional, default=10pfx- optional, default=nonesfx- optional, default=noneseparator- optional, default=", "- Returns:
- the formatted collection
-
equals
Safe equality.- Parameters:
a- may be nullb- may be null- Returns:
- true if both a and b are null or if their long values are equal
-
equals
Safe equality.- Parameters:
a- may be nullb- value to compare with- Returns:
- true if a is not null and its long value equal to b
-
equals
Safe equality.- Parameters:
a- value to compare withb- may be null- Returns:
- true if b is not null and its long value equal to a
-
range
Generate an iterable range of integers.- Parameters:
start- first value, inclusiveend- exclusivestep- increment (can be negative, cannot be zero)- Returns:
- an iterable range
-
range
Generate an incremental range of integers.- Parameters:
start- first value, inclusiveend- exclusive- Returns:
- an iterable range
-
range
Generate an incremental range of integers from 0 to the provided count.- Parameters:
cnt- exclusive upper bound- Returns:
- an iterable range from 0 to
cnt
-