io.virtdata.api.composers.ComposerForDoubleFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of virtdata-lib-realer Show documentation
Show all versions of virtdata-lib-realer Show documentation
With inspiration from other libraries
package io.virtdata.api.composers;
import io.virtdata.api.FunctionType;
import io.virtdata.api.ValueType;
import java.util.function.*;
public class ComposerForDoubleFunction implements FunctionComposer> {
private final DoubleFunction> inner;
public ComposerForDoubleFunction(DoubleFunction> inner) {
this.inner = inner;
}
@Override
public Object getFunctionObject() {
return inner;
}
@Override
@SuppressWarnings("unchecked")
public FunctionComposer andThen(Object outer) {
FunctionType outerFunctionType = FunctionType.valueOf(outer);
Object outv = this.inner.apply(1);
ValueType itype = ValueType.valueOfAssignableClass(outv.getClass());
switch (outerFunctionType) {
case long_long:
switch (itype) {
case LONG:
final DoubleToLongFunction f11 = (double d) ->
((LongUnaryOperator) outer).applyAsLong(((DoubleToLongFunction) inner).applyAsLong(d));
return new ComposerForDoubleToLongFunction(f11);
case DOUBLE:
final DoubleToLongFunction f12 = (double d) ->
((LongUnaryOperator) outer).applyAsLong((long) ((DoubleUnaryOperator) inner).applyAsDouble(d));
return new ComposerForDoubleToLongFunction(f12);
case INT:
final DoubleToLongFunction f13 = (double d) ->
((LongUnaryOperator) outer).applyAsLong(((DoubleToIntFunction) inner).applyAsInt(d));
return new ComposerForDoubleToLongFunction(f13);
default:
final DoubleToLongFunction f14 = (double d) ->
((LongUnaryOperator) outer).applyAsLong(Long.valueOf(((DoubleFunction