Streams are nice
This commit is contained in:
@@ -21,7 +21,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class AquireItemTask extends QuantizedTaskNode implements IClaimProvider, IQuantizedDependentCostCalculator<IQuantizedChildTaskRelationship, IQuantizedParentTaskRelationship> {
|
public class AquireItemTask extends QuantizedTaskNode implements IClaimProvider, IQuantizedDependentCostCalculator {
|
||||||
|
|
||||||
HashMap<IQuantizedChildTaskRelationship, Integer> allocation; // allocation of what tasks have claim over what items in our inventory i guess
|
HashMap<IQuantizedChildTaskRelationship, Integer> allocation; // allocation of what tasks have claim over what items in our inventory i guess
|
||||||
|
|
||||||
|
|||||||
@@ -18,28 +18,21 @@
|
|||||||
package tenor;
|
package tenor;
|
||||||
|
|
||||||
public interface IQuantizedDependentCostCalculator extends IQuantizedTaskNode {
|
public interface IQuantizedDependentCostCalculator extends IQuantizedTaskNode {
|
||||||
|
|
||||||
|
@Override
|
||||||
default IQuantityRelationship cost() {
|
default IQuantityRelationship cost() {
|
||||||
switch (type()) {
|
switch (type()) {
|
||||||
case SERIAL:
|
case SERIAL:
|
||||||
case PARALLEL_ALL:
|
case PARALLEL_ALL:
|
||||||
return q -> {
|
return q -> childTasks().stream()
|
||||||
double sum = 0;
|
.map(IQuantizedParentTaskRelationship::cost)
|
||||||
for (IQuantizedParentTaskRelationship relationship : childTasks()) {
|
.mapToDouble(relationship -> relationship.value(q))
|
||||||
sum += relationship.cost().value(q);
|
.sum();
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
};
|
|
||||||
case ANY_ONE_OF: // TODO this could be smarter about allocating
|
case ANY_ONE_OF: // TODO this could be smarter about allocating
|
||||||
return q -> {
|
return q -> childTasks().stream()
|
||||||
double min = -1;
|
.map(IQuantizedParentTaskRelationship::cost)
|
||||||
for (IQuantizedParentTaskRelationship relationship : childTasks()) {
|
.mapToDouble(relationship -> relationship.value(q))
|
||||||
double cost = relationship.cost().value(q);
|
.min().orElse(-1);
|
||||||
if (min == -1 || cost < min) {
|
|
||||||
min = cost;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return min;
|
|
||||||
};
|
|
||||||
default:
|
default:
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user