/* Atoms do not hold variables. * Makes for nice simplification by dereferencing variable names in * the constructor and just dealing with integer values thereafter. */ private Atom(String token) { /* if (token == null || token.length() < 1) throw new IllegalArgumentException( "Tokens must have length > 1, but was '" + token + "'"); */ if (token == null) throw new IllegalArgumentException("Tokens may not be null"); if (token.length() < 1) throw new IllegalArgumentException("Tokens may not be empty"); if (intPattern.matcher(token).matches()) { val = Long.parseLong(token); return; } if (token.length() == 1) { op = MathOp.valueOf(token.charAt(0)); if (op != null) return; } // System.err.println("Trying '" + token + "'"); val = deref(token); }
public static MathOp valueOf(char c) { for (MathOp o : MathOp.values()) if (o.c == c) return o; return null; }
public String toString() { return (op == null) ? Long.toString(val) : op.toString(); }