summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/UniqueHasher.java
blob: 193a145e05fcbc97121c100f88fef4e07f6c9553 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package NET.worlds.scape;

import java.util.Hashtable;

public class UniqueHasher {
   private int currentHash = 0;
   private static UniqueHasher uh_;
   private Hashtable ht = new Hashtable();

   private UniqueHasher() {
   }

   public static UniqueHasher uh() {
      if (uh_ == null) {
         uh_ = new UniqueHasher();
      }

      return uh_;
   }

   public int hash(Object toHash) {
      Integer value = (Integer)this.ht.get(toHash);
      if (value == null) {
         this.currentHash++;
         value = new Integer(this.currentHash);
         this.ht.put(toHash, value);
      }

      return value;
   }
}