Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
io.magentys.FunctionalAgent Maven / Gradle / Ivy
package io.magentys;
import io.magentys.functional.Functions;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
public class FunctionalAgent extends Agent {
public FunctionalAgent(Memory memory) {
super(memory);
}
public static FunctionalAgent functionalAgent() { return new FunctionalAgent(new CoreMemory()); }
public OUTPUT performs(Function myFunction, INPUT input) {
return myFunction.apply(input);
}
public Boolean tests(Predicate predicate, INPUT input) {
return predicate.test(input);
}
public FunctionalAgent keepsInMindTheResultOf(Supplier supplier, String uniqueKey) {
this.keepsInMind(uniqueKey, supplier.get());
return this;
}
public OUTPUT performs(Functions.Function3 functionalMission, One one, Two two) {
return functionalMission.apply(one,two, this);
}
public OUTPUT performs(Functions.Function4 functionalMission, One one, Two two, Three three) {
return functionalMission.apply(one,two, three, this);
}
public OUTPUT performs(Functions.Function5 functionalMission, One one, Two two, Three three, Four four) {
return functionalMission.apply(one,two, three, four, this);
}
public Result performs(Functions.FunctionalMission1 mission, One one) {
return mission.apply(one, this);
}
public Result performs(Functions.FunctionalMission2 mission, One one, Two two) {
return mission.apply(one, two, this);
}
public Result performs(Functions.FunctionalMission3 mission, One one, Two two, Three three) {
return mission.apply(one, two, three, this);
}
public Result performs(Functions.FunctionalMission4 mission, One one, Two two, Three three, Four four) {
return mission.apply(one, two, three, four, this);
}
public CompletableFuture performsAsync(FutureMission mission) {
return mission.accomplishAsync(mission,this);
}
public Future performsAsync(Functions.FunctionalMission1 mission, Input input) {
CompletableFuture futureResult = new CompletableFuture<>();
Runnable runnable = () -> {
try {
Result result = mission.apply(input, this);
futureResult.complete(result);
} catch (Throwable e) {
futureResult.completeExceptionally(e);
}
};
new Thread(runnable).start();
return futureResult;
}
public Future performsAsync(Functions.FunctionalMission2 mission, One one, Two two) {
CompletableFuture futureResult = new CompletableFuture<>();
Runnable runnable = () -> {
try {
Result result = mission.apply(one, two, this);
futureResult.complete(result);
} catch (Throwable e) {
futureResult.completeExceptionally(e);
}
};
new Thread(runnable).start();
return futureResult;
}
public Future performsAsync(Functions.FunctionalMission3 mission, One one, Two two, Three three) {
CompletableFuture futureResult = new CompletableFuture<>();
Runnable runnable = () -> {
try {
Result result = mission.apply(one, two, three, this);
futureResult.complete(result);
} catch (Throwable e) {
futureResult.completeExceptionally(e);
}
};
new Thread(runnable).start();
return futureResult;
}
public Future performsAsync(Functions.FunctionalMission4 mission, One one, Two two, Three three, Four four) {
CompletableFuture futureResult = new CompletableFuture<>();
Runnable runnable = () -> {
try {
Result result = mission.apply(one, two, three, four, this);
futureResult.complete(result);
} catch (Throwable e) {
futureResult.completeExceptionally(e);
}
};
new Thread(runnable).start();
return futureResult;
}
}