Copyright (c) 2008-2011 Vrije Universiteit, The Netherlands
All rights reserved.
Redistribution and use in source and binary forms,
with or without modification, are permitted provided
that the follo...
If you think the Android project interdroid-swan listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package interdroid.swan.swansong;
//www.java2s.com/**
* An enumeration which represents Mathematical Operators.
*
* @author roelof <rkemp@cs.vu.nl>
* @author nick <palmer@cs.vu.nl>
*
*/publicenum MathOperator implements ParseableEnum<MathOperator> {
/** The minus operator. Can be used for Locations as well. */
MINUS(0, "-"),
/** The plus operator. */
PLUS(1, "+"),
/** The times operator. */
TIMES(2, "*"),
/** The divide operator. */
DIVIDE(3, "/"),
/** The modulus operator. */
MOD(4, "%");
/**
* The persistence value of the enum.
*/privatefinalint mValue;
/** The string version of the enum. */private String mName;
/**
* Construct an operator.
*
* @param value
* the convert value for the enum
* @param name
* the name of the operation
*/private MathOperator(finalint value, final String name) {
mValue = value;
mName = name;
}
@Override
publicint convert() {
return mValue;
}
@Override
public MathOperator convertInt(finalint val) {
MathOperator ret = null;
for (MathOperator op : MathOperator.values()) {
if (op.convert() == val) {
ret = op;
break;
}
}
return ret;
}
/**
* Parse and return a MathOperator.
*
* @param val
* the string to parse
* @return the corresponding MathOperator
*/private MathOperator parseString(final String val) {
MathOperator ret = null;
for (MathOperator op : MathOperator.values()) {
if (op.toParseString().equals(val)) {
ret = op;
break;
}
}
return ret;
}
/**
* Parse a string and return the value.
*
* @param value
* the value to parse
* @return the enum which matches the string.
*/publicstatic MathOperator parse(final String value) {
return MINUS.parseString(value);
}
/**
* Converts a persisted int to the matching enumeration value.
*
* @param value
* the value to get the enumeration for
* @return the enumeration matching this value
*/publicstatic MathOperator convert(finalint value) {
return MINUS.convertInt(value);
}
@Override
public String toString() {
return mName;
}
@Override
public String toParseString() {
return mName;
}
}