
com.github.davidmoten.geo.util.Preconditions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of geo Show documentation
Show all versions of geo Show documentation
Geohash encoding and decoding utilities including bounding box coverage.
package com.github.davidmoten.geo.util;
/**
* Guava like Preconditions.
*/
public final class Preconditions {
/**
* Constructor, private to prevent instantiation.
*/
private Preconditions() {
// do nothing
}
/**
* Ensures the truth of an expression involving one or more parameters to
* the calling method.
*
* @param expression
* a boolean expression
* @param errorMessage
* the exception message to use if the check fails; will be
* converted to a string using {@link String#valueOf(Object)}
* @throws IllegalArgumentException
* if {@code expression} is false
*/
public static void checkArgument(boolean expression, Object errorMessage) {
if (!expression) {
throw new IllegalArgumentException(String.valueOf(errorMessage));
}
}
/**
* Ensures that an object reference passed as a parameter to the calling
* method is not null.
*
* @param reference
* an object reference
* @param errorMessage
* the exception message to use if the check fails; will be
* converted to a string using {@link String#valueOf(Object)}
* @param
* type of object reference
* @return the non-null reference that was validated
* @throws NullPointerException
* if {@code reference} is null
*/
public static T checkNotNull(T reference, Object errorMessage) {
if (reference == null) {
throw new NullPointerException(String.valueOf(errorMessage));
}
return reference;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy