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.AbstractMap.SimpleImmutableEntry;
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.Iterator;
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.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.Timer;
import java.util.TimerTask;
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.annotation.SequentialOnly;
import com.landawn.abacus.util.NoCachingNoUpdating.DisposableArray;
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.ByteBiFunction;
import com.landawn.abacus.util.function.ByteBiPredicate;
import com.landawn.abacus.util.function.ByteConsumer;
import com.landawn.abacus.util.function.ByteFunction;
import com.landawn.abacus.util.function.BytePredicate;
import com.landawn.abacus.util.function.CharBiFunction;
import com.landawn.abacus.util.function.CharBiPredicate;
import com.landawn.abacus.util.function.CharConsumer;
import com.landawn.abacus.util.function.CharFunction;
import com.landawn.abacus.util.function.CharPredicate;
import com.landawn.abacus.util.function.Consumer;
import com.landawn.abacus.util.function.DoubleBiFunction;
import com.landawn.abacus.util.function.DoubleBiPredicate;
import com.landawn.abacus.util.function.DoubleConsumer;
import com.landawn.abacus.util.function.DoubleFunction;
import com.landawn.abacus.util.function.DoublePredicate;
import com.landawn.abacus.util.function.FloatBiFunction;
import com.landawn.abacus.util.function.FloatBiPredicate;
import com.landawn.abacus.util.function.FloatConsumer;
import com.landawn.abacus.util.function.FloatFunction;
import com.landawn.abacus.util.function.FloatPredicate;
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.IntBiFunction;
import com.landawn.abacus.util.function.IntBiPredicate;
import com.landawn.abacus.util.function.IntConsumer;
import com.landawn.abacus.util.function.IntFunction;
import com.landawn.abacus.util.function.IntPredicate;
import com.landawn.abacus.util.function.LongBiFunction;
import com.landawn.abacus.util.function.LongBiPredicate;
import com.landawn.abacus.util.function.LongConsumer;
import com.landawn.abacus.util.function.LongFunction;
import com.landawn.abacus.util.function.LongPredicate;
import com.landawn.abacus.util.function.LongSupplier;
import com.landawn.abacus.util.function.Predicate;
import com.landawn.abacus.util.function.QuadFunction;
import com.landawn.abacus.util.function.ShortBiFunction;
import com.landawn.abacus.util.function.ShortBiPredicate;
import com.landawn.abacus.util.function.ShortConsumer;
import com.landawn.abacus.util.function.ShortFunction;
import com.landawn.abacus.util.function.ShortPredicate;
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.ObjIteratorEx;
import com.landawn.abacus.util.stream.Stream;
/**
* Factory utility class for functional interfaces.
*
*
* Note: Don't save and reuse any Function/Predicat/Consumer/... created by calling the methods in this class.
* The method should be called every time.
*
*
*
*
*
* 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 abstract class Fn extends Comparators {
private static final Object NONE = new Object();
private static final Timer timer = new Timer();
@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(CharSequence t) {
return t == null ? 0 : t.length();
}
};
private static final Function LEN = new Function() {
@Override
public Integer apply(Object[] t) {
return t == null ? 0 : t.length;
}
};
@SuppressWarnings("rawtypes")
private static final Function SIZE = new Function() {
@Override
public Integer apply(Collection t) {
return t == null ? 0 : t.size();
}
};
@SuppressWarnings("rawtypes")
private static final Function SIZE_M = new Function() {
@Override
public Integer apply(Map t) {
return t == null ? 0 : t.size();
}
};
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 new SimpleImmutableEntry<>(t.getValue(), t.getKey());
}
};
private static final BiFunction> ENTRY = new BiFunction>() {
@Override
public Map.Entry apply(Object key, Object value) {
return new 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);
}
};
protected Fn() {
super();
// for extention.
}
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 memoize(final Supplier supplier) {
return new Supplier() {
private volatile boolean initialized = false;
private T instance = null;
@Override
public T get() {
if (initialized == false) {
synchronized (this) {
if (initialized == false) {
instance = supplier.get();
}
}
}
return instance;
}
};
}
public static Function memoize(final Function super T, ? extends R> func) {
return new Function() {
private volatile R resultForNull = (R) NONE;
private volatile Map resultMap = null;
@Override
public R apply(T t) {
R result = null;
if (t == null) {
result = resultForNull;
if (result == NONE) {
synchronized (this) {
if (resultForNull == NONE) {
resultForNull = func.apply(t);
}
result = resultForNull;
}
}
} else {
synchronized (this) {
if (resultMap == null) {
resultMap = new HashMap<>();
}
result = resultMap.get(t);
if (result == null && resultMap.containsKey(t) == false) {
result = func.apply(t);
resultMap.put(t, result);
}
}
}
return result;
}
};
}
/**
* Only for temporary use in sequential stream/single thread, not for parallel stream/multiple threads.
* The returned Collection will clean up before it's returned every time when {@code get} is called.
* Don't save the returned Collection object or use it to save objects.
*
* @param supplier
* @return
* @see {@code Stream.split/sliding};
*/
@Beta
@SequentialOnly
public static > Supplier extends C> reuse(final Supplier extends C> supplier) {
return new Supplier() {
private C c;
@Override
public C get() {
if (c == null) {
c = supplier.get();
} else if (c.size() > 0) {
c.clear();
}
return c;
}
};
}
/**
* Only for temporary use in sequential stream/single thread, not for parallel stream/multiple threads.
* The returned Collection will clean up before it's returned every time when {@code get} is called.
* Don't save the returned Collection object or use it to save objects.
*
* @param supplier
* @return
* @see {@code Stream.split/sliding};
*/
@Beta
@SequentialOnly
public static > IntFunction extends C> reuse(final IntFunction extends C> supplier) {
return new IntFunction() {
private C c;
@Override
public C apply(int size) {
if (c == null) {
c = supplier.apply(size);
} else if (c.size() > 0) {
c.clear();
}
return c;
}
};
}
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 closeAll(final Collection extends AutoCloseable> c) {
return new com.landawn.abacus.util.function.Runnable() {
private volatile boolean isClosed = false;
@Override
public void run() {
if (isClosed) {
return;
}
isClosed = true;
IOUtil.closeAll(c);
}
};
}
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 closeAllQuietly(final Collection extends AutoCloseable> c) {
return new com.landawn.abacus.util.function.Runnable() {
private volatile boolean isClosed = false;
@Override
public void run() {
if (isClosed) {
return;
}
isClosed = true;
IOUtil.closeAllQuietly(c);
}
};
}
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 sleep(final long millis) {
return new Consumer() {
@Override
public void accept(T t) {
N.sleep(millis);
}
};
}
public static Consumer sleepUninterruptibly(final long millis) {
return new Consumer() {
@Override
public void accept(T t) {
N.sleepUninterruptibly(millis);
}
};
}
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> keyMapper) {
N.checkArgNotNull(keyMapper);
return new Function>() {
@Override
public Keyed apply(T t) {
return Keyed.of(keyMapper.apply(t), t);
}
};
}
private static final Function, Object> VAL = new Function, Object>() {
@Override
public Object apply(Keyed, Object> t) {
return t.val();
}
};
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, T> val() {
return (Function) VAL;
}
@SuppressWarnings("rawtypes")
public static Function, V>, T> kk() {
return (Function) KK;
}
private static final Function> WRAP = new Function>() {
@Override
public Wrapper apply(Object t) {
return Wrapper.of(t);
}
};
@SuppressWarnings("rawtypes")
public static Function> wrap() {
return (Function) WRAP;
}
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);
}
};
}
private static final Function, Object> UNWRAP = new Function, Object>() {
@Override
public Object apply(Wrapper t) {
return t.value();
}
};
@SuppressWarnings("rawtypes")
public static Function, T> unwrap() {
return (Function) UNWRAP;
}
@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;
}
public static Function> entry(final K key) {
return new Function>() {
@Override
public Entry apply(T t) {
return new SimpleImmutableEntry<>(key, t);
}
};
}
public static Function> entry(final Function super T, K> keyMapper) {
N.checkArgNotNull(keyMapper);
return new Function>() {
@Override
public Entry apply(T t) {
return new SimpleImmutableEntry<>(keyMapper.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 (Function) LENGTH;
}
@SuppressWarnings("rawtypes")
public static Function len() {
return (Function) LEN;
}
@SuppressWarnings("rawtypes")
public static Function size() {
return (Function) SIZE;
}
@SuppressWarnings("rawtypes")
public static Function sizeM() {
return (Function) SIZE_M;
}
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 != null && c.size() > 0 && c.contains(value);
}
};
}
public static Predicate notIn(final Collection> c) {
N.checkArgNotNull(c);
return new Predicate