generics LOL

This commit is contained in:
Leijurv
2018-10-30 15:23:14 -07:00
parent 7c69a188f6
commit 5089c62ada
19 changed files with 67 additions and 33 deletions
+2 -5
View File
@@ -17,9 +17,7 @@
package tenor; package tenor;
import java.util.List; public class ActuallyCraftTask extends SingularTaskLeaf {
public class ActuallyCraftTask extends TaskLeaf implements ISingularTask {
public final CraftingTask parent; public final CraftingTask parent;
@@ -35,7 +33,6 @@ public class ActuallyCraftTask extends TaskLeaf implements ISingularTask {
@Override @Override
public double priority() { public double priority() {
List<ISingularChildTaskRelationship> parentTasks = (List) parentTasks(); // pog return parentTasks().stream().mapToDouble(ISingularChildTaskRelationship::allocatedPriority).sum();
return parentTasks.stream().mapToDouble(ISingularChildTaskRelationship::allocatedPriority).sum();
} }
} }
@@ -29,8 +29,6 @@ public class AquireCraftingItems extends QuantizedTaskNode implements ClaimProvi
this.parent = parent; this.parent = parent;
this.parentRelationship = createRelationshipToParent(parent); this.parentRelationship = createRelationshipToParent(parent);
addParent(parentRelationship); addParent(parentRelationship);
} }
@Override @Override
+1 -1
View File
@@ -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 ClaimProvider, IQuantizedDependentCostCalculator { public class AquireItemTask extends QuantizedTaskNode implements ClaimProvider, IQuantizedDependentCostCalculator<IQuantizedChildTaskRelationship> {
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
@@ -17,9 +17,7 @@
package tenor; package tenor;
import java.util.List; public class GetToCraftingTableTask extends SingularTaskLeaf {
public class GetToCraftingTableTask extends TaskLeaf implements ISingularTask {
public static final GetToCraftingTableTask INSTANCE = new GetToCraftingTableTask(); // ? idk public static final GetToCraftingTableTask INSTANCE = new GetToCraftingTableTask(); // ? idk
@Override @Override
@@ -29,7 +27,6 @@ public class GetToCraftingTableTask extends TaskLeaf implements ISingularTask {
@Override @Override
public double priority() { public double priority() {
List<ISingularChildTaskRelationship> parentTasks = (List) parentTasks(); // pog return parentTasks().stream().mapToDouble(ISingularChildTaskRelationship::allocatedPriority).sum();
return parentTasks.stream().mapToDouble(ISingularChildTaskRelationship::allocatedPriority).sum();
} }
} }
@@ -17,7 +17,7 @@
package tenor; package tenor;
public interface IQuantizedDependentCostCalculator extends ITaskNodeBase { public interface IQuantizedDependentCostCalculator<T extends ITaskRelationshipBase> extends ITaskNodeBase<T> {
default IQuantityRelationship cost() { default IQuantityRelationship cost() {
switch (type()) { switch (type()) {
case SERIAL: case SERIAL:
+2 -2
View File
@@ -17,7 +17,7 @@
package tenor; package tenor;
public interface IQuantizedTask extends ITask { public interface IQuantizedTask extends ITask<IQuantizedChildTaskRelationship> {
/*default QuantityRelationship priority() { /*default QuantityRelationship priority() {
return q -> { return q -> {
@@ -33,7 +33,7 @@ public interface IQuantizedTask extends ITask {
IQuantityRelationship cost(); IQuantityRelationship cost();
default IQuantizedChildTaskRelationship<? extends ITaskNodeBase> createRelationshipToParent(ITaskNodeBase parent) { default IQuantizedChildTaskRelationship createRelationshipToParent(ITaskNodeBase parent) {
if (parent instanceof IQuantizedTask) { if (parent instanceof IQuantizedTask) {
return new QuantizedToQuantizedTaskRelationship((QuantizedTaskNode) parent, this, parent.type()); return new QuantizedToQuantizedTaskRelationship((QuantizedTaskNode) parent, this, parent.type());
} else { } else {
+1 -1
View File
@@ -21,6 +21,6 @@ package tenor;
* @author Brady * @author Brady
* @since 10/30/2018 * @since 10/30/2018
*/ */
public interface IQuantizedTaskNode extends ITaskNodeBase, IQuantizedTask { public interface IQuantizedTaskNode extends ITaskNodeBase<IQuantizedChildTaskRelationship>, IQuantizedTask {
} }
+1 -1
View File
@@ -17,7 +17,7 @@
package tenor; package tenor;
public interface ISingularTask extends ITask { public interface ISingularTask extends ITask<ISingularChildTaskRelationship> {
double cost(); double cost();
double priority(); double priority();
+1 -1
View File
@@ -21,6 +21,6 @@ package tenor;
* @author Brady * @author Brady
* @since 10/30/2018 * @since 10/30/2018
*/ */
public interface ISingularTaskNode extends ITaskNodeBase, ISingularTask { public interface ISingularTaskNode extends ITaskNodeBase<ISingularChildTaskRelationship>, ISingularTask {
double priorityAllocatedToChild(ISingularParentTaskRelationship relationship); double priorityAllocatedToChild(ISingularParentTaskRelationship relationship);
} }
+4 -4
View File
@@ -19,13 +19,13 @@ package tenor;
import java.util.List; import java.util.List;
public interface ITask { public interface ITask<T extends ITaskRelationshipBase> {
List<ITaskRelationshipBase> parentTasks(); List<T> parentTasks();
ITaskRelationshipBase createRelationshipToParent(ITaskNodeBase parent); T createRelationshipToParent(ITaskNodeBase parent);
void addParent(ITaskRelationshipBase relationship); void addParent(T relationship);
default void addParent(ITaskNodeBase parent) { default void addParent(ITaskNodeBase parent) {
addParent(createRelationshipToParent(parent)); addParent(createRelationshipToParent(parent));
+1 -1
View File
@@ -19,7 +19,7 @@ package tenor;
import java.util.List; import java.util.List;
public interface ITaskNodeBase extends ITask { public interface ITaskNodeBase<T extends ITaskRelationshipBase> extends ITask<T> {
List<ITaskRelationshipBase> childTasks(); List<ITaskRelationshipBase> childTasks();
+1 -1
View File
@@ -17,7 +17,7 @@
package tenor; package tenor;
public class MineTask extends TaskLeaf implements IQuantizedTask { public class MineTask extends QuantizedTaskLeaf {
@Override @Override
public IQuantityRelationship priority() { public IQuantityRelationship priority() {
return null; return null;
@@ -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 abstract class QuantizedTaskLeaf extends TaskLeaf<IQuantizedChildTaskRelationship> implements IQuantizedTask {
}
+1 -1
View File
@@ -17,7 +17,7 @@
package tenor; package tenor;
public abstract class QuantizedTaskNode extends TaskNode implements IQuantizedTask { public abstract class QuantizedTaskNode extends TaskNode<IQuantizedChildTaskRelationship> implements IQuantizedTask {
public QuantizedTaskNode(DependencyType type) { public QuantizedTaskNode(DependencyType type) {
super(type); super(type);
+21
View 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 abstract class SingularTaskLeaf extends TaskLeaf<ISingularChildTaskRelationship> implements ISingularTask {
}
+1 -1
View File
@@ -17,7 +17,7 @@
package tenor; package tenor;
public abstract class SingularTaskNode extends TaskNode implements ISingularTaskNode { public abstract class SingularTaskNode extends TaskNode<ISingularChildTaskRelationship> implements ISingularTaskNode {
public SingularTaskNode(DependencyType type) { public SingularTaskNode(DependencyType type) {
super(type); super(type);
+4 -4
View File
@@ -19,17 +19,17 @@ package tenor;
import java.util.List; import java.util.List;
public abstract class Task implements ITask { public abstract class Task<T extends ITaskRelationshipBase> implements ITask<T> {
List<ITaskRelationshipBase> parentRelationships; List<T> parentRelationships;
@Override @Override
public List<ITaskRelationshipBase> parentTasks() { public List<T> parentTasks() {
return parentRelationships; return parentRelationships;
} }
@Override @Override
public void addParent(ITaskRelationshipBase relationship) { public void addParent(T relationship) {
if (relationship.childTask() != this) { if (relationship.childTask() != this) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
+1 -1
View File
@@ -17,5 +17,5 @@
package tenor; package tenor;
public abstract class TaskLeaf extends Task { public abstract class TaskLeaf<T extends ITaskRelationshipBase> extends Task<T> {
} }
+1 -1
View File
@@ -19,7 +19,7 @@ package tenor;
import java.util.List; import java.util.List;
public abstract class TaskNode extends Task implements ITaskNodeBase { public abstract class TaskNode<T extends ITaskRelationshipBase> extends Task<T> implements ITaskNodeBase<T> {
List<ITaskRelationshipBase> childRelationships; List<ITaskRelationshipBase> childRelationships;
public final DependencyType type; public final DependencyType type;