Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.landawn.abacus.util.Fn Maven / Gradle / Ivy
/*
* Copyright (c) 2017, Haiyang Li.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.landawn.abacus.util;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.NavigableSet;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
import com.landawn.abacus.annotation.Beta;
import com.landawn.abacus.util.Tuple.Tuple1;
import com.landawn.abacus.util.Tuple.Tuple2;
import com.landawn.abacus.util.Tuple.Tuple3;
import com.landawn.abacus.util.Tuple.Tuple4;
import com.landawn.abacus.util.function.BiConsumer;
import com.landawn.abacus.util.function.BiFunction;
import com.landawn.abacus.util.function.BiPredicate;
import com.landawn.abacus.util.function.BinaryOperator;
import com.landawn.abacus.util.function.BooleanSupplier;
import com.landawn.abacus.util.function.Consumer;
import com.landawn.abacus.util.function.DoubleBiPredicate;
import com.landawn.abacus.util.function.DoublePredicate;
import com.landawn.abacus.util.function.Function;
import com.landawn.abacus.util.function.IndexedBiConsumer;
import com.landawn.abacus.util.function.IndexedBiFunction;
import com.landawn.abacus.util.function.IndexedBiPredicate;
import com.landawn.abacus.util.function.IndexedConsumer;
import com.landawn.abacus.util.function.IndexedFunction;
import com.landawn.abacus.util.function.IndexedPredicate;
import com.landawn.abacus.util.function.IntBiPredicate;
import com.landawn.abacus.util.function.IntFunction;
import com.landawn.abacus.util.function.IntPredicate;
import com.landawn.abacus.util.function.LongBiPredicate;
import com.landawn.abacus.util.function.LongPredicate;
import com.landawn.abacus.util.function.Predicate;
import com.landawn.abacus.util.function.QuadFunction;
import com.landawn.abacus.util.function.Supplier;
import com.landawn.abacus.util.function.ToByteFunction;
import com.landawn.abacus.util.function.ToCharFunction;
import com.landawn.abacus.util.function.ToDoubleFunction;
import com.landawn.abacus.util.function.ToFloatFunction;
import com.landawn.abacus.util.function.ToIntFunction;
import com.landawn.abacus.util.function.ToLongFunction;
import com.landawn.abacus.util.function.ToShortFunction;
import com.landawn.abacus.util.function.TriConsumer;
import com.landawn.abacus.util.function.TriFunction;
import com.landawn.abacus.util.function.TriPredicate;
import com.landawn.abacus.util.function.UnaryOperator;
import com.landawn.abacus.util.stream.Collector;
import com.landawn.abacus.util.stream.Collectors;
import com.landawn.abacus.util.stream.Stream;
/**
* Factory utility class for functional interfaces.
*
*
*
*
* Map map = N.asMap("a", 1, "b", 2, "c", 3);
* // Instead of
* Stream.of(map).filter(e -> e.getKey().equals("a") || e.getKey().equals("b")).toMap(e -> e.getKey(), e -> e.getValue());
* // Using Fn
* Stream.of(map).filter(Fn.testByKey(k -> k.equals("a") || k.equals("b"))).collect(Collectors.toMap());
*
*
*
*
*
* @author haiyang li
*
*/
public final class Fn extends Comparators {
@SuppressWarnings("rawtypes")
public static final IntFunction> FACTORY_OF_MAP = (IntFunction) Factory.MAP_FACTORY;
@SuppressWarnings("rawtypes")
public static final IntFunction> FACTORY_OF_LINKED_HASH_MAP = (IntFunction) Factory.LINKED_HASH_MAP_FACTORY;
@SuppressWarnings("rawtypes")
public static final Supplier> SUPPLIER_OF_MAP = (Supplier) Suppliers.MAP;
@SuppressWarnings("rawtypes")
public static final Supplier> SUPPLIER_OF_LINKED_HASH_MAP = (Supplier) Suppliers.LINKED_HASH_MAP;
private static final com.landawn.abacus.util.function.Runnable EMPTY_ACTION = new com.landawn.abacus.util.function.Runnable() {
@Override
public void run() {
}
};
@SuppressWarnings("rawtypes")
private static final Consumer DO_NOTHING = new Consumer() {
@Override
public void accept(Object value) {
// do nothing.
}
};
private static final Consumer CLOSE = new Consumer() {
@Override
public void accept(AutoCloseable value) {
IOUtil.close(value);
}
};
private static final Consumer CLOSE_QUIETLY = new Consumer() {
@Override
public void accept(AutoCloseable value) {
IOUtil.closeQuietly(value);
}
};
@SuppressWarnings("rawtypes")
private static final BiConsumer PRINTLN_EQUAL = new BiConsumer() {
@Override
public void accept(Object key, Object value) {
N.println(StringUtil.concat(N.toString(key), "=", N.toString(value)));
}
};
@SuppressWarnings("rawtypes")
private static final BiConsumer PRINTLN_HYPHEN = new BiConsumer() {
@Override
public void accept(Object key, Object value) {
N.println(StringUtil.concat(N.toString(key), "-", N.toString(value)));
}
};
@SuppressWarnings("rawtypes")
private static final BiConsumer PRINTLN_UNDERSCORE = new BiConsumer() {
@Override
public void accept(Object key, Object value) {
N.println(StringUtil.concat(N.toString(key), "_", N.toString(value)));
}
};
@SuppressWarnings("rawtypes")
private static final BiConsumer PRINTLN_COLON = new BiConsumer() {
@Override
public void accept(Object key, Object value) {
N.println(StringUtil.concat(N.toString(key), ":", N.toString(value)));
}
};
@SuppressWarnings("rawtypes")
private static final BiConsumer PRINTLN_COLON_SPACE = new BiConsumer() {
@Override
public void accept(Object key, Object value) {
N.println(StringUtil.concat(N.toString(key), ": ", N.toString(value)));
}
};
@SuppressWarnings("rawtypes")
private static final BiConsumer PRINTLN_COMMA = new BiConsumer() {
@Override
public void accept(Object key, Object value) {
N.println(StringUtil.concat(N.toString(key), ",", N.toString(value)));
}
};
@SuppressWarnings("rawtypes")
private static final BiConsumer PRINTLN_COMMA_SPACE = new BiConsumer() {
@Override
public void accept(Object key, Object value) {
N.println(StringUtil.concat(N.toString(key), ", ", N.toString(value)));
}
};
@SuppressWarnings("rawtypes")
private static final BiConsumer PRINTLN_EMPTY = new BiConsumer() {
@Override
public void accept(Object key, Object value) {
N.println(StringUtil.concat(N.toString(key), N.toString(value)));
}
};
@SuppressWarnings("rawtypes")
private static final Consumer PRINTLN = new Consumer() {
@Override
public void accept(Object value) {
N.println(value);
}
};
@SuppressWarnings("rawtypes")
private static final Function TO_STRING = new Function() {
@Override
public Object apply(Object t) {
return N.toString(t);
}
};
private static final Function TO_CAMEL_CASE = new Function() {
@Override
public String apply(String t) {
return StringUtil.toCamelCase(t);
}
};
private static final Function TO_LOWER_CASE = new Function() {
@Override
public String apply(String t) {
return StringUtil.toLowerCase(t);
}
};
private static final Function TO_LOWER_CASE_WITH_UNDERSCORE = new Function() {
@Override
public String apply(String t) {
return StringUtil.toLowerCaseWithUnderscore(t);
}
};
private static final Function TO_UPPER_CASE = new Function() {
@Override
public String apply(String t) {
return StringUtil.toUpperCase(t);
}
};
private static final Function TO_UPPER_CASE_WITH_UNDERSCORE = new Function() {
@Override
public String apply(String t) {
return StringUtil.toUpperCaseWithUnderscore(t);
}
};
@SuppressWarnings("rawtypes")
private static final BiFunction COMPARE = new BiFunction() {
@Override
public Integer apply(Comparable a, Comparable b) {
return N.compare(a, b);
}
};
@SuppressWarnings("rawtypes")
private static final Function IDENTITY = new Function() {
@Override
public Object apply(Object t) {
return t;
}
};
private static final Function TRIM = new Function() {
@Override
public String apply(String t) {
return t == null ? null : t.trim();
}
};
private static final Function TRIM_TO_EMPTY = new Function() {
@Override
public String apply(String t) {
return t == null ? "" : t.trim();
}
};
private static final Function TRIM_TO_NULL = new Function() {
@Override
public String apply(String t) {
if (t == null || (t = t.trim()).length() == 0) {
return null;
}
return t;
}
};
private static final Function NULL_TO_EMPTY = new Function() {
@Override
public String apply(String t) {
return t == null ? N.EMPTY_STRING : t;
}
};
@SuppressWarnings("rawtypes")
private static final Function NULL_TO_EMPTY_L = new Function() {
@Override
public List apply(List t) {
return t == null ? N.emptyList() : t;
}
};
@SuppressWarnings("rawtypes")
private static final Function NULL_TO_EMPTY_S = new Function() {
@Override
public Set apply(Set t) {
return t == null ? N.emptySet() : t;
}
};
@SuppressWarnings("rawtypes")
private static final Function NULL_TO_EMPTY_M = new Function() {
@Override
public Map apply(Map t) {
return t == null ? N.emptyMap() : t;
}
};
private static final Function LENGTH = new Function() {
@Override
public Integer apply(String t) {
return N.len(t);
}
};
@SuppressWarnings("rawtypes")
private static final Function SIZE = new Function() {
@Override
public Integer apply(Collection t) {
return N.len(t);
}
};
private static final Function, Object> KEY = new Function, Object>() {
@Override
public Object apply(Map.Entry t) {
return t.getKey();
}
};
private static final Function, Object> VALUE = new Function, Object>() {
@Override
public Object apply(Map.Entry t) {
return t.getValue();
}
};
private static final Function, Map.Entry> INVERSE = new Function, Map.Entry>() {
@Override
public Map.Entry apply(Map.Entry t) {
return Pair.of(t.getValue(), t.getKey());
}
};
// private static final BiFunction> ENTRY = new BiFunction>() {
// @Override
// public Map.Entry apply(Object key, Object value) {
// return new AbstractMap.SimpleImmutableEntry<>(key, value);
// }
// };
private static final BiFunction> PAIR = new BiFunction>() {
@Override
public Pair apply(Object key, Object value) {
return Pair.of(key, value);
}
};
private static final TriFunction> TRIPLE = new TriFunction>() {
@Override
public Triple apply(Object a, Object b, Object c) {
return Triple.of(a, b, c);
}
};
private static final Function> TUPLE_1 = new Function>() {
@Override
public Tuple1 apply(Object t) {
return Tuple.of(t);
}
};
private static final BiFunction> TUPLE_2 = new BiFunction>() {
@Override
public Tuple2 apply(Object t, Object u) {
return Tuple.of(t, u);
}
};
private static final TriFunction> TUPLE_3 = new TriFunction>() {
@Override
public Tuple3 apply(Object a, Object b, Object c) {
return Tuple.of(a, b, c);
}
};
private static final QuadFunction> TUPLE_4 = new QuadFunction>() {
@Override
public Tuple4 apply(Object a, Object b, Object c, Object d) {
return Tuple.of(a, b, c, d);
}
};
@SuppressWarnings("rawtypes")
private static final Predicate ALWAYS_TRUE = new Predicate() {
@Override
public boolean test(Object value) {
return true;
}
};
@SuppressWarnings("rawtypes")
private static final Predicate ALWAYS_FALSE = new Predicate() {
@Override
public boolean test(Object value) {
return false;
}
};
@SuppressWarnings("rawtypes")
private static final Predicate IS_NULL = new Predicate() {
@Override
public boolean test(Object value) {
return value == null;
}
};
private static final Predicate IS_NULL_OR_EMPTY = new Predicate() {
@Override
public boolean test(CharSequence value) {
return value == null || value.length() == 0;
}
};
private static final Predicate IS_NULL_OR_EMPTY_OR_BLANK = new Predicate() {
@Override
public boolean test(CharSequence value) {
return N.isNullOrEmptyOrBlank(value);
}
};
@SuppressWarnings("rawtypes")
private static final Predicate NOT_NULL = new Predicate() {
@Override
public boolean test(Object value) {
return value != null;
}
};
private static final Predicate NOT_NULL_OR_EMPTY = new Predicate() {
@Override
public boolean test(CharSequence value) {
return value != null && value.length() > 0;
}
};
private static final Predicate NOT_NULL_OR_EMPTY_OR_BLANK = new Predicate() {
@Override
public boolean test(CharSequence value) {
return N.notNullOrEmptyOrBlank(value);
}
};
private static final ToIntFunction NUM_TO_INT_FUNC = new ToIntFunction() {
@Override
public int applyAsInt(Number value) {
return value == null ? 0 : value.intValue();
}
};
private static final ToLongFunction NUM_TO_LONG_FUNC = new ToLongFunction() {
@Override
public long applyAsLong(Number value) {
return value == null ? 0 : value.longValue();
}
};
private static final ToDoubleFunction NUM_TO_DOUBLE_FUNC = new ToDoubleFunction() {
@Override
public double applyAsDouble(Number value) {
return value == null ? 0d : value.doubleValue();
}
};
private static final Object NULL = new Object();
private Fn() {
super();
// Singleton.
}
public static T get(final Supplier supplier) {
return supplier.get();
}
/**
* Returns a {@code Supplier} which returns a single instance created by calling the specified {@code supplier.get()}.
*
* @param supplier
* @return
*/
public static Supplier single(final Supplier supplier) {
return new Supplier() {
private T instance = (T) NULL;
@Override
public T get() {
synchronized (this) {
if (instance == NULL) {
instance = supplier.get();
}
return instance;
}
}
};
}
public static com.landawn.abacus.util.function.Runnable close(final AutoCloseable closeable) {
return new com.landawn.abacus.util.function.Runnable() {
private volatile boolean isClosed = false;
@Override
public void run() {
if (isClosed) {
return;
}
isClosed = true;
IOUtil.close(closeable);
}
};
}
@SafeVarargs
public static com.landawn.abacus.util.function.Runnable closeAll(final AutoCloseable... a) {
return new com.landawn.abacus.util.function.Runnable() {
private volatile boolean isClosed = false;
@Override
public void run() {
if (isClosed) {
return;
}
isClosed = true;
IOUtil.closeAll(a);
}
};
}
public static com.landawn.abacus.util.function.Runnable closeQuietly(final AutoCloseable closeable) {
return new com.landawn.abacus.util.function.Runnable() {
private volatile boolean isClosed = false;
@Override
public void run() {
if (isClosed) {
return;
}
isClosed = true;
IOUtil.closeQuietly(closeable);
}
};
}
@SafeVarargs
public static com.landawn.abacus.util.function.Runnable closeAllQuietly(final AutoCloseable... a) {
return new com.landawn.abacus.util.function.Runnable() {
private volatile boolean isClosed = false;
@Override
public void run() {
if (isClosed) {
return;
}
isClosed = true;
IOUtil.closeAllQuietly(a);
}
};
}
public static com.landawn.abacus.util.function.Runnable emptyAction() {
return EMPTY_ACTION;
}
public static Consumer doNothing() {
return DO_NOTHING;
}
public static Consumer close() {
return (Consumer) CLOSE;
}
public static Consumer closeQuietly() {
return (Consumer) CLOSE_QUIETLY;
}
public static Consumer println() {
return PRINTLN;
}
public static BiConsumer println(final String separator) {
N.checkArgNotNull(separator);
switch (separator) {
case "=":
return PRINTLN_EQUAL;
case ":":
return PRINTLN_COLON;
case ": ":
return PRINTLN_COLON_SPACE;
case "-":
return PRINTLN_HYPHEN;
case "_":
return PRINTLN_UNDERSCORE;
case ",":
return PRINTLN_COMMA;
case ", ":
return PRINTLN_COMMA_SPACE;
case "":
return PRINTLN_EMPTY;
default:
return new BiConsumer() {
@Override
public void accept(T t, U u) {
N.println(t + separator + u);
}
};
}
}
public static Function toStr() {
return TO_STRING;
}
public static Function toCamelCase() {
return TO_CAMEL_CASE;
}
public static Function toLowerCase() {
return TO_LOWER_CASE;
}
public static Function toLowerCaseWithUnderscore() {
return TO_LOWER_CASE_WITH_UNDERSCORE;
}
public static Function toUpperCase() {
return TO_UPPER_CASE;
}
public static Function toUpperCaseWithUnderscore() {
return TO_UPPER_CASE_WITH_UNDERSCORE;
}
public static Function identity() {
return IDENTITY;
}
public static Function> keyed(final Function super T, K> keyExtractor) {
N.checkArgNotNull(keyExtractor);
return new Function>() {
@Override
public Keyed apply(T t) {
return Keyed.of(keyExtractor.apply(t), t);
}
};
}
private static final Function, Object>, Object> KK = new Function, Object>, Object>() {
@Override
public Object apply(Map.Entry, Object> t) {
return t.getKey().val();
}
};
@SuppressWarnings("rawtypes")
public static Function, Long>, T> kk() {
return (Function) KK;
}
public static Function> wrap() {
return new Function>() {
@Override
public Wrapper apply(T t) {
return Wrapper.of(t);
}
};
}
public static Function> wrap(final ToIntFunction super T> hashFunction, final BiPredicate super T, ? super T> equalsFunction) {
N.checkArgNotNull(hashFunction);
N.checkArgNotNull(equalsFunction);
return new Function>() {
@Override
public Wrapper apply(T t) {
return Wrapper.of(t, hashFunction, equalsFunction);
}
};
}
@SuppressWarnings("rawtypes")
public static Function, K> key() {
return (Function) KEY;
}
@SuppressWarnings("rawtypes")
public static Function, V> value() {
return (Function) VALUE;
}
@SuppressWarnings("rawtypes")
public static Function, Entry> inverse() {
return (Function) INVERSE;
}
@SuppressWarnings("rawtypes")
public static BiFunction> entry() {
// return (BiFunction) ENTRY;
return (BiFunction) PAIR;
}
public static Function> entry(final K key) {
return new Function>() {
@Override
public Entry apply(T t) {
return Pair.of(key, t);
}
};
}
public static Function> entry(final Function super T, K> keyExtractor) {
N.checkArgNotNull(keyExtractor);
return new Function>() {
@Override
public Entry apply(T t) {
return Pair.of(keyExtractor.apply(t), t);
}
};
}
@SuppressWarnings("rawtypes")
public static BiFunction> pair() {
return (BiFunction) PAIR;
}
@SuppressWarnings("rawtypes")
public static TriFunction> triple() {
return (TriFunction) TRIPLE;
}
@SuppressWarnings("rawtypes")
public static Function> tuple1() {
return (Function) TUPLE_1;
}
@SuppressWarnings("rawtypes")
public static BiFunction> tuple2() {
return (BiFunction) TUPLE_2;
}
@SuppressWarnings("rawtypes")
public static TriFunction > tuple3() {
return (TriFunction) TUPLE_3;
}
@SuppressWarnings({ "rawtypes" })
public static QuadFunction > tuple4() {
return (QuadFunction) TUPLE_4;
}
public static Function trim() {
return TRIM;
}
public static Function trimToEmpty() {
return TRIM_TO_EMPTY;
}
public static Function trimToNull() {
return TRIM_TO_NULL;
}
public static Function nullToEmpty() {
return NULL_TO_EMPTY;
}
@SuppressWarnings("rawtypes")
public static Function, List> nullToEmptyL() {
return (Function) NULL_TO_EMPTY_L;
}
@SuppressWarnings("rawtypes")
public static Function, Set> nullToEmptyS() {
return (Function) NULL_TO_EMPTY_S;
}
@SuppressWarnings("rawtypes")
public static Function, Map> nullToEmptyM() {
return (Function) NULL_TO_EMPTY_M;
}
public static Function length() {
return LENGTH;
}
@SuppressWarnings("rawtypes")
public static Function size() {
return (Function) SIZE;
}
public static Function cast(final Class clazz) {
N.checkArgNotNull(clazz);
return new Function() {
@Override
public U apply(T t) {
return (U) t;
}
};
}
public static Predicate alwaysTrue() {
return ALWAYS_TRUE;
}
public static Predicate alwaysFalse() {
return ALWAYS_FALSE;
}
public static Predicate isNull() {
return IS_NULL;
}
public static Predicate isNullOrEmpty() {
return (Predicate) IS_NULL_OR_EMPTY;
}
public static Predicate isNullOrEmptyOrBlank() {
return (Predicate) IS_NULL_OR_EMPTY_OR_BLANK;
}
public static Predicate notNull() {
return NOT_NULL;
}
public static Predicate notNullOrEmpty() {
return (Predicate) NOT_NULL_OR_EMPTY;
}
public static Predicate notNullOrEmptyOrBlank() {
return (Predicate) NOT_NULL_OR_EMPTY_OR_BLANK;
}
public static Predicate equal(final Object target) {
return new Predicate() {
@Override
public boolean test(T value) {
return N.equals(value, target);
}
};
}
public static Predicate notEqual(final Object target) {
return new Predicate() {
@Override
public boolean test(T value) {
return !N.equals(value, target);
}
};
}
@SuppressWarnings("rawtypes")
public static Predicate greaterThan(final T target) {
return new Predicate() {
@Override
public boolean test(T value) {
return N.compare(value, target) > 0;
}
};
}
@SuppressWarnings("rawtypes")
public static Predicate greaterEqual(final T target) {
return new Predicate() {
@Override
public boolean test(T value) {
return N.compare(value, target) >= 0;
}
};
}
@SuppressWarnings("rawtypes")
public static Predicate lessThan(final T target) {
return new Predicate() {
@Override
public boolean test(T value) {
return N.compare(value, target) < 0;
}
};
}
@SuppressWarnings("rawtypes")
public static Predicate lessEqual(final T target) {
return new Predicate() {
@Override
public boolean test(T value) {
return N.compare(value, target) <= 0;
}
};
}
/**
* Checks if the value/element: {@code minValue < e < maxValue}.
*
* @param minValue
* @param maxValue
* @return
*/
@SuppressWarnings("rawtypes")
public static Predicate between(final T minValue, final T maxValue) {
return new Predicate() {
@Override
public boolean test(T value) {
return N.compare(value, minValue) > 0 && N.compare(value, maxValue) < 0;
}
};
}
public static Predicate in(final Collection> c) {
N.checkArgNotNull(c);
return new Predicate() {
@Override
public boolean test(T value) {
return c.contains(value);
}
};
}
public static Predicate notIn(final Collection> c) {
N.checkArgNotNull(c);
return new Predicate() {
@Override
public boolean test(T value) {
return !c.contains(value);
}
};
}
public static Predicate instanceOf(final Class> clazz) {
N.checkArgNotNull(clazz);
return new Predicate() {
@Override
public boolean test(T value) {
return clazz.isInstance(value);
}
};
}
@SuppressWarnings("rawtypes")
public static Predicate subtypeOf(final Class> clazz) {
N.checkArgNotNull(clazz);
return new Predicate() {
@Override
public boolean test(Class value) {
return clazz.isAssignableFrom(value);
}
};
}
public static Predicate startsWith(final String prefix) {
N.checkArgNotNull(prefix);
return new Predicate() {
@Override
public boolean test(String value) {
return value.startsWith(prefix);
}
};
}
public static Predicate endsWith(final String suffix) {
N.checkArgNotNull(suffix);
return new Predicate() {
@Override
public boolean test(String value) {
return value.endsWith(suffix);
}
};
}
public static Predicate contains(final String str) {
N.checkArgNotNull(str);
return new Predicate() {
@Override
public boolean test(String value) {
return value.contains(str);
}
};
}
public static Predicate matches(final Pattern pattern) {
N.checkArgNotNull(pattern);
return new Predicate() {
@Override
public boolean test(CharSequence value) {
return pattern.matcher(value).find();
}
};
}
public static BiPredicate equal() {
return BiPredicates.EQUAL;
}
public static BiPredicate notEqual() {
return BiPredicates.NOT_EQUAL;
}
@SuppressWarnings("rawtypes")
public static BiPredicate greaterThan() {
return (BiPredicate) BiPredicates.GREATER_THAN;
}
@SuppressWarnings("rawtypes")
public static BiPredicate greaterEqual() {
return (BiPredicate) BiPredicates.GREATER_EQUAL;
}
@SuppressWarnings("rawtypes")
public static BiPredicate lessThan() {
return (BiPredicate) BiPredicates.LESS_THAN;
}
@SuppressWarnings("rawtypes")
public static BiPredicate