1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-08 08:23:11 +00:00

Item template structure

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-14 20:11:42 -03:00
parent e886165b89
commit fe41dbdc6f
59 changed files with 1400 additions and 85 deletions

View File

@@ -0,0 +1,38 @@
package com.l2jserver.util.calculator;
import java.util.List;
import com.l2jserver.util.calculator.operation.AddOperation;
import com.l2jserver.util.calculator.operation.CalculatorOperation;
import com.l2jserver.util.calculator.operation.SetOperation;
import com.l2jserver.util.calculator.operation.SubtractOperation;
import com.l2jserver.util.factory.CollectionFactory;
public class Formula {
private List<CalculatorOperation<Integer>> operations = CollectionFactory
.newList(null);
public void addOperation(int order, CalculatorOperation<Integer> operation) {
operations.set(order, operation);
}
public void add(int order, int value) {
addOperation(order, new AddOperation(value));
}
public void subtract(int order, int value) {
addOperation(order, new SubtractOperation(value));
}
public void set(int order, int value) {
addOperation(order, new SetOperation(value));
}
public int calculate() {
int value = 0;
for (CalculatorOperation<Integer> operation : operations) {
value = operation.calculate(value);
}
return value;
}
}

View File

@@ -0,0 +1,14 @@
package com.l2jserver.util.calculator.operation;
public class AddOperation implements CalculatorOperation<Integer> {
private Integer value;
public AddOperation(Integer value) {
this.value = value;
}
@Override
public Integer calculate(Integer value) {
return value + this.value;
}
}

View File

@@ -0,0 +1,5 @@
package com.l2jserver.util.calculator.operation;
public interface CalculatorOperation<T extends Number> {
T calculate(T value);
}

View File

@@ -0,0 +1,14 @@
package com.l2jserver.util.calculator.operation;
public class MultiplyOperation implements CalculatorOperation<Integer> {
private Integer value;
public MultiplyOperation(Integer value) {
this.value = value;
}
@Override
public Integer calculate(Integer value) {
return value * this.value;
}
}

View File

@@ -0,0 +1,14 @@
package com.l2jserver.util.calculator.operation;
public class SetOperation implements CalculatorOperation<Integer> {
private Integer value;
public SetOperation(Integer value) {
this.value = value;
}
@Override
public Integer calculate(Integer value) {
return this.value;
}
}

View File

@@ -0,0 +1,14 @@
package com.l2jserver.util.calculator.operation;
public class SubtractOperation implements CalculatorOperation<Integer> {
private Integer value;
public SubtractOperation(Integer value) {
this.value = value;
}
@Override
public Integer calculate(Integer value) {
return value - this.value;
}
}