/** * Implement a sortable object based on numbers. */ public class IntegerKey implements SearchKey { int value; public IntegerKey(int a) { value = a; } private void verifyType(SearchKey o) { if (! (o instanceof IntegerKey)) throw new RuntimeException("You cannot mix keys here."); } public int compareKey(SearchKey o) { verifyType(o); return (((IntegerKey) o).value - value); } public boolean equalKey(SearchKey o) { return compareKey(o) == 0; } }