Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package crossnum;
- import java.util.Comparator;
- /**
- * Represents an integer variable value, with some special functionality to support
- * the algorithm in CrossNum.
- *
- * @author dub_nerd
- *
- */
- public class Variable {
- /**
- * The value of this variable.
- */
- private int value;
- /**
- * An ordinal value which can function as a label for the variable.
- */
- private int ordinal = -1;
- /**
- * Variable values may be locked against modification. If the
- * lockHolder is non-null the variable is locked.
- */
- private Object lockHolder;
- /**
- * A convenience Comparator for sorting by ordinal value
- */
- static public Comparator<Variable> sortByOrdinal = new Comparator<Variable>() {
- @Override
- public int compare(Variable o1, Variable o2) {
- return o1.getOrdinal() > o2.getOrdinal()? 1 : o1.getOrdinal() == o2.getOrdinal()? 0 : -1;
- }
- };
- /**
- * Construct a new Variable.
- *
- * @param val
- * the variable value
- */
- public Variable(int val) {
- value = val;
- }
- // Various accessor methods
- public int getValue() {
- return value;
- }
- public void setValue(int value) {
- this.value = value;
- }
- public int getOrdinal() {
- return ordinal;
- }
- public void setOrdinal(int ord) {
- this.ordinal = ord;
- }
- public Object getLock() {
- return lockHolder;
- }
- public boolean isLocked() {
- return lockHolder != null;
- }
- public void lock(Object holder) {
- lockHolder = holder;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement