@Deprecated public final class Longs extends Object
long values.| Modifier and Type | Method and Description |
|---|---|
static boolean |
assertIfEnabled(LongBiPredicate requirement,
long value,
long otherValue)
Deprecated.
Asserts that the provided
value and provided otherValue satisfies the provided requirement
if assertions is enabled (i.e. |
static boolean |
assertIfEnabled(LongPredicate requirement,
long value)
Deprecated.
Asserts that the provided
value satisfies the provided requirement if
assertions is enabled (i.e. |
static boolean |
assertIfEnabled(LongTriPredicate requirement,
long value,
long otherFirstValue,
long otherSecondValue)
Deprecated.
Asserts that the provided
value, provided otherFirstValue and provided otherSecondValue
satisfies the provided requirement if assertions is enabled (i.e. |
static LongTriPredicate |
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 LongTriPredicate |
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 LongBiPredicate |
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 LongBiPredicate |
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 LongTriPredicate |
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 LongPredicate |
byteConvertible()
Deprecated.
Returns a predicate that can test if a value can fit in a
byte (i.e. |
static LongBiPredicate |
equalTo()
Deprecated.
Returns a predicate that can test if a value is equal to another value.
|
static LongPredicate |
evenPowerOfTwo()
Deprecated.
Returns a predicate that can test if a value is an even power of two
(i.e.
|
static String |
failDescription(LongBiPredicate requirement,
long value,
long 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(LongPredicate requirement,
long 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(LongTriPredicate requirement,
long value,
long otherFirstValue,
long 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 LongBiPredicate |
greaterOrEqual()
Deprecated.
Returns a predicate that can test if a value is greater or equal to another value.
|
static LongBiPredicate |
greaterThan()
Deprecated.
Returns a predicate that can test if a value is greater than to another value.
|
static LongPredicate |
intAligned()
Deprecated.
Returns a predicate that can test if a value is int aligned
(i.e.
|
static LongBiPredicate |
lessOrEqual()
Deprecated.
Returns a predicate that can test if a value is less or equal to another value.
|
static LongBiPredicate |
lessThan()
Deprecated.
Returns a predicate that can test if a value is less than to another value.
|
static LongBiPredicate |
log2()
Deprecated.
Returns a predicate that can test if a value is log2 of another value
(i.e.
|
static LongPredicate |
longAligned()
Deprecated.
Returns a predicate that can test if a value is long aligned
(i.e.
|
static LongPredicate |
negative()
Deprecated.
Returns a predicate that can test if a value is negative (i.e.
|
static LongPredicate |
nonNegative()
Deprecated.
Returns a predicate that can test if a value is non-negative (i.e.
|
static LongPredicate |
positive()
Deprecated.
Returns a predicate that can test if a value is positive (i.e.
|
static LongBiPredicate |
powerOfTwo()
Deprecated.
Returns a predicate that can test if a value is a power of two of another value
(i.e.
|
static void |
require(BooleanSupplier requirement,
String msg)
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(BooleanSupplier requirement,
String msg,
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 long |
require(LongBiPredicate requirement,
long value,
long 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(LongBiPredicate requirement,
long value,
long 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 long |
require(LongPredicate requirement,
long 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(LongPredicate requirement,
long 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 long |
require(LongTriPredicate requirement,
long value,
long otherFirstValue,
long 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(LongTriPredicate requirement,
long value,
long otherFirstValue,
long 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 long |
requireNonNegative(long value)
Deprecated.
Returns the provided
value after checking that it is non-negative throwing
an IllegalArgumentException if the check fails. |
static LongPredicate |
shortAligned()
Deprecated.
Returns a predicate that can test if a value is short aligned
(i.e.
|
static LongPredicate |
shortConvertible()
Deprecated.
Returns a predicate that can test if a value can fit in a
short (i.e. |
static LongPredicate |
zero()
Deprecated.
Returns a predicate that can test if a value is zero (i.e.
|
public static long requireNonNegative(long 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(long 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 long require(LongPredicate requirement, long 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(long 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 void require(BooleanSupplier requirement, String msg)
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(long bar) {
this.bar = require(() -> bar > 0, "bar should be positive");
}
requirement - to impose on the provided valueNullPointerException - If the provided requirement is null.IllegalArgumentException - If the check failspublic static <X extends RuntimeException> long require(LongPredicate requirement, long 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(long 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 <X extends RuntimeException> void require(BooleanSupplier requirement, String msg, 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(long bar) {
this.bar = require(byteConvertible(), bar, ArithmeticException::new);
}
X - Exception typ to throw if the check failsrequirement - to impose on the provided valueexceptionMapper - to apply should the check failNullPointerException - If the provided requirement is null or if the provided
exceptionMapper is null.RuntimeException - of the specified type of the provided exceptionMapperpublic static long require(LongBiPredicate requirement, long value, long 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(long 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> long require(LongBiPredicate requirement, long value, long 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(long 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 long require(LongTriPredicate requirement, long value, long otherFirstValue, long 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(long 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> long require(LongTriPredicate requirement, long value, long otherFirstValue, long 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(long 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(LongPredicate requirement, long 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(long 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(LongBiPredicate requirement, long value, long 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(long 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(LongTriPredicate requirement, long value, long otherFirstValue, long 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(long 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(LongPredicate requirement, long 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(LongBiPredicate requirement, long value, long 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(LongTriPredicate requirement, long value, long otherFirstValue, long 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 LongPredicate positive()
public static LongPredicate negative()
public static LongPredicate nonNegative()
This is equivalent to: negative().negate()
public static LongPredicate zero()
public static LongPredicate byteConvertible()
byte (i.e. value ∈ [-128, 127]").byte (i.e. value ∈ [-128, 127]")public static LongPredicate shortConvertible()
short (i.e. value ∈ [-32768, 32767]").short (i.e. value ∈ [-32768, 32767]")public static LongPredicate evenPowerOfTwo()
public static LongPredicate shortAligned()
public static LongPredicate intAligned()
public static LongPredicate longAligned()
public static LongBiPredicate equalTo()
public static LongBiPredicate greaterThan()
public static LongBiPredicate greaterOrEqual()
public static LongBiPredicate lessThan()
public static LongBiPredicate lessOrEqual()
public static LongBiPredicate betweenZeroAnd()
public static LongBiPredicate betweenZeroAndClosed()
public static LongBiPredicate powerOfTwo()
powerOfTwo().test(16, 4) is true because 2^4 is 16public static LongBiPredicate log2()
For example,
log2().test(4, 16) is true because log2(16) is 4
public static LongTriPredicate between()
public static LongTriPredicate betweenClosed()
public static LongTriPredicate betweenZeroAndReserving()
This predicate is useful when ensuring that a memory structure can be updated without exceeding its upper bounds. For example:
public static void putLong(byte[] bytes, long offset, long value) {
assert nonNull(bytes);
assert betweenZeroAndReserving.test(offset, bytes.length, Integer.BYTES);
...
Copyright © 2023. All rights reserved.