Created
December 9, 2014 19:39
-
-
Save ictrobot/e2230d600efd594e57cd to your computer and use it in GitHub Desktop.
OLD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ethanjones.cubes.block.data; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Collections; | |
import java.util.List; | |
public class IntegerAttribute extends BasicAttribute<Integer> { | |
private final boolean range; | |
private final int min; | |
private final int max; | |
private final int step; | |
private final List<Integer> values; | |
public IntegerAttribute(String name, int min, int max) { | |
this(name, min, max, 1); | |
} | |
/** | |
* @param min Inclusive | |
* @param max Inclusive | |
*/ | |
public IntegerAttribute(String name, int min, int max, int step) { | |
super(name); | |
this.range = true; | |
this.min = min; | |
this.max = max; | |
this.step = step; | |
this.values = null; | |
} | |
public IntegerAttribute(String name, Integer... values) { | |
super(name); | |
this.range = false; | |
this.min = 0; | |
this.max = 0; | |
this.step = 0; | |
ArrayList<Integer> list = new ArrayList<Integer>(); | |
list.addAll(Arrays.asList(values)); | |
this.values = Collections.unmodifiableList(list); | |
} | |
@Override | |
public int getAttribute(Integer integer) { | |
if (range) { | |
return (integer - min) / step; | |
} else { | |
return values.indexOf(integer); | |
} | |
} | |
@Override | |
public Integer getAttribute(int i) { | |
if (range) { | |
return values.get(i); | |
} else { | |
return min + (i * step); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment