public class CommonUtils
extends java.lang.Object
| Constructor and Description |
|---|
CommonUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T> java.util.List<T> |
concatLists(java.util.List<T> first,
java.util.List<T> second)
Returns a new list of the concatenation of the two provided lists.
|
static <T> java.lang.Iterable<T> |
emptyIfNull(java.lang.Iterable<T> iterable)
Returns an empty iterable if a null is passed.
|
static <K,V> java.util.Map<K,V> |
entriesOnlyOnLeftMap(java.util.Map<K,V> left,
java.util.Map<K,V> right)
Returns a map with entries from the left map which keys aren't in the right map.
|
static <T> java.util.Collection<T> |
filterCollection(java.util.Collection<T> unfiltered,
java.util.function.Predicate<T> predicate)
Returns a collection containing only the elements of the original collection that satisfy the predicate.
|
static <K,V> java.util.Map<K,V> |
filterMapKeys(java.util.Map<K,V> map,
java.util.function.Predicate<K> predicate)
Returns a map containing only the keys of the original map that satisfy the predicate.
|
static <K,V> java.util.Map<K,V> |
filterMapValues(java.util.Map<K,V> map,
java.util.function.Predicate<V> predicate)
Returns a map containing only the values of the original map that satisfy the predicate.
|
static <T> T |
getFirstSatisfying(java.util.Collection<T> collection,
java.util.function.Predicate<T> predicate,
T defaultValue)
Returns the first element in the provided collection that satisfies the predicate.
|
static <T> T |
getLast(java.util.Collection<T> collection)
Returns the last element in the collection.
|
static <T> T |
getOnlyElement(java.util.Collection<T> collection)
Returns the only element in the provided collection.
|
static void |
handleJavaTmpdirProperty()
Handle 'java.io.tmpdir' system property.
|
static <T> boolean |
isAnySatisfying(java.util.Collection<T> collection,
java.util.function.Predicate<T> predicate)
Returns true if any of the elements in the provided collection satisfies the predicate.
|
static <E> java.util.HashSet<E> |
newHashSet(E... elements)
Returns a new HashSet of the provided elements.
|
static java.lang.String |
readByCharset(java.io.File from,
java.nio.charset.Charset charset)
Read a string from a file using the provided Charset.
|
static <F,T> java.util.ArrayList<T> |
transformList(java.lang.Iterable<F> iterable,
java.util.function.Function<F,T> function)
Outputs a new list after applying the provided function on every element in the provided list.
|
static void |
writeByCharset(java.lang.String from,
java.io.File to,
java.nio.charset.Charset charset)
Write a string to a file using the provided Charset.
|
public static <K,V> java.util.Map<K,V> filterMapValues(java.util.Map<K,V> map,
java.util.function.Predicate<V> predicate)
public static <K,V> java.util.Map<K,V> filterMapKeys(java.util.Map<K,V> map,
java.util.function.Predicate<K> predicate)
public static <K,V> java.util.Map<K,V> entriesOnlyOnLeftMap(java.util.Map<K,V> left,
java.util.Map<K,V> right)
public static <T> java.util.List<T> concatLists(java.util.List<T> first,
java.util.List<T> second)
public static <F,T> java.util.ArrayList<T> transformList(java.lang.Iterable<F> iterable,
java.util.function.Function<F,T> function)
public static <T> T getFirstSatisfying(java.util.Collection<T> collection,
java.util.function.Predicate<T> predicate,
T defaultValue)
public static <T> boolean isAnySatisfying(java.util.Collection<T> collection,
java.util.function.Predicate<T> predicate)
public static <T> java.util.Collection<T> filterCollection(java.util.Collection<T> unfiltered,
java.util.function.Predicate<T> predicate)
public static <T> T getLast(java.util.Collection<T> collection)
public static <T> T getOnlyElement(java.util.Collection<T> collection)
public static void writeByCharset(java.lang.String from,
java.io.File to,
java.nio.charset.Charset charset)
throws java.lang.RuntimeException
java.lang.RuntimeExceptionpublic static java.lang.String readByCharset(java.io.File from,
java.nio.charset.Charset charset)
throws java.io.IOException
java.io.IOExceptionpublic static <E> java.util.HashSet<E> newHashSet(E... elements)
public static <T> java.lang.Iterable<T> emptyIfNull(java.lang.Iterable<T> iterable)
public static void handleJavaTmpdirProperty()
java.lang.RuntimeException - if 'java.io.tmpdir' property is missing in Windows or the path is not accessible.