com.bluecatcode.common.base.Predicates Maven / Gradle / Ivy
package com.bluecatcode.common.base;
import com.bluecatcode.common.base.predicates.IsInstancePredicate;
import com.google.common.annotations.Beta;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.Dictionary;
import java.util.Map;
import static java.lang.String.format;
/**
* Additional Predicates as an extension to {@link com.google.common.base.Predicates}
*
* In performance critical contexts it is probably better to use hand-written checks, but measure first!.
*
*
* - nor - A 'not or' predicate
* - isEmpty* - Performs emptiness and nullness check for:
* String, CharSequence, Optional, Collection, Iterable, Map, Object[], prim[]
* - isValidURI - Performs URI check against RFC 2396 specification
* - isValidEmail - Performs email address check against RFC 822 specification
* - isInstance - Performs a runtime check if the reference is an instance of any of provided class(es)
*
*
* @see com.google.common.base.Predicates
*/
public final class Predicates {
private static Predicate isEmpty() {
return IsEmpty::isEmpty;
}
public static Predicate isEmptyString() {
return String::isEmpty;
}
public static Predicate isEmptyCharSequence() {
return chs -> chs.length() == 0;
}
public static Predicate isEmptyOptional() {
return o -> !o.isPresent();
}
public static Predicate isEmptyIterable() {
return i -> !i.iterator().hasNext();
}
public static Predicate isEmptyCollection() {
return Collection::isEmpty;
}
public static Predicate
© 2015 - 2024 Weber Informatics LLC | Privacy Policy