public final class Jdk8Methods
extends java.lang.Object
The contents of this class replace functionality available in JDK 8.
| Modifier and Type | Method | Description |
|---|---|---|
static int |
compareInts(int a,
int b) |
Compares two ints.
|
static int |
compareLongs(long a,
long b) |
Compares two longs.
|
static boolean |
equals(java.lang.Object a,
java.lang.Object b) |
Compares two objects.
|
static int |
floorDiv(int a,
int b) |
Returns the floor division.
|
static long |
floorDiv(long a,
long b) |
Returns the floor division.
|
static int |
floorMod(int a,
int b) |
Returns the floor modulus.
|
static int |
floorMod(long a,
int b) |
Returns the floor modulus.
|
static long |
floorMod(long a,
long b) |
Returns the floor modulus.
|
static <T> T |
requireNonNull(T value) |
Ensures that the argument is non-null.
|
static <T> T |
requireNonNull(T value,
java.lang.String parameterName) |
Ensures that the argument is non-null.
|
static int |
safeAdd(int a,
int b) |
Safely adds two int values.
|
static long |
safeAdd(long a,
long b) |
Safely adds two long values.
|
static int |
safeMultiply(int a,
int b) |
Safely multiply one int by another.
|
static long |
safeMultiply(long a,
int b) |
Safely multiply a long by an int.
|
static long |
safeMultiply(long a,
long b) |
Multiply two values throwing an exception if overflow occurs.
|
static int |
safeSubtract(int a,
int b) |
Safely subtracts one int from another.
|
static long |
safeSubtract(long a,
long b) |
Safely subtracts one long from another.
|
static int |
safeToInt(long value) |
Safely convert a long to an int.
|
public static <T> T requireNonNull(T value)
T - the value typevalue - the value to checkjava.lang.NullPointerException - if the value is nullpublic static <T> T requireNonNull(T value,
java.lang.String parameterName)
T - the value typevalue - the value to checkparameterName - the name of the parameterjava.lang.NullPointerException - if the value is nullpublic static boolean equals(java.lang.Object a,
java.lang.Object b)
a - the first valueb - the second valuepublic static int compareInts(int a,
int b)
a - the first valueb - the second valuepublic static int compareLongs(long a,
long b)
a - the first valueb - the second valuepublic static int safeAdd(int a,
int b)
a - the first valueb - the second valuejava.lang.ArithmeticException - if the result overflows an intpublic static long safeAdd(long a,
long b)
a - the first valueb - the second valuejava.lang.ArithmeticException - if the result overflows a longpublic static int safeSubtract(int a,
int b)
a - the first valueb - the second value to subtract from the firstjava.lang.ArithmeticException - if the result overflows an intpublic static long safeSubtract(long a,
long b)
a - the first valueb - the second value to subtract from the firstjava.lang.ArithmeticException - if the result overflows a longpublic static int safeMultiply(int a,
int b)
a - the first valueb - the second valuejava.lang.ArithmeticException - if the result overflows an intpublic static long safeMultiply(long a,
int b)
a - the first valueb - the second valuejava.lang.ArithmeticException - if the result overflows a longpublic static long safeMultiply(long a,
long b)
a - the first valueb - the second valuejava.lang.ArithmeticException - if the result overflows a longpublic static int safeToInt(long value)
value - the value to convertjava.lang.ArithmeticException - if the result overflows an intpublic static long floorDiv(long a,
long b)
This returns 0 for floorDiv(0, 4).
This returns -1 for floorDiv(-1, 4).
This returns -1 for floorDiv(-2, 4).
This returns -1 for floorDiv(-3, 4).
This returns -1 for floorDiv(-4, 4).
This returns -2 for floorDiv(-5, 4).
a - the dividendb - the divisorpublic static long floorMod(long a,
long b)
This returns 0 for floorMod(0, 4).
This returns 1 for floorMod(-1, 4).
This returns 2 for floorMod(-2, 4).
This returns 3 for floorMod(-3, 4).
This returns 0 for floorMod(-4, 4).
a - the dividendb - the divisorpublic static int floorMod(long a,
int b)
This returns 0 for floorMod(0, 4).
This returns 3 for floorMod(-1, 4).
This returns 2 for floorMod(-2, 4).
This returns 1 for floorMod(-3, 4).
This returns 0 for floorMod(-4, 4).
This returns 3 for floorMod(-5, 4).
a - the dividendb - the divisorpublic static int floorDiv(int a,
int b)
This returns 1 for floorDiv(3, 3).
This returns 0 for floorDiv(2, 3).
This returns 0 for floorDiv(1, 3).
This returns 0 for floorDiv(0, 3).
This returns -1 for floorDiv(-1, 3).
This returns -1 for floorDiv(-2, 3).
This returns -1 for floorDiv(-3, 3).
This returns -2 for floorDiv(-4, 3).
a - the dividendb - the divisorpublic static int floorMod(int a,
int b)
This returns 0 for floorMod(3, 3).
This returns 2 for floorMod(2, 3).
This returns 1 for floorMod(1, 3).
This returns 0 for floorMod(0, 3).
This returns 2 for floorMod(-1, 3).
This returns 1 for floorMod(-2, 3).
This returns 0 for floorMod(-3, 3).
This returns 2 for floorMod(-4, 3).
a - the dividendb - the divisorCopyright © 2007–2018 ThreeTen.org. All rights reserved.