equivalent-exchange-3/common/com/pahimar/ee3/item/EnergyStack.java

90 lines
2.6 KiB
Java
Raw Normal View History

package com.pahimar.ee3.item;
2013-08-23 16:59:50 +02:00
public class EnergyStack implements Comparable<EnergyStack> {
2013-08-23 16:59:50 +02:00
public static final String VANILLA_SMELTING_ENERGY_NAME = "vanillaFuelValueUnits";
public static final int VANILLA_SMELTING_ENERGY_THRESHOLD = 200;
public String energyName;
public int stackSize;
public EnergyStack(String energyName, int stackSize) {
this.energyName = energyName;
this.stackSize = stackSize;
}
public EnergyStack(String energyName) {
this(energyName, 1);
2013-08-23 16:59:50 +02:00
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(String.format("%dxenergyStack.%s", stackSize, energyName));
return stringBuilder.toString();
}
@Override
public boolean equals(Object object) {
if (!(object instanceof EnergyStack)) {
return false;
}
EnergyStack energyStack = (EnergyStack) object;
if ((this.energyName != null) && (energyStack.energyName != null)) {
return (stackSize == energyStack.stackSize) && energyName.equalsIgnoreCase(energyStack.energyName);
}
else if ((this.energyName == null) && (energyStack.energyName == null)) {
return (stackSize == energyStack.stackSize);
}
else {
return false;
}
2013-08-23 16:59:50 +02:00
}
2013-09-28 21:00:28 +02:00
public static boolean compareEnergyNames(EnergyStack energyStack1, EnergyStack energyStack2) {
if (energyStack1 != null && energyStack2 != null) {
if ((energyStack1.energyName != null) && (energyStack2.energyName != null)) {
return energyStack1.energyName.equalsIgnoreCase(energyStack2.energyName);
}
}
return false;
}
2013-08-23 16:59:50 +02:00
@Override
public int compareTo(EnergyStack energyStack) {
if (energyStack != null) {
if ((this.energyName != null) && (energyStack.energyName != null)) {
if (this.energyName.equalsIgnoreCase(energyStack.energyName)) {
return (this.stackSize - energyStack.stackSize);
}
else {
return this.energyName.compareToIgnoreCase(energyStack.energyName);
}
}
else if ((this.energyName != null) && (energyStack.energyName == null)) {
return 1;
}
else if ((this.energyName == null) && (energyStack.energyName != null)) {
return -1;
}
else {
return (this.stackSize - energyStack.stackSize);
}
}
else {
return 1;
}
}
2013-08-23 16:59:50 +02:00
}