i love generics
This commit is contained in:
@@ -17,8 +17,6 @@
|
||||
|
||||
package tenor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AquireCraftingItems extends QuantizedTaskNode implements IClaimProvider {
|
||||
|
||||
final CraftingTask parent;
|
||||
@@ -51,11 +49,11 @@ public class AquireCraftingItems extends QuantizedTaskNode implements IClaimProv
|
||||
return x -> {
|
||||
// cost to get x copies of these items
|
||||
double sum = 0;
|
||||
for (QuantizedToQuantizedTaskRelationship resource : (List<QuantizedToQuantizedTaskRelationship>) (Object) childTasks()) {
|
||||
for (IQuantizedParentTaskRelationship resource : childTasks()) {
|
||||
int amountPerCraft = parent.inputSizeFor((AquireItemTask) resource.childTask());
|
||||
int totalAmountNeeded = x * amountPerCraft;
|
||||
|
||||
int amountForUs = resource.quantityCompleted();
|
||||
int amountForUs = ((IQuantizedChildTaskRelationship) resource).quantityCompleted();
|
||||
totalAmountNeeded -= amountForUs;
|
||||
|
||||
if (totalAmountNeeded <= 0) {
|
||||
@@ -75,8 +73,8 @@ public class AquireCraftingItems extends QuantizedTaskNode implements IClaimProv
|
||||
}
|
||||
// our only parent is the crafting task
|
||||
int minCompletion = Integer.MAX_VALUE;
|
||||
for (IQuantizedChildTaskRelationship resource : (List<IQuantizedChildTaskRelationship>) (Object) childTasks()) {
|
||||
int amountForUs = resource.quantityCompleted();
|
||||
for (IQuantizedParentTaskRelationship resource : childTasks()) {
|
||||
int amountForUs = ((IQuantizedChildTaskRelationship) resource).quantityCompleted();
|
||||
|
||||
int amountPerCraft = parent.inputSizeFor((AquireItemTask) resource.childTask());
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class AquireItemTask extends QuantizedTaskNode implements IClaimProvider, IQuantizedDependentCostCalculator<IQuantizedChildTaskRelationship> {
|
||||
public class AquireItemTask extends QuantizedTaskNode implements IClaimProvider, IQuantizedDependentCostCalculator<IQuantizedChildTaskRelationship, IQuantizedParentTaskRelationship> {
|
||||
|
||||
HashMap<IQuantizedChildTaskRelationship, Integer> allocation; // allocation of what tasks have claim over what items in our inventory i guess
|
||||
|
||||
|
||||
21
src/main/java/tenor/IChildTaskRelationship.java
Normal file
21
src/main/java/tenor/IChildTaskRelationship.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package tenor;
|
||||
|
||||
public interface IChildTaskRelationship {
|
||||
}
|
||||
21
src/main/java/tenor/IParentTaskRelationship.java
Normal file
21
src/main/java/tenor/IParentTaskRelationship.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package tenor;
|
||||
|
||||
public interface IParentTaskRelationship {
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package tenor;
|
||||
|
||||
public interface IQuantizedChildTaskRelationship<T extends ITaskNodeBase> extends ITaskRelationshipBase<T, IQuantizedTask> {
|
||||
public interface IQuantizedChildTaskRelationship<T extends ITaskNodeBase> extends ITaskRelationshipBase<T, IQuantizedTask>, IChildTaskRelationship {
|
||||
|
||||
double allocatedPriority(int quantity);
|
||||
|
||||
|
||||
@@ -17,23 +17,23 @@
|
||||
|
||||
package tenor;
|
||||
|
||||
public interface IQuantizedDependentCostCalculator<T extends ITaskRelationshipBase> extends ITaskNodeBase<T> {
|
||||
public interface IQuantizedDependentCostCalculator extends IQuantizedTaskNode {
|
||||
default IQuantityRelationship cost() {
|
||||
switch (type()) {
|
||||
case SERIAL:
|
||||
case PARALLEL_ALL:
|
||||
return q -> {
|
||||
double sum = 0;
|
||||
for (ITaskRelationshipBase relationship : childTasks()) {
|
||||
sum += ((IQuantizedParentTaskRelationship) relationship).cost().value(q);
|
||||
for (IQuantizedParentTaskRelationship relationship : childTasks()) {
|
||||
sum += relationship.cost().value(q);
|
||||
}
|
||||
return sum;
|
||||
};
|
||||
case ANY_ONE_OF: // TODO this could be smarter about allocating
|
||||
return q -> {
|
||||
double min = -1;
|
||||
for (ITaskRelationshipBase relationship : childTasks()) {
|
||||
double cost = ((IQuantizedParentTaskRelationship) relationship).cost().value(q);
|
||||
for (IQuantizedParentTaskRelationship relationship : childTasks()) {
|
||||
double cost = relationship.cost().value(q);
|
||||
if (min == -1 || cost < min) {
|
||||
min = cost;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package tenor;
|
||||
|
||||
public interface IQuantizedParentTaskRelationship<T extends ITask> extends ITaskRelationshipBase<QuantizedTaskNode, T> {
|
||||
public interface IQuantizedParentTaskRelationship<T extends ITask> extends ITaskRelationshipBase<QuantizedTaskNode, T>, IParentTaskRelationship {
|
||||
|
||||
IQuantityRelationship cost();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,6 @@ package tenor;
|
||||
* @author Brady
|
||||
* @since 10/30/2018
|
||||
*/
|
||||
public interface IQuantizedTaskNode extends ITaskNodeBase<IQuantizedChildTaskRelationship>, IQuantizedTask {
|
||||
public interface IQuantizedTaskNode extends ITaskNodeBase<IQuantizedChildTaskRelationship, IQuantizedParentTaskRelationship>, IQuantizedTask {
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package tenor;
|
||||
|
||||
public interface ISingularChildTaskRelationship<T extends ITaskNodeBase> extends ITaskRelationshipBase<T, ISingularTask> {
|
||||
public interface ISingularChildTaskRelationship<T extends ITaskNodeBase> extends ITaskRelationshipBase<T, ISingularTask>, IChildTaskRelationship {
|
||||
|
||||
double allocatedPriority();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package tenor;
|
||||
|
||||
public interface ISingularParentTaskRelationship<T extends ITask> extends ITaskRelationshipBase<SingularTaskNode, T> {
|
||||
public interface ISingularParentTaskRelationship<T extends ITask> extends ITaskRelationshipBase<SingularTaskNode, T>, IParentTaskRelationship {
|
||||
|
||||
double cost();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,6 @@ package tenor;
|
||||
* @author Brady
|
||||
* @since 10/30/2018
|
||||
*/
|
||||
public interface ISingularTaskNode extends ITaskNodeBase<ISingularChildTaskRelationship>, ISingularTask {
|
||||
public interface ISingularTaskNode extends ITaskNodeBase<ISingularChildTaskRelationship, ISingularParentTaskRelationship>, ISingularTask {
|
||||
double priorityAllocatedToChild(ISingularParentTaskRelationship relationship);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package tenor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ITask<T extends ITaskRelationshipBase> {
|
||||
public interface ITask<T extends IChildTaskRelationship & ITaskRelationshipBase> {
|
||||
|
||||
List<T> parentTasks();
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ package tenor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ITaskNodeBase<T extends ITaskRelationshipBase> extends ITask<T> {
|
||||
public interface ITaskNodeBase<T extends IChildTaskRelationship & ITaskRelationshipBase, S extends IParentTaskRelationship & ITaskRelationshipBase> extends ITask<T> {
|
||||
|
||||
List<ITaskRelationshipBase> childTasks();
|
||||
List<S> childTasks();
|
||||
|
||||
DependencyType type();
|
||||
|
||||
void addChild(ITaskRelationshipBase relationship);
|
||||
void addChild(S relationship);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package tenor;
|
||||
|
||||
public abstract class QuantizedTaskNode extends TaskNode<IQuantizedChildTaskRelationship> implements IQuantizedTask {
|
||||
public abstract class QuantizedTaskNode extends TaskNode<IQuantizedChildTaskRelationship, IQuantizedParentTaskRelationship> implements IQuantizedTask {
|
||||
|
||||
public QuantizedTaskNode(DependencyType type) {
|
||||
super(type);
|
||||
@@ -37,7 +37,7 @@ public abstract class QuantizedTaskNode extends TaskNode<IQuantizedChildTaskRela
|
||||
}
|
||||
int minQuantity = -1;
|
||||
for (int i = 0; i < childTasks().indexOf(child); i++) {
|
||||
QuantizedToQuantizedTaskRelationship relationship = (QuantizedToQuantizedTaskRelationship) childTasks().get(i);
|
||||
IQuantizedChildTaskRelationship relationship = (IQuantizedChildTaskRelationship) childTasks().get(i);
|
||||
IClaimProvider claim = (IClaimProvider) relationship.childTask();
|
||||
int amt = claim.quantityCompletedForParent(relationship);
|
||||
if (minQuantity == -1 || amt < minQuantity) {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
package tenor;
|
||||
|
||||
public abstract class SingularTaskNode extends TaskNode<ISingularChildTaskRelationship> implements ISingularTaskNode {
|
||||
public abstract class SingularTaskNode extends TaskNode<ISingularChildTaskRelationship, ISingularParentTaskRelationship> implements ISingularTaskNode {
|
||||
|
||||
public SingularTaskNode(DependencyType type) {
|
||||
super(type);
|
||||
|
||||
@@ -19,7 +19,7 @@ package tenor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Task<T extends ITaskRelationshipBase> implements ITask<T> {
|
||||
public abstract class Task<T extends IChildTaskRelationship & ITaskRelationshipBase> implements ITask<T> {
|
||||
|
||||
List<T> parentRelationships;
|
||||
|
||||
@@ -33,7 +33,7 @@ public abstract class Task<T extends ITaskRelationshipBase> implements ITask<T>
|
||||
if (relationship.childTask() != this) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
relationship.parentTask().addChild(relationship);
|
||||
relationship.parentTask().addChild((IParentTaskRelationship) relationship);
|
||||
parentRelationships.add(relationship);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,5 +17,5 @@
|
||||
|
||||
package tenor;
|
||||
|
||||
public abstract class TaskLeaf<T extends ITaskRelationshipBase> extends Task<T> {
|
||||
public abstract class TaskLeaf<T extends IChildTaskRelationship & ITaskRelationshipBase> extends Task<T> {
|
||||
}
|
||||
|
||||
@@ -19,24 +19,27 @@ package tenor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class TaskNode<T extends ITaskRelationshipBase> extends Task<T> implements ITaskNodeBase<T> {
|
||||
public abstract class TaskNode<T extends IChildTaskRelationship & ITaskRelationshipBase, S extends IParentTaskRelationship & ITaskRelationshipBase> extends Task<T> implements ITaskNodeBase<T, S> {
|
||||
|
||||
List<ITaskRelationshipBase> childRelationships;
|
||||
List<S> childRelationships;
|
||||
public final DependencyType type;
|
||||
|
||||
public TaskNode(DependencyType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public List<ITaskRelationshipBase> childTasks() {
|
||||
@Override
|
||||
public List<S> childTasks() {
|
||||
return childRelationships;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DependencyType type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void addChild(ITaskRelationshipBase relationship) {
|
||||
@Override
|
||||
public void addChild(S relationship) {
|
||||
if (relationship.parentTask() != this) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user