@Deprecated public final class Ints extends Object
int values.| Modifier and Type | Method and Description |
|---|---|
static boolean |
assertIfEnabled(IntBiPredicate requirement,
int value,
int otherValue)
Deprecated.
Asserts that the provided
value and provided otherValue satisfies the provided requirement
if assertions is enabled (i.e. |
static boolean |
assertIfEnabled(IntPredicate requirement,
int value)
Deprecated.
Asserts that the provided
value satisfies the provided requirement if
assertions is enabled (i.e. |
static boolean |
assertIfEnabled(IntTriPredicate requirement,
int value,
int otherFirstValue,
int otherSecondValue)
Deprecated.
Asserts that the provided
value, provided otherFirstValue and provided otherSecondValue
satisfies the provided requirement if assertions is enabled (i.e. |
static IntTriPredicate |
between()
Deprecated.
Returns a predicate that can test if a value is between another first value (inclusive)
and another second value (exclusive) (i.e value ∈ [other first value , other second value) ).
|
static IntTriPredicate |
betweenClosed()
Deprecated.
Returns a predicate that can test if a value is between (closed) another first value (inclusive)
and another second value (inclusive) (i.e value ∈ [other first value , other second value] ).
|
static IntBiPredicate |
betweenZeroAnd()
Deprecated.
Returns a predicate that can test if a value is between zero and another value (exclusive)
(i.e value ∈ [0, other value) ).
|
static IntBiPredicate |
betweenZeroAndClosed()
Deprecated.
Returns a predicate that can test if a value is between zero and another value (inclusive)
(i.e value ∈ [0, other value] ).
|
static IntTriPredicate |
betweenZeroAndReserving()
Deprecated.
Returns a predicate that can test if a value is between zero and another first value (inclusive)
whilst ensuring a value of size defined by another second value can fit.
|
static IntPredicate |
byteConvertible()
Deprecated.
Returns a predicate that can test if a value can fit in a
byte (i.e. |
static IntBiPredicate |
equalTo()
Deprecated.
Returns a predicate that can test if a value is equal to another value.
|
static IntPredicate |
evenPowerOfTwo()
Deprecated.
Returns a predicate that can test if a value is an even power of two
(i.e.
|
static String |
failDescription(IntBiPredicate requirement,
int value,
int otherValue)
Deprecated.
Returns a human-readable form of a failure message provided that the provided
value and
provided otherValue did not satisfy the provided requirement. |
static String |
failDescription(IntPredicate requirement,
int value)
Deprecated.
Returns a human-readable form of a failure message provided that the provided
value did not
satisfy the provided requirement. |
static String |
failDescription(IntTriPredicate requirement,
int value,
int otherFirstValue,
int otherSecondValue)
Deprecated.
Returns a human-readable form of a failure message provided that the provided
value,
provided otherFirstValue and provided otherFirstValue did not satisfy the
provided requirement. |
static IntBiPredicate |
greaterOrEqual()
Deprecated.
Returns a predicate that can test if a value is greater or equal to another value.
|
static IntBiPredicate |
greaterThan()
Deprecated.
Returns a predicate that can test if a value is greater than to another value.
|
static IntPredicate |
intAligned()
Deprecated.
Returns a predicate that can test if a value is int aligned
(i.e.
|
static IntBiPredicate |
lessOrEqual()
Deprecated.
Returns a predicate that can test if a value is less or equal to another value.
|
static IntBiPredicate |
lessThan()
Deprecated.
Returns a predicate that can test if a value is less than to another value.
|
static IntBiPredicate |
log2()
Deprecated.
Returns a predicate that can test if a value is log2 of another value
(i.e.
|
static IntPredicate |
longAligned()
Deprecated.
Returns a predicate that can test if a value is long aligned
(i.e.
|
static IntPredicate |
negative()
Deprecated.
Returns a predicate that can test if a value is negative (i.e.
|
static IntPredicate |
nonNegative()
Deprecated.
Returns a predicate that can test if a value is non-negative (i.e.
|
static IntPredicate |
positive()
Deprecated.
Returns a predicate that can test if a value is positive (i.e.
|
static IntBiPredicate |
powerOfTwo()
Deprecated.
Returns a predicate that can test if a value is a power of two of another value
(i.e.
|
static int |
require(IntBiPredicate requirement,
int value,
int otherValue)
Deprecated.
Returns the provided
value after checking that it and the provided otherValue satisfies the
provided requirement throwing an IllegalArgumentException if the check fails. |
static <X extends RuntimeException> |
require(IntBiPredicate requirement,
int value,
int otherValue,
Function<String,X> exceptionMapper)
Deprecated.
Returns the provided
value after checking that it and the provided otherValue satisfies the
provided requirement throwing an IllegalArgumentException if the check fails. |
static int |
require(IntPredicate requirement,
int value)
Deprecated.
Returns the provided
value after checking that it satisfies the provided requirement throwing
an IllegalArgumentException if the check fails. |
static <X extends RuntimeException> |
require(IntPredicate requirement,
int value,
Function<String,X> exceptionMapper)
Deprecated.
Returns the provided
value after checking that it satisfies the provided requirement throwing
a custom exception if the check fails. |
static int |
require(IntTriPredicate requirement,
int value,
int otherFirstValue,
int otherSecondValue)
Deprecated.
Returns the provided
value after checking that it and the provided otherValue
and the provided otherSecondValue satisfies the provided requirement
throwing an IllegalArgumentException if the check fails. |
static <X extends RuntimeException> |
require(IntTriPredicate requirement,
int value,
int otherFirstValue,
int otherSecondValue,
Function<String,X> exceptionMapper)
Deprecated.
Returns the provided
value after checking that it and the provided otherValue
and the provided otherSecondValue satisfies the provided requirement
throwing an IllegalArgumentException if the check fails. |
static int |
requireNonNegative(int value)
Deprecated.
Returns the provided
value after checking that it is non-negative throwing
an IllegalArgumentException if the check fails. |
static IntPredicate |
shortAligned()
Deprecated.
Returns a predicate that can test if a value is short aligned
(i.e.
|
static IntPredicate |
shortConvertible()
Deprecated.
Returns a predicate that can test if a value can fit in a
short (i.e. |
static IntPredicate |
zero()
Deprecated.
Returns a predicate that can test if a value is zero (i.e.
|
public static int requireNonNegative(int value)
value after checking that it is non-negative throwing
an IllegalArgumentException if the check fails.
This method is designed primarily for doing parameter validation in public methods and constructors, as demonstrated below:
public Foo(int bar) {
this.bar = requireNonNegative(bar);
}
This method is functionally equivalent to:
require(negative().negate(), value);
but is potentially optimized for performance.value - the value to checkvalue if the check passesIllegalArgumentException - if the check failspublic static int require(IntPredicate requirement, int value)
value after checking that it satisfies the provided requirement throwing
an IllegalArgumentException if the check fails.
This method is designed primarily for doing parameter validation in public methods and constructors, as demonstrated below:
public Foo(int bar) {
this.bar = require(nonNegative(), bar);
}
requirement - to impose on the provided valuevalue - the value to checkvalue if the check passesNullPointerException - if the provided requirement is null.IllegalArgumentException - if the check failspublic static <X extends RuntimeException> int require(IntPredicate requirement, int value, Function<String,X> exceptionMapper)
value after checking that it satisfies the provided requirement throwing
a custom exception if the check fails.
This method is designed primarily for doing parameter validation in public methods and constructors, as demonstrated below:
public Foo(int bar) {
this.bar = require(byteConvertible(), bar, ArithmeticException::new);
}
X - Exception typ to throw if the check failsrequirement - to impose on the provided valuevalue - the value to checkexceptionMapper - to apply should the check failvalue if the check passesNullPointerException - if the provided requirement is null or if the provided
exceptionMapper is null.RuntimeException - of the specified type of the provided exceptionMapperpublic static int require(IntBiPredicate requirement, int value, int otherValue)
value after checking that it and the provided otherValue satisfies the
provided requirement throwing an IllegalArgumentException if the check fails.
Checks that the provided value and provided otherValue satisfies the provided requirement.
This method is designed primarily for doing parameter validation in public methods and constructors, as demonstrated below:
public Foo(int bar) {
this.bar = require(betweenZeroAnd(), bar, 32);
}
requirement - to impose on the provided value and otherValuevalue - the value to checkotherValue - the other value to compare against the provided valuevalue if the check passesNullPointerException - if the provided requirement is null.IllegalArgumentException - if the check failspublic static <X extends RuntimeException> int require(IntBiPredicate requirement, int value, int otherValue, Function<String,X> exceptionMapper)
value after checking that it and the provided otherValue satisfies the
provided requirement throwing an IllegalArgumentException if the check fails.
Checks that the provided value and provided otherValue satisfies the provided requirement.
This method is designed primarily for doing parameter validation in public methods and constructors, as demonstrated below:
public Foo(int bar) {
this.bar = require(betweenZeroAnd(), bar, 16, 32, ArithmeticException::new);
}
X - Exception typ to throw if the check failsrequirement - to impose on the provided value and otherValuevalue - the value to checkotherValue - the other value to compare against the provided valueexceptionMapper - to apply should the check failvalue if the check passesNullPointerException - if the provided requirement is null.IllegalArgumentException - if the check failspublic static int require(IntTriPredicate requirement, int value, int otherFirstValue, int otherSecondValue)
value after checking that it and the provided otherValue
and the provided otherSecondValue satisfies the provided requirement
throwing an IllegalArgumentException if the check fails.
This method is designed primarily for doing parameter validation in public methods and constructors, as demonstrated below:
public Foo(int bar) {
this.bar = require(between(), bar, 16, 32);
}
requirement - to impose on the provided valuesvalue - the value to checkotherFirstValue - the other first value to compare against the provided valueotherSecondValue - the other first value to compare against the provided valuevalue if the check passesNullPointerException - if the provided requirement is null.IllegalArgumentException - if the check failspublic static <X extends RuntimeException> int require(IntTriPredicate requirement, int value, int otherFirstValue, int otherSecondValue, Function<String,X> exceptionMapper)
value after checking that it and the provided otherValue
and the provided otherSecondValue satisfies the provided requirement
throwing an IllegalArgumentException if the check fails.
This method is designed primarily for doing parameter validation in public methods and constructors, as demonstrated below:
public Foo(int bar) {
this.bar = require(between(), bar, 16, 32, ArithmeticException::new);
}
X - Exception typ to throw if the check failsrequirement - to impose on the provided valuesvalue - the value to checkotherFirstValue - the other first value to compare against the provided valueotherSecondValue - the other first value to compare against the provided valueexceptionMapper - to apply should the check failvalue if the check passesNullPointerException - if the provided requirement is null.IllegalArgumentException - if the check failspublic static boolean assertIfEnabled(IntPredicate requirement, int value)
value satisfies the provided requirement if
assertions is enabled (i.e. -ea) and AssertUtil.SKIP_ASSERTIONS is false.
This method is designed primarily for doing parameter validation in private methods and constructors, as demonstrated below:
private Foo(int bar) {
assertIfEnabled(nonNegative, bar);
this.bar = bar;
}
requirement - to impose on the provided valuevalue - the value to checktrueNullPointerException - if the provided requirement is null. There is no guarantee that this
exception is thrown. For example, if assertions are not enabled, then the exception
might not be thrown.AssertionError - if the check fails and assertions are enabled both via the -ea JVM command
line option and by setting AssertUtil.SKIP_ASSERTIONS to false.public static boolean assertIfEnabled(IntBiPredicate requirement, int value, int otherValue)
value and provided otherValue satisfies the provided requirement
if assertions is enabled (i.e. -ea) and AssertUtil.SKIP_ASSERTIONS is false.
This method is designed primarily for doing parameter validation in private methods and constructors, as demonstrated below:
private Foo(int bar) {
assertIfEnabled(betweenZeroAnd(), bar, 32);
this.bar = bar;
}
requirement - to impose on the provided value and otherValuevalue - the value to checkotherValue - the other value to compare against the provided valuetrueNullPointerException - if the provided requirement is null. There is no guarantee that this
exception is thrown. For example, if assertions are not enabled, then the exception
might not be thrown.AssertionError - if the check fails and assertions are enabled both via the -ea JVM command
line option and by setting AssertUtil.SKIP_ASSERTIONS to false.public static boolean assertIfEnabled(IntTriPredicate requirement, int value, int otherFirstValue, int otherSecondValue)
value, provided otherFirstValue and provided otherSecondValue
satisfies the provided requirement if assertions is enabled (i.e. -ea) and
AssertUtil.SKIP_ASSERTIONS is false.
This method is designed primarily for doing parameter validation in private methods and constructors, as demonstrated below:
public private(int bar) {
assertIfEnabled(between(), bar, 13, 42);
this.bar = bar;
}
requirement - to impose on the provided valuesvalue - the value to checkotherFirstValue - the other first value to compare against the provided valueotherSecondValue - the other first value to compare against the provided valuetrueNullPointerException - if the provided requirement is null. There is no guarantee that this
exception is thrown. For example, if assertions are not enabled, then the exception
might not be thrown.AssertionError - if the check fails and assertions are enabled both via the -ea JVM command
line option and by setting AssertUtil.SKIP_ASSERTIONS to false.public static String failDescription(IntPredicate requirement, int value)
value did not
satisfy the provided requirement.requirement - to imposed on the provided valuesvalue - the value to checkvalue did not
satisfy the provided requirementNullPointerException - if the provided requirement is null.public static String failDescription(IntBiPredicate requirement, int value, int otherValue)
value and
provided otherValue did not satisfy the provided requirement.requirement - to imposed on the provided valuesvalue - the value to checkotherValue - the other value to compare against the provided valuevalue and
provided otherValue did not satisfy the provided requirementNullPointerException - if the provided requirement is null.public static String failDescription(IntTriPredicate requirement, int value, int otherFirstValue, int otherSecondValue)
value,
provided otherFirstValue and provided otherFirstValue did not satisfy the
provided requirement.requirement - to imposed on the provided valuesvalue - the value to checkvalue and
provided otherValue did not satisfy the provided requirementNullPointerException - if the provided requirement is null.public static IntPredicate positive()
public static IntPredicate negative()
public static IntPredicate nonNegative()
This is equivalent to: negative().negate()
public static IntPredicate zero()
public static IntPredicate byteConvertible()
byte (i.e. value ∈ [-128, 127]").byte (i.e. value ∈ [-128, 127]")public static IntPredicate shortConvertible()
short (i.e. value ∈ [-32768, 32767]").short (i.e. value ∈ [-32768, 32767]")public static IntPredicate evenPowerOfTwo()
public static IntPredicate shortAligned()
public static IntPredicate intAligned()
public static IntPredicate longAligned()
public static IntBiPredicate equalTo()
public static IntBiPredicate greaterThan()
public static IntBiPredicate greaterOrEqual()
public static IntBiPredicate lessThan()
public static IntBiPredicate lessOrEqual()
public static IntBiPredicate betweenZeroAnd()
public static IntBiPredicate betweenZeroAndClosed()
public static IntBiPredicate powerOfTwo()
powerOfTwo().test(16, 4) is true because 2^4 is 16public static IntBiPredicate log2()
For example,
log2().test(4, 16) is true because log2(16) is 4
public static IntTriPredicate between()
public static IntTriPredicate betweenClosed()
public static IntTriPredicate betweenZeroAndReserving()
This predicate is useful when ensuring that a memory structure can be updated without exceeding its upper bounds. For example:
public static void putInt(byte[] bytes, int offset, int value) {
assert nonNull(bytes);
assert betweenZeroAndReserving.test(offset, bytes.length, Integer.BYTES);
...
Copyright © 2023. All rights reserved.