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;
//fromwww.java2s.com/**
* The ways we know how to compare values.
*
* @author roelof <rkemp@cs.vu.nl>
* @author nick <palmer@cs.vu.nl>
*
*/publicenum Comparator implements ParseableEnum<Comparator> {
/** greater than. */
GREATER_THAN(0, ">"),
/** less than. */
LESS_THAN(1, "<"),
/** greater than or equal to. */
GREATER_THAN_OR_EQUALS(2, ">="),
/** less than or equal to. */
LESS_THAN_OR_EQUALS(3, "<="),
/** equal to. */
EQUALS(4, "=="),
/** not equal to. */
NOT_EQUALS(5, "!="),
/** Regular Expression Match. */
REGEX_MATCH(6, "regex"),
/** String contains. */
STRING_CONTAINS(7, "contains");
/**
* The converted value for this enum.
*/privatefinalint mValue;
/** The string version of the enum. */private String mName;
/**
* Constructs a Comparator.
*
* @param value
* the convert value
* @param name
* the name of the comparator
*/private Comparator(finalint value, final String name) {
mValue = value;
mName = name;
}
@Override
publicfinal String toString() {
return mName;
}
@Override
publicint convert() {
return mValue;
}
@Override
public Comparator convertInt(finalint val) {
Comparator ret = null;
for (Comparator comp : Comparator.values()) {
if (comp.convert() == val) {
ret = comp;
break;
}
}
return ret;
}
/**
* Parses a string and returns a Comparator.
*
* @param val
* a string to parse
* @return the parsed Comparator
*/private Comparator parseString(final String val) {
Comparator ret = null;
for (Comparator comp : Comparator.values()) {
if (comp.toParseString().equals(val)) {
ret = comp;
break;
}
}
return ret;
}
/**
* Parse a string and return the value.
*
* @param value
* the value to parse
* @return the enum which matches the string.
*/publicstatic Comparator parse(final String value) {
return GREATER_THAN.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 Comparator convert(finalint value) {
return GREATER_THAN.convertInt(value);
}
@Override
public String toParseString() {
return mName;
}
}