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/**
* An enumeration which represents BinaryLogicalOperators.
*
* @author nick <palmer@cs.vu.nl>
*
*/publicenum BinaryLogicOperator implements ParseableEnum<BinaryLogicOperator>,
LogicOperator {
/** Logical AND. */
AND(0, "&&"),
/** Logical OR. */
OR(1, "||");
/** The converted value of this value. */privateint mValue;
/** The string version of the enum. */private String mName;
/**
* Construct a BinaryLogical Operator.
*
* @param value
* the converted value.
* @param name
* the name of the operator.
*/private BinaryLogicOperator(finalint value, final String name) {
mValue = value;
mName = name;
}
@Override
publicint convert() {
return mValue;
}
@Override
public BinaryLogicOperator convertInt(finalint val) {
BinaryLogicOperator ret = null;
for (BinaryLogicOperator op : BinaryLogicOperator.values()) {
if (op.convert() == val) {
ret = op;
break;
}
}
return ret;
}
/**
* Parses and returns a BinaryLogicOperator.
*
* @param val
* the string to parse
* @return the corresponding BinaryLogicOperator
*/public BinaryLogicOperator parseString(final String val) {
BinaryLogicOperator ret = null;
for (BinaryLogicOperator op : BinaryLogicOperator.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 BinaryLogicOperator parse(final String value) {
return AND.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 BinaryLogicOperator convert(finalint value) {
return AND.convertInt(value);
}
@Override
public String toString() {
return mName;
}
@Override
public String toParseString() {
return mName;
}
@Override
public TriState operate(TriState first, TriState last) {
if (mValue == 0) {
// AND
if (first == TriState.TRUE && last == TriState.TRUE) {
return TriState.TRUE;
} elseif (first == TriState.UNDEFINED || last == TriState.UNDEFINED) {
return TriState.UNDEFINED;
} else {
return TriState.FALSE;
}
} elseif (mValue == 1) {
// OR
if (first == TriState.UNDEFINED && last == TriState.UNDEFINED) {
return TriState.UNDEFINED;
} elseif (first == TriState.TRUE || last == TriState.TRUE) {
return TriState.TRUE;
} else {
return TriState.FALSE;
}
} else {
return TriState.UNDEFINED;
}
}
}