From c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 12 Feb 2026 22:33:32 -0800 Subject: Initial commit --- NET/worlds/core/Hashtable.java | 105 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 NET/worlds/core/Hashtable.java (limited to 'NET/worlds/core/Hashtable.java') diff --git a/NET/worlds/core/Hashtable.java b/NET/worlds/core/Hashtable.java new file mode 100644 index 0000000..adbc5fd --- /dev/null +++ b/NET/worlds/core/Hashtable.java @@ -0,0 +1,105 @@ +package NET.worlds.core; + +import NET.worlds.scape.Persister; +import NET.worlds.scape.Restorer; +import NET.worlds.scape.Saver; +import NET.worlds.scape.TooNewException; +import java.io.IOException; +import java.util.Enumeration; + +public class Hashtable extends java.util.Hashtable implements Persister { + private static final long serialVersionUID = 1133311923215053895L; + private static Object classCookie = new Object(); + + public Hashtable(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + public Hashtable(int initialCapacity) { + super(initialCapacity); + } + + public Hashtable() { + } + + public Object getKey(Object obj) { + Enumeration e = this.keys(); + + while (e.hasMoreElements()) { + Object key = e.nextElement(); + if (this.get(key) == obj) { + return key; + } + } + + return null; + } + + @Override + public void saveState(Saver s) throws IOException { + s.saveVersion(0, classCookie); + int count = 0; + Enumeration e = this.keys(); + + while (e.hasMoreElements()) { + Object key = e.nextElement(); + Object obj = this.get(key); + if ((key instanceof String || key instanceof Persister) && obj instanceof Persister) { + count++; + } + } + + s.saveInt(count); + e = this.keys(); + + while (e.hasMoreElements()) { + Object key = e.nextElement(); + Object obj = this.get(key); + if ((key instanceof String || key instanceof Persister) && obj instanceof Persister) { + if (key instanceof String) { + s.saveBoolean(true); + s.saveString((String)key); + } else { + s.saveBoolean(false); + s.save((Persister)key); + } + + s.save((Persister)obj); + } + } + } + + @Override + public void restoreState(Restorer r) throws IOException, TooNewException { + int count = this.restoreCount(r); + + for (int i = 0; i < count; i++) { + this.restoreEntry(r); + } + } + + @Override + public void postRestore(int version) { + } + + public int restoreCount(Restorer r) throws IOException, TooNewException { + switch (r.restoreVersion(classCookie)) { + case 0: + return r.restoreInt(); + default: + throw new TooNewException(); + } + } + + public void restoreEntry(Restorer r) throws IOException, TooNewException { + K key; + if (r.restoreBoolean()) { + key = (K)r.restoreString(); + } else { + key = (K)r.restore(); + } + + V obj = (V)r.restore(); + this.put(key, obj); + } +} -- cgit v1.2.3