public final class Longs extends Object
long values.| Modifier and Type | Method and Description |
|---|---|
static LongPredicate |
nonNegative()
Returns a predicate that can test if a value is non-negative (i.e.
|
static <X extends RuntimeException> |
require(LongPredicate requirement,
long value,
Function<String,X> exceptionMapper)
Returns the provided
value after checking that it satisfies the provided requirement throwing
a custom exception if the check fails. |
static long |
requireNonNegative(long value)
Returns the provided
value after checking that it is non-negative throwing
an IllegalArgumentException if the check fails. |
static long |
requirePositive(long value)
Returns the provided
value after checking that it is positive throwing
an IllegalArgumentException if the check fails. |
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);
}
value - the value to checkvalue if the check passesIllegalArgumentException - If the check failspublic static long requirePositive(long value)
value after checking that it is positive 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 = requirePositive(bar);
}
value - the value to checkvalue if the check passesIllegalArgumentException - 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 LongPredicate nonNegative()
This is equivalent to: negative().negate()
Copyright © 2024. All rights reserved.