public final class Objects2
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static boolean |
equalsIgnoreCase(java.lang.String string,
java.lang.String... alternatives)
Checks if
string is equal to, ignoring case, any of the String s in alternatives . |
static <T> java.lang.String |
optional(java.lang.String left,
java.lang.String right,
java.lang.String separator,
java.util.List<?> objects) |
static java.lang.String |
optional(java.lang.String left,
java.lang.String right,
java.lang.String separator,
java.lang.Object... objects) |
static java.lang.String |
repeat(java.lang.String string,
int repetition)
Returns a
String that consists of string repeated repetition times. |
static <T> T[] |
requireDeepNonNull(T[] objects) |
static <T> T[] |
requireDeepNonNull(T[] objects,
java.lang.String name) |
static byte |
requireRange(byte value,
byte minimum,
byte maximum)
Checks that the specified value is within a given closed range, such as [minimum, maximum].
|
static byte |
requireRange(byte value,
byte minimum,
byte maximum,
java.lang.String name)
Checks that the specified value is within a given closed range, such as [minimum, maximum].
|
static char |
requireRange(char value,
char minimum,
char maximum)
Checks that the specified value is within a given closed range, such as [minimum, maximum].
|
static char |
requireRange(char value,
char minimum,
char maximum,
java.lang.String name)
Checks that the specified value is within a given closed range, such as [minimum, maximum].
|
static double |
requireRange(double value,
double minimum,
double maximum)
Checks that the specified value is within a given closed range, such as [minimum, maximum].
|
static double |
requireRange(double value,
double minimum,
double maximum,
java.lang.String name)
Checks that the specified value is within a given closed range, such as [minimum, maximum].
|
static float |
requireRange(float value,
float minimum,
float maximum)
Checks that the specified value is within a given closed range, such as [minimum, maximum].
|
static float |
requireRange(float value,
float minimum,
float maximum,
java.lang.String name)
Checks that the specified value is within a given closed range, such as [minimum, maximum].
|
static int[] |
requireRange(int[] array,
int minimum,
int maximum)
Returns
array , but only if its elements are within the range of minimum (inclusive) and maximum (inclusive). |
static int |
requireRange(int value,
int minimum,
int maximum)
Checks that the specified value is within a given closed range, such as [minimum, maximum].
|
static int |
requireRange(int value,
int minimum,
int maximum,
java.lang.String name)
Checks that the specified value is within a given closed range, such as [minimum, maximum].
|
static long |
requireRange(long value,
long minimum,
long maximum)
Checks that the specified value is within a given closed range, such as [minimum, maximum].
|
static long |
requireRange(long value,
long minimum,
long maximum,
java.lang.String name)
Checks that the specified value is within a given closed range, such as [minimum, maximum].
|
static short |
requireRange(short value,
short minimum,
short maximum)
Checks that the specified value is within a given closed range, such as [minimum, maximum].
|
static short |
requireRange(short value,
short minimum,
short maximum,
java.lang.String name)
Checks that the specified value is within a given closed range, such as [minimum, maximum].
|
public static boolean equalsIgnoreCase(java.lang.String string, java.lang.String... alternatives)
string
is equal to, ignoring case, any of the String
s in alternatives
.
Returns true
if, and only if, string
is equal to, ignoring case, any of the String
s in alternatives
, false
otherwise.
If either string
or alternatives
are null
, a NullPointerException
will be thrown.
string
- the String
to checkalternatives
- an array of alternative String
strue
if, and only if, string
is equal to, ignoring case, any of the String
s in alternatives
, false
otherwisejava.lang.NullPointerException
- thrown if, and only if, either string
or alternatives
are null
public static byte requireRange(byte value, byte minimum, byte maximum)
Returns the value itself.
If value
is less than minimum
or greater than maximum
, an IllegalArgumentException
will be thrown.
This method is implemented in terms of requireRange(byte, byte, byte, String)
, with a name of "value"
.
value
- the value to checkminimum
- the minimum (inclusive) bound of the rangemaximum
- the maximum (inclusive) bound of the rangejava.lang.IllegalArgumentException
- thrown if, and only if, value
is less than minimum
or greater than maximum
public static byte requireRange(byte value, byte minimum, byte maximum, java.lang.String name)
Returns the value itself.
If value
is less than minimum
or greater than maximum
, an IllegalArgumentException
will be thrown.
If name
is null
, a NullPointerException
will be thrown.
value
- the value to checkminimum
- the minimum (inclusive) bound of the rangemaximum
- the maximum (inclusive) bound of the rangename
- the name of the value, that will be part of the message to the IllegalArgumentException
, if thrownjava.lang.IllegalArgumentException
- thrown if, and only if, value
is less than minimum
or greater than maximum
java.lang.NullPointerException
- thrown if, and only if, name
is null
public static char requireRange(char value, char minimum, char maximum)
Returns the value itself.
If value
is less than minimum
or greater than maximum
, an IllegalArgumentException
will be thrown.
This method is implemented in terms of requireRange(char, char, char, String)
, with a name of "value"
.
value
- the value to checkminimum
- the minimum (inclusive) bound of the rangemaximum
- the maximum (inclusive) bound of the rangejava.lang.IllegalArgumentException
- thrown if, and only if, value
is less than minimum
or greater than maximum
public static char requireRange(char value, char minimum, char maximum, java.lang.String name)
Returns the value itself.
If value
is less than minimum
or greater than maximum
, an IllegalArgumentException
will be thrown.
If name
is null
, a NullPointerException
will be thrown.
value
- the value to checkminimum
- the minimum (inclusive) bound of the rangemaximum
- the maximum (inclusive) bound of the rangename
- the name of the value, that will be part of the message to the IllegalArgumentException
, if thrownjava.lang.IllegalArgumentException
- thrown if, and only if, value
is less than minimum
or greater than maximum
java.lang.NullPointerException
- thrown if, and only if, name
is null
public static double requireRange(double value, double minimum, double maximum)
Returns the value itself.
If value
is less than minimum
or greater than maximum
, an IllegalArgumentException
will be thrown.
This method is implemented in terms of requireRange(double, double, double, String)
, with a name of "value"
.
value
- the value to checkminimum
- the minimum (inclusive) bound of the rangemaximum
- the maximum (inclusive) bound of the rangejava.lang.IllegalArgumentException
- thrown if, and only if, value
is less than minimum
or greater than maximum
public static double requireRange(double value, double minimum, double maximum, java.lang.String name)
Returns the value itself.
If value
is less than minimum
or greater than maximum
, an IllegalArgumentException
will be thrown.
If name
is null
, a NullPointerException
will be thrown.
value
- the value to checkminimum
- the minimum (inclusive) bound of the rangemaximum
- the maximum (inclusive) bound of the rangename
- the name of the value, that will be part of the message to the IllegalArgumentException
, if thrownjava.lang.IllegalArgumentException
- thrown if, and only if, value
is less than minimum
or greater than maximum
java.lang.NullPointerException
- thrown if, and only if, name
is null
public static float requireRange(float value, float minimum, float maximum)
Returns the value itself.
If value
is less than minimum
or greater than maximum
, an IllegalArgumentException
will be thrown.
This method is implemented in terms of requireRange(float, float, float, String)
, with a name of "value"
.
value
- the value to checkminimum
- the minimum (inclusive) bound of the rangemaximum
- the maximum (inclusive) bound of the rangejava.lang.IllegalArgumentException
- thrown if, and only if, value
is less than minimum
or greater than maximum
public static float requireRange(float value, float minimum, float maximum, java.lang.String name)
Returns the value itself.
If value
is less than minimum
or greater than maximum
, an IllegalArgumentException
will be thrown.
If name
is null
, a NullPointerException
will be thrown.
value
- the value to checkminimum
- the minimum (inclusive) bound of the rangemaximum
- the maximum (inclusive) bound of the rangename
- the name of the value, that will be part of the message to the IllegalArgumentException
, if thrownjava.lang.IllegalArgumentException
- thrown if, and only if, value
is less than minimum
or greater than maximum
java.lang.NullPointerException
- thrown if, and only if, name
is null
public static int requireRange(int value, int minimum, int maximum)
Returns the value itself.
If value
is less than minimum
or greater than maximum
, an IllegalArgumentException
will be thrown.
This method is implemented in terms of requireRange(int, int, int, String)
, with a name of "value"
.
value
- the value to checkminimum
- the minimum (inclusive) bound of the rangemaximum
- the maximum (inclusive) bound of the rangejava.lang.IllegalArgumentException
- thrown if, and only if, value
is less than minimum
or greater than maximum
public static int requireRange(int value, int minimum, int maximum, java.lang.String name)
Returns the value itself.
If value
is less than minimum
or greater than maximum
, an IllegalArgumentException
will be thrown.
If name
is null
, a NullPointerException
will be thrown.
value
- the value to checkminimum
- the minimum (inclusive) bound of the rangemaximum
- the maximum (inclusive) bound of the rangename
- the name of the value, that will be part of the message to the IllegalArgumentException
, if thrownjava.lang.IllegalArgumentException
- thrown if, and only if, value
is less than minimum
or greater than maximum
java.lang.NullPointerException
- thrown if, and only if, name
is null
public static int[] requireRange(int[] array, int minimum, int maximum)
array
, but only if its elements are within the range of minimum
(inclusive) and maximum
(inclusive).
If one or more of its elements are not within said range, an IllegalArgumentException
will be thrown.
If array
is null
, a NullPointerException
will be thrown.
array
- the array with elements to verifyminimum
- the minimum value allowed (inclusive)maximum
- the maximum value allowed (inclusive)array
, but only if its elements are within the range of minimum
(inclusive) and maximum
(inclusive)java.lang.IllegalArgumentException
- thrown if, and only if, array
contains an element that is less than minimum
or greater than maximum
java.lang.NullPointerException
- thrown if, and only if, array
is null
public static long requireRange(long value, long minimum, long maximum)
Returns the value itself.
If value
is less than minimum
or greater than maximum
, an IllegalArgumentException
will be thrown.
This method is implemented in terms of requireRange(long, long, long, String)
, with a name of "value"
.
value
- the value to checkminimum
- the minimum (inclusive) bound of the rangemaximum
- the maximum (inclusive) bound of the rangejava.lang.IllegalArgumentException
- thrown if, and only if, value
is less than minimum
or greater than maximum
public static long requireRange(long value, long minimum, long maximum, java.lang.String name)
Returns the value itself.
If value
is less than minimum
or greater than maximum
, an IllegalArgumentException
will be thrown.
If name
is null
, a NullPointerException
will be thrown.
value
- the value to checkminimum
- the minimum (inclusive) bound of the rangemaximum
- the maximum (inclusive) bound of the rangename
- the name of the value, that will be part of the message to the IllegalArgumentException
, if thrownjava.lang.IllegalArgumentException
- thrown if, and only if, value
is less than minimum
or greater than maximum
java.lang.NullPointerException
- thrown if, and only if, name
is null
public static short requireRange(short value, short minimum, short maximum)
Returns the value itself.
If value
is less than minimum
or greater than maximum
, an IllegalArgumentException
will be thrown.
This method is implemented in terms of requireRange(short, short, short, String)
, with a name of "value"
.
value
- the value to checkminimum
- the minimum (inclusive) bound of the rangemaximum
- the maximum (inclusive) bound of the rangejava.lang.IllegalArgumentException
- thrown if, and only if, value
is less than minimum
or greater than maximum
public static short requireRange(short value, short minimum, short maximum, java.lang.String name)
Returns the value itself.
If value
is less than minimum
or greater than maximum
, an IllegalArgumentException
will be thrown.
If name
is null
, a NullPointerException
will be thrown.
value
- the value to checkminimum
- the minimum (inclusive) bound of the rangemaximum
- the maximum (inclusive) bound of the rangename
- the name of the value, that will be part of the message to the IllegalArgumentException
, if thrownjava.lang.IllegalArgumentException
- thrown if, and only if, value
is less than minimum
or greater than maximum
java.lang.NullPointerException
- thrown if, and only if, name
is null
public static java.lang.String optional(java.lang.String left, java.lang.String right, java.lang.String separator, java.lang.Object... objects)
public static <T> java.lang.String optional(java.lang.String left, java.lang.String right, java.lang.String separator, java.util.List<?> objects)
public static java.lang.String repeat(java.lang.String string, int repetition)
String
that consists of string
repeated repetition
times.
If string
is null
, the String
literal "null"
will be repeated repetition
times.
If repetition
is less than or equal to 0
, an empty String
will be returned.
string
- the String
to repeatrepetition
- how many times string
should be repeatedString
that consists of string
repeated repetition
timespublic static <T> T[] requireDeepNonNull(T[] objects)
public static <T> T[] requireDeepNonNull(T[] objects, java.lang.String name)