public final class Volume implements Comparable {
public static final int SILENT_LEVEL = 0;
public static final int SOFT_LEVEL = 1;
public static final int AUDIBLE_LEVEL = 2;
public static final int LOUD_LEVEL = 3;
public static final int ELEVEN_LEVEL = 4;
public static final Volume SILENT = new Volume(SILENT_LEVEL);
public static final Volume SOFT = new Volume(SOFT_LEVEL);
public static final Volume AUDIBLE = new Volume(AUDIBLE_LEVEL);
public static final Volume LOUD = new Volume(LOUD_LEVEL);
public static final Volume ELEVEN = new Volume(ELEVEN_LEVEL);
private static final Volume __VOLUMES[] = {
SILENT, SOFT, AUDIBLE, LOUD, ELEVEN
};
private int __level;
public static final Volume getVolume(int level) {
if(level >= SILENT_LEVEL && level <= ELEVEN_LEVEL)
return __VOLUMES[level];
return null;
}
private Volume(int level) {
__level = level;
}
public boolean equals(Object obj) {
// Assume proper type was given
return (__level == ((Volume)obj).__level);
}
public int compareTo(Object obj) {
// Assume proper type was given
int other = ((Volume)obj).__level;
if(__level == other)
return 0;
if(__level < other)
return -1;
return 1;
}
public int getLevel() { return __level; }
}
|