001: // This file is part of KeY - Integrated Deductive Software Design
002: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003: // Universitaet Koblenz-Landau, Germany
004: // Chalmers University of Technology, Sweden
005: //
006: // The KeY system is protected by the GNU General Public License.
007: // See LICENSE.TXT for details.
008: //
009: //
010:
011: package de.uka.ilkd.key.util;
012:
013: import java.util.Enumeration;
014: import java.util.Hashtable;
015:
016: /**
017: * Hashtable that uses identity of objects as equality relation
018: * HACK: this is currently quite inefficient
019: */
020:
021: public class ObjectHashtable {
022:
023: private final Hashtable table;
024:
025: private final KeyContainer key;
026:
027: public ObjectHashtable() {
028: table = new Hashtable();
029: key = new KeyContainer(null);
030: }
031:
032: private ObjectHashtable(Hashtable p_table) {
033: table = p_table;
034: key = new KeyContainer(null);
035: }
036:
037: private static class KeyContainer {
038: public Object key;
039:
040: public KeyContainer(Object p) {
041: key = p;
042: }
043:
044: public int hashCode() {
045: return key == null ? 0 : key.hashCode();
046: }
047:
048: public boolean equals(Object p) {
049: return (p instanceof KeyContainer)
050: && ((KeyContainer) p).key == key;
051: }
052: }
053:
054: public Object get(Object p_key) {
055: key.key = p_key;
056: return table.get(key);
057: }
058:
059: public Object remove(Object p_key) {
060: key.key = p_key;
061: return table.remove(key);
062: }
063:
064: public Object put(Object p_key, Object p_value) {
065: return table.put(new KeyContainer(p_key), p_value);
066: }
067:
068: public Enumeration keys() {
069: return new KeyEnumeration(table.keys());
070: }
071:
072: public boolean isEmpty() {
073: return table.isEmpty();
074: }
075:
076: public void clear() {
077: table.clear();
078: }
079:
080: public int size() {
081: return table.size();
082: }
083:
084: public Object clone() {
085: return new ObjectHashtable((Hashtable) table.clone());
086: }
087:
088: private static class KeyEnumeration implements Enumeration {
089: private Enumeration en;
090:
091: public KeyEnumeration(Enumeration p_en) {
092: en = p_en;
093: }
094:
095: public boolean hasMoreElements() {
096: return en.hasMoreElements();
097: }
098:
099: public Object nextElement() {
100: return ((KeyContainer) en.nextElement()).key;
101: }
102: }
103:
104: }
|