Package it.bancaditalia.oss.vtl.util
Class Utils
- java.lang.Object
-
- it.bancaditalia.oss.vtl.util.Utils
-
public final class Utils extends Object
This class contains various utility SerFunctions used by the VTL Engine implementation. Most of the SerFunctions are wrappers of the standard packages in Java 8.- Author:
- Valentino Pinna
- See Also:
java.util.function
,java.util.stream
,java.util
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
ORDERED
static boolean
SEQUENTIAL
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T,R>
SerPredicate<T>afterMapping(SerFunction<? super T,? extends R> mapper, SerPredicate<? super R> condition)
<T> SerConsumer<T>
asConsumer(SerFunction<? super T,?> function)
static <A,B,C>
SerBiFunction<A,B,C>asFun(SerBiFunction<? super A,? super B,? extends C> biFunction)
static <A,B>
SerFunction<A,B>asFun(SerFunction<? super A,? extends B> function)
static <K,V>
SerConsumer<Map.Entry<K,V>>atKey(SerConsumer<? super K> valueMapper)
static <K,V>
SerConsumer<Map.Entry<K,V>>atValue(SerConsumer<? super V> valueMapper)
static int[]
catArrays(int[] a, int[] b)
static <A1 extends Serializable,A2 extends Serializable,B extends Serializable,C extends Serializable>
SerFunction<Triple<A1,B,C>,Triple<A2,B,C>>changingFirst(SerFunction<? super A1,? extends A2> mapper)
static <T,C extends Collection<T>>
Ccoalesce(C value, C defaultValue)
static <T> T
coalesce(T value, T defaultValue)
static <T> T
coalesceSwapped(T defaultValue, T value)
static <A,B>
SerFunction<A,SerConsumer<B>>curry(SerBiConsumer<A,B> biconsumer)
static <A,B,C>
SerFunction<A,SerFunction<B,C>>curry(SerBiFunction<A,B,C> biFunction)
static <A,B,C>
SerFunction<B,SerFunction<A,C>>curryRev(SerBiFunction<A,B,C> biFunction)
static <U,V>
SerCollector<Map.Entry<? extends U,? extends V>,?,ConcurrentMap<U,V>>entriesToMap()
static <U,V>
SerCollector<Map.Entry<U,V>,?,ConcurrentMap<U,V>>entriesToMap(SerBinaryOperator<V> combiner)
static <U,V,M extends ConcurrentMap<U,V>>
SerCollector<Map.Entry<U,V>,?,M>entriesToMap(SerSupplier<M> mapSupplier)
static <K,V>
SerPredicate<Map.Entry<K,V>>entryByKey(SerPredicate<K> keyPredicate)
static <K,V>
SerPredicate<? super Map.Entry<K,V>>entryByKeyValue(SerBiPredicate<? super K,? super V> entryPredicate)
static <K,V>
SerPredicate<Map.Entry<K,V>>entryByValue(SerPredicate<V> valuePredicate)
static <T,U,A,R>
SerCollector<T,A,R>flatMapping(SerFunction<? super T,? extends Stream<? extends U>> mapper, SerCollector<? super U,A,R> downstream)
static <T,R>
Rfold(R accumulator, Iterable<T> iterable, SerBiFunction<? super R,? super T,? extends R> aggregator)
static <T,R>
Rfolding(R accumulator, Stream<T> stream, SerBiFunction<? super R,? super T,? extends R> aggregator)
static DoubleStream
getStream(double[] ds)
static IntStream
getStream(int max)
static IntStream
getStream(int[] is)
static Stream<String>
getStream(String fileName)
static <T> Stream<T>
getStream(Collection<T> source)
static <K,V>
Stream<Map.Entry<K,V>>getStream(Map<K,V> source)
static <T> Stream<T>
getStream(Spliterator<T> source)
static <T> Stream<T>
getStream(Stream<T> stream)
static <T,K extends T>
Stream<T>getStream(K... elements)
static <U,V,R>
SerCollector<Map.Entry<U,V>,?,ConcurrentMap<U,R>>groupingByKeys(SerCollector<Map.Entry<U,V>,?,R> valueMapper)
static <K,A,B>
SerFunction<Map.Entry<K,A>,Map.Entry<K,B>>keepingKey(SerBiFunction<K,A,B> valueMapper)
static <K,V1,V2>
SerFunction<Map.Entry<K,V1>,Map.Entry<K,V2>>keepingKey(SerFunction<? super V1,? extends V2> valueMapper)
static <K1,K2,V>
SerFunction<Map.Entry<K1,V>,Map.Entry<K2,V>>keepingValue(SerFunction<? super K1,? extends K2> keyMapper)
static <U,V>
SerCollector<Map.Entry<U,V>,?,ConcurrentMap<U,V>>mappingConcurrentEntries(SerSupplier<ConcurrentMap<U,V>> factory)
static <U,V,R>
SerCollector<Map.Entry<U,V>,?,ConcurrentMap<R,V>>mappingKeys(SerFunction<? super U,? extends R> keyMapper)
static <U,V,R>
SerCollector<Map.Entry<U,V>,?,ConcurrentMap<U,R>>mappingValues(SerFunction<? super V,? extends R> valueMapper)
static <T> SerBinaryOperator<T>
mergeError()
static <T> SerBinaryOperator<T>
mergeLeft()
static <T> SerBinaryOperator<T>
mergeRight()
static <T,U>
SerBiPredicate<T,U>not(SerBiPredicate<T,U> test)
static <T,U>
SerPredicate<T>not(SerPredicate<T> test)
static <R> SerUnaryOperator<R>
onlyIf(SerPredicate<? super R> condition, SerUnaryOperator<R> mapper)
static <A extends Serializable,B extends Serializable,C extends Serializable,R extends Serializable>
SerBiFunction<B,C,R>partial(SerTriFunction<A,B,C,R> triFunction, A a)
static <A extends Serializable,B extends Serializable,C extends Serializable,D extends Serializable>
SerConsumer<Quadruple<A,B,C,D>>quartet(QuadConsumer<? super A,? super B,? super C,? super D> quadconsumer)
static <T> SerUnaryOperator<Set<T>>
retainer(Set<? extends T> toRetain)
static <K,V>
Map<K,V>retainOnly(Map<? extends K,? extends V> originalMap, Set<? extends K> askedKeys)
static SerBiPredicate<DataPoint,DataPoint>
reverseIf(boolean isReverse, SerBiPredicate<DataPoint,DataPoint> predicate)
static <A,R>
SerBiFunction<? super A,? super A,? extends R>reverseIf(SerBiFunction<? super A,? super A,? extends R> biFunction, boolean isReverse)
static <A> SerBinaryOperator<A>
reverseIf(SerBinaryOperator<A> binaryOperator, boolean isReverse)
static <T> Set<? extends T>
setOf(T... elements)
static <A extends Serializable,B extends Serializable,C extends Serializable,D extends Serializable,R>
SerFunction<Quadruple<A,B,C,D>,R>splitting(QuadFunction<? super A,? super B,? super C,? super D,? extends R> quadfunction)
static <K,V,R>
SerFunction<Map.Entry<K,V>,R>splitting(SerBiFunction<? super K,? super V,R> biFunction)
static <A extends Serializable,B extends Serializable,C extends Serializable,R>
SerFunction<Triple<A,B,C>,R>splitting(SerTriFunction<? super A,? super B,? super C,? extends R> trifunction)
static <K,V,R>
SerConsumer<Map.Entry<K,V>>splittingConsumer(SerBiConsumer<? super K,? super V> consumer)
static <T,K,V>
SerFunction<T,Map.Entry<K,V>>toEntry(SerFunction<? super T,? extends K> keyMapper, SerFunction<? super T,? extends V> valueMapper)
static <K,V>
SerFunction<V,Map.Entry<K,V>>toEntryWithKey(SerFunction<? super V,? extends K> valueToKeyMapper)
static <K,V>
SerFunction<K,Map.Entry<K,V>>toEntryWithValue(SerFunction<? super K,? extends V> keyToValueMapper)
static <K,V>
SerCollector<V,?,ConcurrentMap<K,V>>toMapWithKeys(SerFunction<? super V,? extends K> valueMapper)
static <K,V>
SerCollector<K,?,ConcurrentMap<K,V>>toMapWithValues(SerFunction<K,V> keyMapper)
static <A extends Serializable,B extends Serializable,C extends Serializable>
SerConsumer<Triple<A,B,C>>triple(TriConsumer<? super A,? super B,? super C> triconsumer)
-
-
-
Method Detail
-
keepingKey
public static <K,V1,V2> SerFunction<Map.Entry<K,V1>,Map.Entry<K,V2>> keepingKey(SerFunction<? super V1,? extends V2> valueMapper)
-
atKey
public static <K,V> SerConsumer<Map.Entry<K,V>> atKey(SerConsumer<? super K> valueMapper)
-
atValue
public static <K,V> SerConsumer<Map.Entry<K,V>> atValue(SerConsumer<? super V> valueMapper)
-
onlyIf
public static <R> SerUnaryOperator<R> onlyIf(SerPredicate<? super R> condition, SerUnaryOperator<R> mapper)
-
afterMapping
public static <T,R> SerPredicate<T> afterMapping(SerFunction<? super T,? extends R> mapper, SerPredicate<? super R> condition)
-
keepingValue
public static <K1,K2,V> SerFunction<Map.Entry<K1,V>,Map.Entry<K2,V>> keepingValue(SerFunction<? super K1,? extends K2> keyMapper)
-
keepingKey
public static <K,A,B> SerFunction<Map.Entry<K,A>,Map.Entry<K,B>> keepingKey(SerBiFunction<K,A,B> valueMapper)
-
toEntry
public static <T,K,V> SerFunction<T,Map.Entry<K,V>> toEntry(SerFunction<? super T,? extends K> keyMapper, SerFunction<? super T,? extends V> valueMapper)
-
toEntryWithValue
public static <K,V> SerFunction<K,Map.Entry<K,V>> toEntryWithValue(SerFunction<? super K,? extends V> keyToValueMapper)
-
toEntryWithKey
public static <K,V> SerFunction<V,Map.Entry<K,V>> toEntryWithKey(SerFunction<? super V,? extends K> valueToKeyMapper)
-
entriesToMap
public static <U,V> SerCollector<Map.Entry<? extends U,? extends V>,?,ConcurrentMap<U,V>> entriesToMap()
-
toMapWithValues
public static <K,V> SerCollector<K,?,ConcurrentMap<K,V>> toMapWithValues(SerFunction<K,V> keyMapper)
-
toMapWithKeys
public static <K,V> SerCollector<V,?,ConcurrentMap<K,V>> toMapWithKeys(SerFunction<? super V,? extends K> valueMapper)
-
entriesToMap
public static <U,V,M extends ConcurrentMap<U,V>> SerCollector<Map.Entry<U,V>,?,M> entriesToMap(SerSupplier<M> mapSupplier)
-
entriesToMap
public static <U,V> SerCollector<Map.Entry<U,V>,?,ConcurrentMap<U,V>> entriesToMap(SerBinaryOperator<V> combiner)
-
mappingValues
public static <U,V,R> SerCollector<Map.Entry<U,V>,?,ConcurrentMap<U,R>> mappingValues(SerFunction<? super V,? extends R> valueMapper)
-
mappingKeys
public static <U,V,R> SerCollector<Map.Entry<U,V>,?,ConcurrentMap<R,V>> mappingKeys(SerFunction<? super U,? extends R> keyMapper)
-
mappingConcurrentEntries
public static <U,V> SerCollector<Map.Entry<U,V>,?,ConcurrentMap<U,V>> mappingConcurrentEntries(SerSupplier<ConcurrentMap<U,V>> factory)
-
groupingByKeys
public static <U,V,R> SerCollector<Map.Entry<U,V>,?,ConcurrentMap<U,R>> groupingByKeys(SerCollector<Map.Entry<U,V>,?,R> valueMapper)
-
folding
public static <T,R> R folding(R accumulator, Stream<T> stream, SerBiFunction<? super R,? super T,? extends R> aggregator)
-
fold
public static <T,R> R fold(R accumulator, Iterable<T> iterable, SerBiFunction<? super R,? super T,? extends R> aggregator)
-
mergeError
public static <T> SerBinaryOperator<T> mergeError()
-
mergeLeft
public static <T> SerBinaryOperator<T> mergeLeft()
-
mergeRight
public static <T> SerBinaryOperator<T> mergeRight()
-
entryByValue
public static <K,V> SerPredicate<Map.Entry<K,V>> entryByValue(SerPredicate<V> valuePredicate)
-
entryByKey
public static <K,V> SerPredicate<Map.Entry<K,V>> entryByKey(SerPredicate<K> keyPredicate)
-
entryByKeyValue
public static <K,V> SerPredicate<? super Map.Entry<K,V>> entryByKeyValue(SerBiPredicate<? super K,? super V> entryPredicate)
-
splitting
public static <K,V,R> SerFunction<Map.Entry<K,V>,R> splitting(SerBiFunction<? super K,? super V,R> biFunction)
-
splittingConsumer
public static <K,V,R> SerConsumer<Map.Entry<K,V>> splittingConsumer(SerBiConsumer<? super K,? super V> consumer)
-
splitting
public static <A extends Serializable,B extends Serializable,C extends Serializable,R> SerFunction<Triple<A,B,C>,R> splitting(SerTriFunction<? super A,? super B,? super C,? extends R> trifunction)
-
triple
public static <A extends Serializable,B extends Serializable,C extends Serializable> SerConsumer<Triple<A,B,C>> triple(TriConsumer<? super A,? super B,? super C> triconsumer)
-
quartet
public static <A extends Serializable,B extends Serializable,C extends Serializable,D extends Serializable> SerConsumer<Quadruple<A,B,C,D>> quartet(QuadConsumer<? super A,? super B,? super C,? super D> quadconsumer)
-
splitting
public static <A extends Serializable,B extends Serializable,C extends Serializable,D extends Serializable,R> SerFunction<Quadruple<A,B,C,D>,R> splitting(QuadFunction<? super A,? super B,? super C,? super D,? extends R> quadfunction)
-
getStream
public static <T> Stream<T> getStream(Spliterator<T> source)
-
getStream
public static <T> Stream<T> getStream(Collection<T> source)
-
getStream
public static IntStream getStream(int max)
-
getStream
public static Stream<String> getStream(String fileName) throws IOException
- Throws:
IOException
-
getStream
@SafeVarargs public static <T,K extends T> Stream<T> getStream(K... elements)
-
getStream
public static IntStream getStream(int[] is)
-
getStream
public static DoubleStream getStream(double[] ds)
-
flatMapping
public static <T,U,A,R> SerCollector<T,A,R> flatMapping(SerFunction<? super T,? extends Stream<? extends U>> mapper, SerCollector<? super U,A,R> downstream)
-
changingFirst
public static <A1 extends Serializable,A2 extends Serializable,B extends Serializable,C extends Serializable> SerFunction<Triple<A1,B,C>,Triple<A2,B,C>> changingFirst(SerFunction<? super A1,? extends A2> mapper)
-
retainer
public static <T> SerUnaryOperator<Set<T>> retainer(Set<? extends T> toRetain)
-
catArrays
public static int[] catArrays(int[] a, int[] b)
-
retainOnly
public static <K,V> Map<K,V> retainOnly(Map<? extends K,? extends V> originalMap, Set<? extends K> askedKeys)
-
curry
public static <A,B,C> SerFunction<A,SerFunction<B,C>> curry(SerBiFunction<A,B,C> biFunction)
-
curry
public static <A,B> SerFunction<A,SerConsumer<B>> curry(SerBiConsumer<A,B> biconsumer)
-
curryRev
public static <A,B,C> SerFunction<B,SerFunction<A,C>> curryRev(SerBiFunction<A,B,C> biFunction)
-
asFun
public static <A,B> SerFunction<A,B> asFun(SerFunction<? super A,? extends B> function)
-
reverseIf
public static <A> SerBinaryOperator<A> reverseIf(SerBinaryOperator<A> binaryOperator, boolean isReverse)
-
reverseIf
public static <A,R> SerBiFunction<? super A,? super A,? extends R> reverseIf(SerBiFunction<? super A,? super A,? extends R> biFunction, boolean isReverse)
-
reverseIf
public static SerBiPredicate<DataPoint,DataPoint> reverseIf(boolean isReverse, SerBiPredicate<DataPoint,DataPoint> predicate)
-
asFun
public static <A,B,C> SerBiFunction<A,B,C> asFun(SerBiFunction<? super A,? super B,? extends C> biFunction)
-
asConsumer
public <T> SerConsumer<T> asConsumer(SerFunction<? super T,?> function)
-
not
public static <T,U> SerBiPredicate<T,U> not(SerBiPredicate<T,U> test)
-
not
public static <T,U> SerPredicate<T> not(SerPredicate<T> test)
-
coalesce
public static <T,C extends Collection<T>> C coalesce(C value, C defaultValue)
-
coalesce
public static <T> T coalesce(T value, T defaultValue)
-
coalesceSwapped
public static <T> T coalesceSwapped(T defaultValue, T value)
-
setOf
@SafeVarargs public static <T> Set<? extends T> setOf(T... elements)
-
partial
public static <A extends Serializable,B extends Serializable,C extends Serializable,R extends Serializable> SerBiFunction<B,C,R> partial(SerTriFunction<A,B,C,R> triFunction, A a)
-
partial
public static <A,B,C,R> SerBiFunction<B,C,R> partial(SerTriFunction<A,B,C,R> triFunction, A a)
-
-