com.ctreber.aclib.gui.MOEnum Maven / Gradle / Ivy
Show all versions of plantuml Show documentation
package com.ctreber.aclib.gui;
import java.util.HashSet;
/**
*
* Monitored enumeration value.
*
*
*
* © 2002 Christian Treber, [email protected]
*
*
* @author Christian Treber, [email protected]
*
*/
public class MOEnum extends MonitoredObject {
private HashSet fValidValues = new HashSet();
/**
*
* null if no value selected
*/
private Object fValue;
public void addValidValue(Object pValue) {
fValidValues.add(pValue);
}
public void set(Object pValue) {
if (pValue != null) {
checkValue(pValue);
}
fValue = pValue;
fireValueChanged();
}
public Object get() {
return fValue;
}
public boolean is(Object pObject) {
checkValue(pObject);
return this.equals(pObject);
}
public int hashCode() {
if (fValue == null) {
return 0;
}
return fValue.hashCode();
}
private void checkValue(Object pValue) {
if (!fValidValues.contains(pValue)) {
throw new IllegalArgumentException("Illegal enum value '" + pValue + "'");
}
}
public boolean equals(Object obj) {
if (obj instanceof MOEnum) {
MOEnum lOther = (MOEnum) obj;
if (fValue == null) {
return lOther.fValue == null;
}
return fValue.equals(lOther.fValue);
}
if (fValue == null) {
return obj.equals(null);
}
return fValue.equals(obj);
}
public HashSet getValidValues() {
return fValidValues;
}
public boolean checkRange() {
return true;
}
}