-public class Weight {
+public class Weight implements Comparable<Weight> {
+ private int min = 2;
+ private int max = 600;
+ private int defaultWeight = 72;
private int weight;
+ Weight() {
+ }
+
Weight(int weight) {
setWeight(weight);
}
+ public int getMin() {
+ return min;
+ }
+
+ public int getMax() {
+ return max;
+ }
+
+ public int getDefaultWeight() {
+ return defaultWeight;
+ }
+
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
if (validateWeight(weight)) {
this.weight = weight;
- } /* FIXME: raise an error */
+ } else {
+ throw new IllegalArgumentException("Weight must be between " + this.getMin() + " and " + this.getMax());
+ }
}
private boolean validateWeight(int weight) {
- return (weight > 0);
+ return (weight >= getMin() && weight <= getMax());
+ }
+
+ public Integer[] getValuesArray() {
+ int arrayLength = this.getMax() - this.getMin() + 1;
+ Integer[] intArray = new Integer[arrayLength];
+ for (int i = 0; i < intArray.length; i++) {
+ intArray[i] = this.getMin() + i;
+ }
+ return intArray;
+ }
+
+ @Override
+ public int compareTo(Weight weight) {
+ int distance = weight.getWeight() - this.getWeight();
+ if (distance >= 0)
+ return distance;
+ else
+ return -distance;
}
}