Created
February 13, 2012 16:40
-
-
Save Feder1co5oave/1818063 to your computer and use it in GitHub Desktop.
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 arithmeticExpression.tokens; | |
import java.util.regex.Pattern; | |
/** | |
* | |
* @author Feder1co 5oave | |
*/ | |
public class Operator extends Token { | |
//TODO verificare la correttezza dell'uso dei get* static | |
public enum Operators { | |
ADDITION ("+", 0), | |
SUBSTRACTION ("-", 0), | |
MULTIPLICATION ("*", 1), | |
DIVISION ("/", 1); | |
Operators (String s, int prio) { | |
this.s = s; | |
this.prio = prio; | |
} | |
private int prio; | |
private String s; | |
} | |
private Operators type; | |
public Operator (int pos, Operators type) { //XXX private contructor | |
super(pos); | |
this.type = type; | |
} | |
public final int compareTo(Operator o) { //per priorità | |
Integer me, you; | |
me = this.type.prio; | |
you = o.type.prio; | |
return me.compareTo(you); | |
} | |
public Operators getType () { | |
return this.type; | |
} | |
public int getPrio () { | |
return type.prio; | |
} | |
public String toString () { | |
return this.type.s; | |
} | |
public static Operator getAdd (int pos) { | |
return new Operator(pos, Operators.ADDITION); | |
} | |
public static Operator getSub (int pos) { | |
return new Operator(pos, Operators.SUBSTRACTION); | |
} | |
public static Operator getMul (int pos) { | |
return new Operator(pos, Operators.MULTIPLICATION); | |
} | |
public static Operator getDiv (int pos) { | |
return new Operator(pos, Operators.DIVISION); | |
} | |
public Operator clone() { | |
return new Operator(this.getPos(), this.type); | |
} | |
public Pattern getRegex() { | |
//TODO scrivere | |
throw new UnsupportedOperationException("Not supported yet."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment