/** * Copyright (c): Uwe Schmidt, FH Wedel * * You may study, modify and distribute this source code * FOR NON-COMMERCIAL PURPOSES ONLY. * This copyright message has to remain unchanged. * * Note that this document is provided 'as is', * WITHOUT WARRANTY of any kind either expressed or implied. */ package ds.util; /** just an example class for comparable elements */ public class K implements Comparable { public final int key; public K(int k) { key = k; } // smart constructor public static K mkK(int v) { return new K(v); } // used in IntMap public int intValue() { return key; } public int compareTo(K k2) { if (key == k2.key) return 0; if (key > k2.key) return 1; else return -1; } public boolean equalTo(K k2) { return compareTo(k2) == 0; } public String toString() { return "" + key; } public int hash() { // a very simple hash function for ints return key; } }