# HG changeset patch # User Jaroslav Tulach # Date 1352575899 -3600 # Node ID 945817561b9ae3c06aa01255a0a815d0b47c1069 # Parent 32653a09f0db4ff886d8a4c26fccab61f8535e60 Trivial implementation of Hashtable and Vector diff -r 32653a09f0db -r 945817561b9a javap/src/main/java/sun/tools/javap/Hashtable.java --- a/javap/src/main/java/sun/tools/javap/Hashtable.java Sat Nov 10 19:01:28 2012 +0100 +++ b/javap/src/main/java/sun/tools/javap/Hashtable.java Sat Nov 10 20:31:39 2012 +0100 @@ -9,25 +9,73 @@ * @author Jaroslav Tulach */ final class Hashtable { + private Object[] keys; + private Object[] values; Hashtable(int i) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + this(); } Hashtable(int i, double d) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + this(); } Hashtable() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } - void put(Object keys, Object val) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + synchronized void put(Object key, Object val) { + int[] where = { -1, -1 }; + Object found = get(key, where); + if (where[0] != -1) { + // key exists + values[where[0]] = val; + } else { + if (where[1] != -1) { + // null found + keys[where[1]] = key; + values[where[1]] = val; + } else { + if (keys == null) { + keys = new Object[11]; + values = new Object[11]; + keys[0] = key; + values[0] = val; + } else { + Object[] newKeys = new Object[keys.length * 2]; + Object[] newValues = new Object[values.length * 2]; + for (int i = 0; i < keys.length; i++) { + newKeys[i] = keys[i]; + newValues[i] = values[i]; + } + newKeys[keys.length] = key; + newValues[keys.length] = val; + keys = newKeys; + values = newValues; + } + } + } } - Object get(String mnem) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + Object get(Object key) { + return get(key, null); + } + private synchronized Object get(Object key, int[] foundAndNull) { + if (keys == null) { + return null; + } + for (int i = 0; i < keys.length; i++) { + if (keys[i] == null) { + if (foundAndNull != null) { + foundAndNull[1] = i; + } + } else if (keys[i].equals(key)) { + if (foundAndNull != null) { + foundAndNull[0] = i; + } + return values[i]; + } + } + return null; } } diff -r 32653a09f0db -r 945817561b9a javap/src/main/java/sun/tools/javap/Vector.java --- a/javap/src/main/java/sun/tools/javap/Vector.java Sat Nov 10 19:01:28 2012 +0100 +++ b/javap/src/main/java/sun/tools/javap/Vector.java Sat Nov 10 20:31:39 2012 +0100 @@ -9,37 +9,49 @@ * @author Jaroslav Tulach */ final class Vector { + private Object[] arr; + Vector() { } Vector(int i) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + this(); } void add(Object objectType) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + addElement(objectType); } void addElement(Object obj) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + setSize(size() + 1); + setElementAt(obj, size()); } int size() { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return arr == null ? 0 : arr.length; } - void copyInto(String[] accflags) { + void copyInto(Object[] accflags) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } Object elementAt(int index) { - throw new UnsupportedOperationException("Not supported yet."); + return arr[index]; } - void setSize(int i) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + void setSize(int len) { + if (arr == null) { + arr = new Object[len]; + } else { + Object[] newArr = new Object[len]; + int min = Math.min(len, arr.length); + for (int i = 0; i < min; i++) { + newArr[i] = arr[i]; + } + arr = newArr; + } } - void setElementAt(String id, int token) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + void setElementAt(Object val, int index) { + arr[index] = val; } }