equivalent-exchange-3/common/com/pahimar/ee3/emc/EmcComponent.java

62 lines
1.3 KiB
Java
Raw Normal View History

2013-08-23 16:59:50 +02:00
package com.pahimar.ee3.emc;
public class EmcComponent implements Comparable<EmcComponent> {
2013-08-23 16:59:50 +02:00
private final EmcType type;
private final int ratioWeight;
2013-08-23 16:59:50 +02:00
public EmcComponent(EmcType emcType, int ratioWeight) {
2013-08-23 16:59:50 +02:00
this.type = emcType;
this.ratioWeight = ratioWeight;
2013-08-23 16:59:50 +02:00
}
public EmcType getType() {
2013-08-23 16:59:50 +02:00
return type;
2013-08-23 16:59:50 +02:00
}
public int getRatioWeight() {
2013-08-23 16:59:50 +02:00
return ratioWeight;
2013-08-23 16:59:50 +02:00
}
@Override
public boolean equals(Object object) {
if (!(object instanceof EmcComponent)) {
return false;
}
EmcComponent emcComponent = (EmcComponent) object;
2013-08-23 16:59:50 +02:00
return ((this.type == emcComponent.type) && (this.ratioWeight == emcComponent.ratioWeight));
2013-08-23 16:59:50 +02:00
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(String.format("<EMC Type: %s, Ratio Weight: %s>", type, ratioWeight));
2013-08-23 16:59:50 +02:00
return stringBuilder.toString();
}
@Override
public int compareTo(EmcComponent emcComponent) {
if (emcComponent != null) {
if (this.type == emcComponent.type) {
return (this.ratioWeight - emcComponent.ratioWeight);
}
else {
return this.type.compareTo(emcComponent.type);
}
}
else {
return 1;
}
}
2013-08-23 16:59:50 +02:00
}