io.virtdata.api.composers.ComposerForLongFunction 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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.function.*;
public class ComposerForLongFunction implements FunctionComposer> {
private final static Logger logger = LoggerFactory.getLogger(ComposerForLongFunction.class);
private final LongFunction> inner;
public ComposerForLongFunction(LongFunction> inner) {
this.inner = inner;
}
@Override
public Object getFunctionObject() {
return inner;
}
@Override
@SuppressWarnings("unchecked")
public FunctionComposer andThen(Object outer) {
FunctionType functionType = FunctionType.valueOf(outer);
Object outv = this.inner.apply(1L);
ValueType itype = ValueType.valueOfAssignableClass(outv.getClass());
switch (functionType) {
case long_long:
switch (itype) {
case LONG:
final LongUnaryOperator f11 =
(long l) -> ((LongUnaryOperator) outer).applyAsLong(((LongFunction) inner).apply(l));
return new ComposerForLongUnaryOperator(f11);
case DOUBLE:
final LongUnaryOperator f12 =
(long l) -> ((LongUnaryOperator) outer).applyAsLong(((LongFunction) inner).apply(l).longValue());
return new ComposerForLongUnaryOperator(f12);
case INT:
final LongUnaryOperator f13 =
(long l) -> ((LongUnaryOperator) outer).applyAsLong(((LongFunction) inner).apply(l));
return new ComposerForLongUnaryOperator(f13);
default:
final LongUnaryOperator f14 =
(long l) -> ((LongUnaryOperator) outer).applyAsLong(Double.valueOf(((LongFunction