Created
April 26, 2019 18:36
-
-
Save zeryx/c6e7317bbe4cdc5f5506cadbcd0f545a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AlgorithmHandler<INPUT, O, CONTEXT> { | |
private BiFunction<INPUT, CONTEXT, O> applyFunc; | |
private Supplier<CONTEXT> loadFunc; | |
private HashMap<String, Object> context; | |
private <T, J, L> BiFunction<T, J, L> applyHandler(FunctionWithException<T, J, L> fe) { | |
return (arg1, arg2) -> { | |
try { | |
return fe.apply(arg1, arg2); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
}; | |
} | |
private <J> Supplier<J> loadHandler(SupplierWithException<J> fe) { | |
return () -> { | |
try { | |
return fe.apply(); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
}; | |
} | |
public AlgorithmHandler(){ } | |
public AlgorithmHandler(FunctionWithException<INPUT, CONTEXT, O> applyFunc, SupplierWithException<CONTEXT> loadFunc){ | |
this.applyFunc = applyHandler(applyFunc); | |
this.loadFunc = loadHandler(loadFunc); | |
} | |
public AlgorithmHandler(FunctionWithException<INPUT, O> applyFunc){ | |
this.applyFunc = applyHandler(applyFunc); | |
} | |
public void setApply(FunctionWithException<INPUT, CONTEXT, O> func){ | |
applyFunc = applyHandler(func); | |
} | |
public void setLoad(SupplierWithException<CONTEXT> func){ | |
loadFunc = loadHandler(func); | |
} | |
public void run(){ | |
System.out.println(this.applyFunc.getClass()); | |
System.out.println(this.loadFunc.getClass()); | |
System.out.println("Not implemented"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment