diff options
-rw-r--r-- | crypto/j2me/java/util/AbstractCollection.java | 261 | ||||
-rw-r--r-- | crypto/j2me/java/util/AbstractList.java | 305 | ||||
-rw-r--r-- | crypto/j2me/java/util/AbstractMap.java | 173 | ||||
-rw-r--r-- | crypto/j2me/java/util/AbstractSet.java | 46 | ||||
-rw-r--r-- | crypto/j2me/java/util/ArrayList.java | 107 | ||||
-rw-r--r-- | crypto/j2me/java/util/Arrays.java | 118 | ||||
-rw-r--r-- | crypto/j2me/java/util/Collection.java | 21 | ||||
-rw-r--r-- | crypto/j2me/java/util/Collections.java | 365 | ||||
-rw-r--r-- | crypto/j2me/java/util/HashMap.java | 279 | ||||
-rw-r--r-- | crypto/j2me/java/util/HashSet.java | 71 | ||||
-rw-r--r-- | crypto/j2me/java/util/Iterator.java | 9 | ||||
-rw-r--r-- | crypto/j2me/java/util/List.java | 32 | ||||
-rw-r--r-- | crypto/j2me/java/util/ListIterator.java | 20 | ||||
-rw-r--r-- | crypto/j2me/java/util/Map.java | 54 | ||||
-rw-r--r-- | crypto/j2me/java/util/Set.java | 38 | ||||
-rw-r--r-- | crypto/j2me/java/util/Sublist.java | 142 |
16 files changed, 2041 insertions, 0 deletions
diff --git a/crypto/j2me/java/util/AbstractCollection.java b/crypto/j2me/java/util/AbstractCollection.java new file mode 100644 index 000000000..a08de0005 --- /dev/null +++ b/crypto/j2me/java/util/AbstractCollection.java @@ -0,0 +1,261 @@ +package java.util; + +public abstract class AbstractCollection + implements Collection +{ + protected AbstractCollection() + { + } + + public abstract Iterator iterator(); + + public abstract int size(); + + public boolean isEmpty() + { + return size() == 0; + } + + public boolean contains(Object o) + { + Iterator it = iterator(); + while (it.hasNext()) + { + Object e = it.next(); + if (o == null) + { + if (e == null) + { + return true; + } + } + else + { + if (o.equals(e)) + { + return true; + } + } + } + return false; + } + + public Object[] toArray() + { + Object[] arObjects = new Object[size()]; + Iterator it = iterator(); + int i = 0; + while (it.hasNext()) + { + arObjects[i++] = it.next(); + } + return arObjects; + } + + public Object[] toArray(Object[] a) + throws NullPointerException, ArrayStoreException + //TODO: Check if this is realy compatible to SUN!!! + { + if (a == null) + { + throw new NullPointerException(); + } + + if (isEmpty()) + { + return a; + } + Object[] arObjects = null; + int size = size(); + if (a.length < size) + { + Iterator it = iterator(); + Object o = it.next(); + if (o == null) //no object or object is null + { + throw new ArrayStoreException(); //correct ? + } + throw new ArrayStoreException("please pass array of correct size"); + } + else + { + arObjects = a; + if (a.length > size) + { + arObjects[size] = null; + } + + } + + Iterator it = iterator(); + int i = 0; + while (it.hasNext()) + { + Object o = it.next(); + arObjects[i++] = o; + } + return arObjects; + } + + public boolean add(Object o) + throws RuntimeException, NullPointerException, ClassCastException, IllegalArgumentException + { + throw new RuntimeException(); + } + + public boolean remove(Object o) + throws RuntimeException + { + Iterator it = iterator(); + while (it.hasNext()) + { + Object e = it.next(); + if (o == null) + { + if (e == null) + { + try + { + it.remove(); + } + catch (RuntimeException ue) + { + throw ue; + } + return true; + } + } + else + { + if (o.equals(e)) + { + try + { + it.remove(); + } + catch (RuntimeException ue) + { + throw ue; + } + return true; + } + } + } + return false; + } + + public boolean containsAll(Collection c) + { + Iterator it = c.iterator(); + while (it.hasNext()) + { + if (!contains(it.next())) + { + return false; + } + } + return true; + } + + public boolean addAll(Collection c) + throws RuntimeException + { + Iterator it = c.iterator(); + boolean ret = false; + while (it.hasNext()) + { + try + { + ret |= add(it.next()); + } + catch (RuntimeException ue) + { + throw ue; + } + } + return ret; + } + + public boolean removeAll(Collection c) + throws RuntimeException + { + Iterator it = iterator(); + boolean ret = false; + while (it.hasNext()) + { + if (c.contains(it.next())) + { + try + { + it.remove(); + ret = true; + } + catch (RuntimeException ue) + { + throw ue; + } + } + } + return ret; + } + + public boolean retainAll(Collection c) + throws RuntimeException + { + Iterator it = iterator(); + boolean ret = false; + while (it.hasNext()) + { + if (!c.contains(it.next())) + { + try + { + it.remove(); + ret = true; + } + catch (RuntimeException ue) + { + throw ue; + } + } + } + return ret; + } + + public void clear() + throws RuntimeException + { + Iterator it = iterator(); + while (it.hasNext()) + { + try + { + it.next(); + it.remove(); + } + catch (RuntimeException ue) + { + throw ue; + } + } + } + + public String toString() + { + String ret = "["; + Iterator it = iterator(); + if (it.hasNext()) + { + ret += String.valueOf(it.next()); + } + while (it.hasNext()) + { + ret += ", "; + ret += String.valueOf(it.next()); + + } + ret += "]"; + return ret; + } + +} diff --git a/crypto/j2me/java/util/AbstractList.java b/crypto/j2me/java/util/AbstractList.java new file mode 100644 index 000000000..42dda96ee --- /dev/null +++ b/crypto/j2me/java/util/AbstractList.java @@ -0,0 +1,305 @@ +package java.util; + +public abstract class AbstractList + extends AbstractCollection + implements List +{ + protected AbstractList al = this; + + + protected AbstractList() + { + } + + public boolean add(Object o) + throws RuntimeException, ClassCastException, IllegalArgumentException + { + try + { + add(size(), o); + return true; + } + catch (RuntimeException ue) + { + throw ue; + } + } + + public abstract Object get(int index) + throws IndexOutOfBoundsException; + + public Object set(int index, Object element) + throws RuntimeException, ClassCastException, IllegalArgumentException, IndexOutOfBoundsException + { + throw new RuntimeException(); + } + + public void add(int index, Object element) + throws RuntimeException, ClassCastException, IllegalArgumentException, IndexOutOfBoundsException + { + throw new RuntimeException(); + } + + public Object remove(int index) + throws RuntimeException, IndexOutOfBoundsException + { + Object o = get(index); + + removeRange(index, index + 1); + return o; + } + + public int indexOf(Object o) + { + ListIterator li = listIterator(); + Object e; + while (li.hasNext()) + { + int index = li.nextIndex(); + e = li.next(); + System.out.println(e); + if (o == null) + { + if (e == null) + { + return index; + } + } + else + { + if (o.equals(e)) + { + return index; + } + } + } + return -1; + } + + public int lastIndexOf(Object o) + { + ListIterator li = listIterator(size()); + while (li.hasPrevious()) + { + int index = li.previousIndex(); + Object e = li.previous(); + if (o == null) + { + if (e == null) + { + return index; + } + } + else + { + if (o.equals(e)) + { + return index; + } + } + } + return -1; + } + + public void clear() + throws RuntimeException + { + try + { + removeRange(0, size()); + } + catch (RuntimeException ue) + { + throw ue; + } + } + + public boolean addAll(int index, Collection c) + throws RuntimeException, ClassCastException, IllegalArgumentException, IndexOutOfBoundsException + { + Iterator it = c.iterator(); + boolean ret = false; + while (it.hasNext()) + { + try + { + add(index++, it.next()); + ret = true; + } + catch (RuntimeException ue) + { + throw ue; + } + } + return ret; + } + + public Iterator iterator() + { + return new AbstractListIterator(this, 0); + } + + public ListIterator listIterator() + { + return listIterator(0); + } + + public ListIterator listIterator(int index) + throws IndexOutOfBoundsException + { + if (index < 0 || index > size()) + { + throw new IndexOutOfBoundsException(); + } + return new AbstractListListIterator(this, index); + } + + public List subList(int fromIndex, int toIndex) + throws IndexOutOfBoundsException, IllegalArgumentException + { + if (fromIndex < 0 || toIndex > size()) + { + throw new IndexOutOfBoundsException(); + } + if (fromIndex > toIndex) + { + throw new IllegalArgumentException(); + } + return (List)new Sublist(this, fromIndex, toIndex); + } + + public boolean equals(Object o) + { + if (o == this) + { + return true; + } + if (!(o instanceof List)) + { + return false; + } + Iterator it1 = iterator(); + Iterator it2 = ((List)o).iterator(); + while (it1.hasNext()) + { + if (!it2.hasNext()) + { + return false; + } + Object e1 = it1.next(); + Object e2 = it2.next(); + if (e1 == null) + { + if (e2 != null) + { + return false; + } + } + if (!e1.equals(e2)) + { + return false; + } + } + return true; + } + + public int hashCode() + { + int hashCode = 1; + Iterator it = iterator(); + while (it.hasNext()) + { + Object o = it.next(); + hashCode = 31 * hashCode + (o == null ? 0 : o.hashCode()); + } + return hashCode; + } + + protected void removeRange(int fromIndex, int toIndex) + { + System.out.println("breakpoint 1"); + if (fromIndex == toIndex) + { + return; + } + System.out.println("breakpoint 2"); + ListIterator li = listIterator(fromIndex); + System.out.println("breakpoint 3"); + int i = fromIndex; + do + { + li.next(); + li.remove(); + i++; + } + while (li.hasNext() && i < toIndex); + } + + private class AbstractListIterator + implements Iterator + { + AbstractList m_al = null; + int m_nextIndex = 0; + + public AbstractListIterator(AbstractList al, int index) + { + m_al = al; + m_nextIndex = index; + } + + public boolean hasNext() + { + return m_nextIndex < m_al.size(); + } + + public Object next() + { + return m_al.get(m_nextIndex++); + } + + public void remove() + { + m_al.remove(m_nextIndex - 1); + } + } + + private class AbstractListListIterator + extends AbstractListIterator + implements ListIterator + { + public AbstractListListIterator(AbstractList al, int index) + { + super(al, index); + } + + public boolean hasPrevious() + { + return m_nextIndex > 0; + } + + public Object previous()// throws NoSuchElementException; + { + return m_al.get(--m_nextIndex); + } + + public int nextIndex() + { + return m_nextIndex; + } + + public int previousIndex() + { + return m_nextIndex - 1; + } + + public void set(Object o) //throws RuntimeException, ClassCastException, IllegalArgumentException,IllegalStateException; + { + m_al.set(m_nextIndex - 1, o); + } + + public void add(Object o)// throws RuntimeException, ClassCastException, IllegalArgumentException; + { + m_al.add(m_nextIndex - 1, o); + } + } +} diff --git a/crypto/j2me/java/util/AbstractMap.java b/crypto/j2me/java/util/AbstractMap.java new file mode 100644 index 000000000..13c61ecfa --- /dev/null +++ b/crypto/j2me/java/util/AbstractMap.java @@ -0,0 +1,173 @@ +package java.util; + +public abstract class AbstractMap + implements Map +{ + + protected AbstractMap() + { + } + + public int size() + { + return entrySet().size(); + } + + public boolean isEmpty() + { + return size() == 0; + } + + public boolean containsValue(Object value) + { + Iterator it = entrySet().iterator(); + while (it.hasNext()) + { + Map.Entry v = (Map.Entry)it.next(); + if (value == null) + { + if (v.getValue() == null) + { + return true; + } + } + else + { + if (value.equals(v.getValue())) + { + return true; + } + } + } + return false; + } + + public boolean containsKey(Object key) + throws ClassCastException, NullPointerException + { + Iterator it = entrySet().iterator(); + while (it.hasNext()) + { + Map.Entry v = (Map.Entry)it.next(); + if (key == null) + { + if (v.getKey() == null) + { + return true; + } + } + else + { + if (key.equals(v.getKey())) + { + return true; + } + } + } + return false; + } + + public Object get(Object key) + throws ClassCastException, NullPointerException + { + Iterator it = entrySet().iterator(); + while (it.hasNext()) + { + Map.Entry v = (Map.Entry)it.next(); + if (key == null) + { + if (v.getKey() == null) + { + return v.getValue(); + } + } + else + { + if (key.equals(v.getKey())) + { + return v.getValue(); + } + } + } + return null; + } + + public Object put(Object key, Object value) + throws RuntimeException + { + throw new RuntimeException(); + } + + public Object remove(Object key) + { + Iterator it = entrySet().iterator(); + Object o = null; + while (it.hasNext()) + { + Map.Entry v = (Map.Entry)it.next(); + if (key == null) + { + if (v.getKey() == null) + { + o = v.getValue(); + it.remove(); + return o; + } + } + else + { + if (key.equals(v.getKey())) + { + o = v.getValue(); + it.remove(); + return o; + } + } + } + return null; + } + + public void putAll(Map t) + { + Iterator it = t.entrySet().iterator(); + while (it.hasNext()) + { + Map.Entry v = (Map.Entry)it.next(); + put(v.getKey(), v.getValue()); + } + } + + public void clear() + { + entrySet().clear(); + } + + public Set keySet() + { + throw new RuntimeException("no keySet in AbstractMap()"); + } + + public Collection values() + { + throw new RuntimeException("no values in AbstractMap()"); + } + + public abstract Set entrySet(); + + public boolean equals(Object o) + { + throw new RuntimeException("no equals in AbstractMap()"); + } + + public int hashCode() + { + throw new RuntimeException("no hashCode in AbstractMap()"); + } + + public String toString() + { + throw new RuntimeException("no toString in AbstractMap()"); + } + + +} diff --git a/crypto/j2me/java/util/AbstractSet.java b/crypto/j2me/java/util/AbstractSet.java new file mode 100644 index 000000000..2a91c4766 --- /dev/null +++ b/crypto/j2me/java/util/AbstractSet.java @@ -0,0 +1,46 @@ +package java.util; + +public abstract class AbstractSet + extends AbstractCollection + implements Set +{ + protected AbstractSet() + { + } + + public boolean equals(Object o) + { + if (this == o) + { + return true; + } + if (o == null) + { + return false; + } + if (!(o instanceof Set)) + { + return false; + } + if (((Set)o).size() != size()) + { + return false; + } + return containsAll((Collection)o); + } + + public int hashCode() + { + int hashCode = 0; + Iterator it = iterator(); + while (it.hasNext()) + { + Object o = it.next(); + if (o != null) + { + hashCode += o.hashCode(); + } + } + return hashCode; + } +} diff --git a/crypto/j2me/java/util/ArrayList.java b/crypto/j2me/java/util/ArrayList.java new file mode 100644 index 000000000..80adf4785 --- /dev/null +++ b/crypto/j2me/java/util/ArrayList.java @@ -0,0 +1,107 @@ +package java.util; + +public class ArrayList extends AbstractList + implements List + { + Vector m_Vector=null; + + public ArrayList() + { + m_Vector=new Vector(); + } + + public ArrayList(Collection c) + { + m_Vector=new Vector((int)(c.size()*1.1)); + addAll(c); + } + + public ArrayList(int initialCapacity) + { + m_Vector=new Vector(initialCapacity); + } + + public void trimToSize() + { + m_Vector.trimToSize(); + } + + public void ensureCapacity(int minCapacity) + { + m_Vector.ensureCapacity(minCapacity); + } + + public int size() + { + return m_Vector.size(); + } + + public boolean contains(Object elem) + { + return m_Vector.contains(elem); + } + + public int indexOf(Object elem) + { + return m_Vector.indexOf(elem); + } + + public int lastIndexOf(Object elem) + { + return m_Vector.lastIndexOf(elem); + } + + public Object clone() + { + ArrayList al=new ArrayList(this); + + return al; + } + + public Object[] toArray() + { + Object[] o=new Object[m_Vector.size()]; + m_Vector.copyInto(o); + return o; + } + + public Object get(int index) + { + return m_Vector.elementAt(index); + } + + public Object set(int index,Object elem) + { + Object o=m_Vector.elementAt(index); + m_Vector.setElementAt(elem,index); + return o; + } + + public boolean add(Object o) + { + m_Vector.addElement(o); + return true; + } + + public void add(int index,Object elem) + { + m_Vector.insertElementAt(elem,index); + } + + public Object remove(int index) + { + Object o=m_Vector.elementAt(index); + m_Vector.removeElementAt(index); + return o; + } + + public void clear() + { + m_Vector.removeAllElements(); + } + + + + + + } diff --git a/crypto/j2me/java/util/Arrays.java b/crypto/j2me/java/util/Arrays.java new file mode 100644 index 000000000..8cd74daae --- /dev/null +++ b/crypto/j2me/java/util/Arrays.java @@ -0,0 +1,118 @@ +package java.util; + +public class Arrays +{ + + private Arrays() + { + } + + public static void fill(byte[] ret, byte v) + { + for (int i = 0; i != ret.length; i++) + { + ret[i] = v; + } + } + + public static boolean equals(byte[] a, byte[] a2) + { + if (a == a2) + { + return true; + } + if (a == null || a2 == null) + { + return false; + } + + int length = a.length; + if (a2.length != length) + { + return false; + } + + for (int i = 0; i < length; i++) + { + if (a[i] != a2[i]) + { + return false; + } + } + + return true; + } + + public static List asList(Object[] a) + { + return new ArrayList(a); + } + + private static class ArrayList + extends AbstractList + { + private Object[] a; + + ArrayList(Object[] array) + { + a = array; + } + + public int size() + { + return a.length; + } + + public Object[] toArray() + { + Object[] tmp = new Object[a.length]; + + System.arraycopy(a, 0, tmp, 0, tmp.length); + + return tmp; + } + + public Object get(int index) + { + return a[index]; + } + + public Object set(int index, Object element) + { + Object oldValue = a[index]; + a[index] = element; + return oldValue; + } + + public int indexOf(Object o) + { + if (o == null) + { + for (int i = 0; i < a.length; i++) + { + if (a[i] == null) + { + return i; + } + } + } + else + { + for (int i = 0; i < a.length; i++) + { + if (o.equals(a[i])) + { + return i; + } + } + } + return -1; + } + + public boolean contains(Object o) + { + return indexOf(o) != -1; + } + } + +} diff --git a/crypto/j2me/java/util/Collection.java b/crypto/j2me/java/util/Collection.java new file mode 100644 index 000000000..a911dcd63 --- /dev/null +++ b/crypto/j2me/java/util/Collection.java @@ -0,0 +1,21 @@ + +package java.util; + +public interface Collection + { + public boolean add(Object o) throws RuntimeException,ClassCastException,IllegalArgumentException; + public boolean addAll(Collection c) throws RuntimeException,ClassCastException,IllegalArgumentException; + public void clear() throws RuntimeException; + public boolean contains(Object o); + public boolean containsAll(Collection c); + public boolean equals(Object o); + public int hashCode(); + public boolean isEmpty(); + public Iterator iterator(); + public /*SK13*/boolean remove(Object o) throws RuntimeException; + public boolean removeAll(Collection c) throws RuntimeException; + public boolean retainAll(Collection c) throws RuntimeException; + public int size(); + public Object[] toArray(); + public Object[] toArray(Object[] a) throws ArrayStoreException; + } diff --git a/crypto/j2me/java/util/Collections.java b/crypto/j2me/java/util/Collections.java new file mode 100644 index 000000000..d611e5e3e --- /dev/null +++ b/crypto/j2me/java/util/Collections.java @@ -0,0 +1,365 @@ +package java.util; + +public class Collections +{ + public static List EMPTY_LIST = new ArrayList(); + + private Collections() + { + } + + public static Collection unmodifiableCollection(Collection c) + { + return new UnmodifiableCollection(c); + } + + static class UnmodifiableCollection + implements Collection + { + Collection c; + + UnmodifiableCollection(Collection c) + { + this.c = c; + } + + public int size() + { + return c.size(); + } + + public boolean isEmpty() + { + return c.isEmpty(); + } + + public boolean contains(Object o) + { + return c.contains(o); + } + + public Object[] toArray() + { + return c.toArray(); + } + + public Object[] toArray(Object[] a) + { + return c.toArray(a); + } + + public Iterator iterator() + { + return new Iterator() + { + Iterator i = c.iterator(); + + public boolean hasNext() + { + return i.hasNext(); + } + + public Object next() + { + return i.next(); + } + + public void remove() + { + throw new RuntimeException(); + } + }; + } + + public boolean add(Object o) + { + throw new RuntimeException(); + } + + public boolean remove(Object o) + { + throw new RuntimeException(); + } + + public boolean containsAll(Collection coll) + { + return c.containsAll(coll); + } + + public boolean addAll(Collection coll) + { + throw new RuntimeException(); + } + + public boolean removeAll(Collection coll) + { + throw new RuntimeException(); + } + + public boolean retainAll(Collection coll) + { + throw new RuntimeException(); + } + + public void clear() + { + throw new RuntimeException(); + } + + public String toString() + { + return c.toString(); + } + } + + public static Set unmodifiableSet(Set s) + { + return new UnmodifiableSet(s); + } + + static class UnmodifiableSet + extends UnmodifiableCollection + implements Set + { + UnmodifiableSet(Set s) + { + super(s); + } + + public boolean equals(Object o) + { + return c.equals(o); + } + + public int hashCode() + { + return c.hashCode(); + } + } + + public static Map unmodifiableMap(Map map) + { + return new UnmodifiableMap(map); + } + + static class UnmodifiableMap + implements Map + { + private Map map; + + UnmodifiableMap(Map map) + { + this.map = map; + } + + public int size() + { + return map.size(); + } + + public boolean isEmpty() + { + return map.isEmpty(); + } + + public boolean containsKey(Object key) + throws ClassCastException, NullPointerException + { + return map.containsKey(key); + } + + public boolean containsValue(Object value) + { + return map.containsValue(value); + } + + public Object get(Object key) + throws ClassCastException, NullPointerException + { + return map.get(key); + } + + public Object put(Object key, Object value) + throws RuntimeException, ClassCastException, IllegalArgumentException, NullPointerException + { + throw new RuntimeException("unsupported operation - map unmodifiable"); + } + + public Object remove(Object key) + throws RuntimeException + { + throw new RuntimeException("unsupported operation - map unmodifiable"); + } + + public void putAll(Map t) + throws RuntimeException, ClassCastException, IllegalArgumentException, NullPointerException + { + throw new RuntimeException("unsupported operation - map unmodifiable"); + } + + public void clear() + throws RuntimeException + { + throw new RuntimeException("unsupported operation - map unmodifiable"); + } + + public Set keySet() + { + return map.keySet(); + } + + public Collection values() + { + return map.values(); + } + + public Set entrySet() + { + return map.entrySet(); + } + } + + public static List unmodifiableList(List list) + { + return new UnmodifiableList(list); + } + + static class UnmodifiableList + extends UnmodifiableCollection + implements List + { + private List list; + + UnmodifiableList(List list) + { + super(list); + this.list = list; + } + + public boolean equals(Object o) + { + return list.equals(o); + } + + public int hashCode() + { + return list.hashCode(); + } + + public Object get(int index) + { + return list.get(index); + } + + public Object set(int index, Object element) + { + throw new RuntimeException(); + } + + public void add(int index, Object element) + { + throw new RuntimeException(); + } + + public Object remove(int index) + { + throw new RuntimeException(); + } + + public int indexOf(Object o) + { + return list.indexOf(o); + } + + public int lastIndexOf(Object o) + { + return list.lastIndexOf(o); + } + + public boolean addAll(int index, Collection c) + { + throw new RuntimeException(); + } + + public ListIterator listIterator() + { + return listIterator(0); + } + + public ListIterator listIterator(final int index) + { + return new ListIterator() + { + ListIterator i = list.listIterator(index); + + public boolean hasNext() + { + return i.hasNext(); + } + + public Object next() + { + return i.next(); + } + + public boolean hasPrevious() + { + return i.hasPrevious(); + } + + public Object previous() + { + return i.previous(); + } + + public int nextIndex() + { + return i.nextIndex(); + } + + public int previousIndex() + { + return i.previousIndex(); + } + + public void remove() + { + throw new RuntimeException(); + } + + public void set(Object o) + { + throw new RuntimeException(); + } + + public void add(Object o) + { + throw new RuntimeException(); + } + }; + } + + public List subList(int fromIndex, int toIndex) + { + return new UnmodifiableList(list.subList(fromIndex, toIndex)); + } + } + + public static Enumeration enumeration(final Collection c) + { + return new Enumeration() + { + Iterator i = c.iterator(); + + public boolean hasMoreElements() + { + return i.hasNext(); + } + + public Object nextElement() + { + return i.next(); + } + }; + } +} diff --git a/crypto/j2me/java/util/HashMap.java b/crypto/j2me/java/util/HashMap.java new file mode 100644 index 000000000..0bcd75ddd --- /dev/null +++ b/crypto/j2me/java/util/HashMap.java @@ -0,0 +1,279 @@ +package java.util; + + +public class HashMap extends AbstractMap{ + + ////////////////////////////////////////////////////////////// + ///// innere Klasse Null //////////////////////////////////// + ////////////////////////////////////////////////////////////// +public class Null extends Object + { + public Null() + { + + } + + public String toString() + { + return "Nullobject"; + } + } + + + ////////////////////////////////////////////////////////////// + ///// innere Klasse innerSet //////////////////////////////////// + ////////////////////////////////////////////////////////////// + + class ISet extends AbstractSet implements java.util.Set + { + + Vector vec = null; + + public ISet() + { + + vec = new Vector(); + + } + + public boolean add(Object o) + { + vec.addElement(o); + return true; + } + + public int size() + { + return vec.size(); + } + + public Iterator iterator() + { + return new IIterator(vec); + } + } + + ////////////////////////////////////////////////////////////// + ///// innere Klasse Iterator //////////////////////////////////// + ////////////////////////////////////////////////////////////// + class IIterator implements java.util.Iterator + { + int index = 0; + Vector vec = null; + public IIterator(Vector ve) + { + vec = ve; + } + + public boolean hasNext() + { + if (vec.size() > index) return true; + return false; + } + + public Object next() + { + Object o = vec.elementAt(index); + if (o==Nullobject) o=null; + index++; + return o; + + } + + public void remove() + { + index--; + vec.removeElementAt(index); + } + + } + + ////////////////////////////////////////////////////////////// + ///// innere Klasse Entry //////////////////////////////////// + ////////////////////////////////////////////////////////////// + + + class Entry implements Map.Entry + { + public Object key=null; + public Object value=null; + + public Entry(Object ke,Object valu) + { + key = ke; + value = valu; + } + public boolean equals(Object o) + { + if (value == ((Entry)o).value && key == ((Entry)o).key ) return true; + else return false; + + } + + public Object getValue() + { + return value; + } + + public Object getKey() + { + return (Object)key; + } + + public int hashCode() + { + return value.hashCode() + key.hashCode(); + + } + + public Object setValue(Object valu) + { + value = (String)valu; + return this; + } + } + + //////////////////////////////////////////////////////////////////// + + private Hashtable m_HashTable=null; + private Null Nullobject = null; + + public HashMap() + { + Nullobject = new Null(); + m_HashTable=new Hashtable(); + } + + public HashMap(int initialCapacity) + { + Nullobject = new Null(); + m_HashTable=new Hashtable(initialCapacity); + } + + public HashMap(Map t) + { + Nullobject = new Null(); + m_HashTable=new Hashtable(); + this.putAll(t); + } + + public void clear() + { + m_HashTable.clear(); + } + + public Object clone() + { + HashMap hm=new HashMap(this); + + return hm; + } + + public boolean containsKey(Object key) + { + if (key == null) key = Nullobject; + boolean b = m_HashTable.containsKey(key); + return b; + + } + + public boolean containsValue(Object value) + { + if (value == null ) value = Nullobject; + boolean b = m_HashTable.contains(value); + return b; + } + + public Set entrySet() + { + + Object Key = null; + ISet s = new ISet(); + Enumeration en = m_HashTable.keys(); + while (en.hasMoreElements()) + { + Key = en.nextElement(); + s.add(new Entry(Key,m_HashTable.get(Key))); + } + return s; + } + + public Object get(Object key) + { + + if (key==null) key= Nullobject; + + Object o = m_HashTable.get(key); + + if (o == Nullobject) o=null; + + return o; + } + + public boolean isEmpty() + { + return m_HashTable.isEmpty(); + } + + public Set keySet() + { + ISet s=new ISet(); + Enumeration en = m_HashTable.keys(); + + while (en.hasMoreElements()) + { + s.add(en.nextElement()); + } + + return s; + } + + public Object put(Object key, Object value) + { + if (key==null) key=Nullobject; + if (value==null) value = Nullobject; + return m_HashTable.put(key,value); + } + + public void putAll(Map m) + { + Iterator it = m.entrySet().iterator(); + Object key=null; + Object value=null; + + while (it.hasNext()) + { + Map.Entry me = (Map.Entry)it.next(); + if (me.getKey() == null) key = Nullobject; + else key= me.getKey(); + if (me.getValue()==null) value = Nullobject; + else value = me.getValue(); + m_HashTable.put(key,value); + } + } + + public Object remove(Object key) + { + return m_HashTable.remove(key); + } + + public int size() + { + return m_HashTable.size(); + } + + public Collection values() + { + + ISet s=new ISet(); + Enumeration en = m_HashTable.keys(); + + while (en.hasMoreElements()) + { + Object Key = en.nextElement(); + //s.add(((Map.Entry)m_HashTable.get(Key)).getValue()); + s.add(m_HashTable.get(Key)); + } + return s; + } +} diff --git a/crypto/j2me/java/util/HashSet.java b/crypto/j2me/java/util/HashSet.java new file mode 100644 index 000000000..e37cb7c8d --- /dev/null +++ b/crypto/j2me/java/util/HashSet.java @@ -0,0 +1,71 @@ +package java.util; + +public class HashSet + extends AbstractSet +{ + private HashMap m_HashMap = null; + + public HashSet() + { + m_HashMap = new HashMap(); + } + + public HashSet(Collection c) + { + m_HashMap = new HashMap(Math.max(11, c.size() * 2)); + addAll(c); + } + + public HashSet(int initialCapacity) + { + m_HashMap = new HashMap(initialCapacity); + + } + + public Iterator iterator() + { + return (m_HashMap.keySet()).iterator(); + } + + public int size() + { + return m_HashMap.size(); + } + + public boolean contains(Object o) + { + return m_HashMap.containsKey(o); + } + + public boolean add(Object o) + { + if (!m_HashMap.containsValue(o)) + { + m_HashMap.put((Object)o, (Object)o); + + return true; + + } + + return false; + } + + public boolean remove(Object o) + { + return (m_HashMap.remove(o) != null); + } + + public void clear() + { + m_HashMap.clear(); + } + + + public Object clone() + { + HashSet hs = new HashSet(); + hs.m_HashMap = (HashMap)m_HashMap.clone(); + return hs; + } + +} diff --git a/crypto/j2me/java/util/Iterator.java b/crypto/j2me/java/util/Iterator.java new file mode 100644 index 000000000..f1b9c05fc --- /dev/null +++ b/crypto/j2me/java/util/Iterator.java @@ -0,0 +1,9 @@ + +package java.util; + +public interface Iterator +{ + public abstract boolean hasNext(); + public abstract Object next() throws NoSuchElementException; + public abstract void remove() throws RuntimeException,IllegalStateException; +} diff --git a/crypto/j2me/java/util/List.java b/crypto/j2me/java/util/List.java new file mode 100644 index 000000000..d9df616fd --- /dev/null +++ b/crypto/j2me/java/util/List.java @@ -0,0 +1,32 @@ +package java.util; + +public interface List + extends Collection +{ + void add(int index, Object element) + throws RuntimeException, ClassCastException, IllegalArgumentException, IndexOutOfBoundsException; + + boolean addAll(int index, Collection c) + throws RuntimeException, ClassCastException, IllegalArgumentException, IndexOutOfBoundsException; + + Object get(int index) + throws IndexOutOfBoundsException; + + int indexOf(Object o); + + int lastIndexOf(Object o); + + ListIterator listIterator(); + + ListIterator listIterator(int index) + throws IndexOutOfBoundsException; + + Object remove(int index) + throws RuntimeException, IndexOutOfBoundsException; + + Object set(int index, Object element) + throws RuntimeException, ClassCastException, IllegalArgumentException, IndexOutOfBoundsException; + + List subList(int fromIndex, int toIndex) + throws IndexOutOfBoundsException; +} diff --git a/crypto/j2me/java/util/ListIterator.java b/crypto/j2me/java/util/ListIterator.java new file mode 100644 index 000000000..3e08d959c --- /dev/null +++ b/crypto/j2me/java/util/ListIterator.java @@ -0,0 +1,20 @@ +package java.util; + +public interface ListIterator + extends Iterator +{ + public boolean hasPrevious(); + + public Object previous() + throws NoSuchElementException; + + public int nextIndex(); + + public int previousIndex(); + + public void set(Object o) + throws RuntimeException, ClassCastException, IllegalArgumentException, IllegalStateException; + + public void add(Object o) + throws RuntimeException, ClassCastException, IllegalArgumentException; +} diff --git a/crypto/j2me/java/util/Map.java b/crypto/j2me/java/util/Map.java new file mode 100644 index 000000000..cf496f89d --- /dev/null +++ b/crypto/j2me/java/util/Map.java @@ -0,0 +1,54 @@ +package java.util; + +public interface Map +{ + + public static interface Entry + { + public Object getKey(); + + public Object getValue(); + + public Object setValue(Object value) + throws RuntimeException, ClassCastException, IllegalArgumentException, NullPointerException; + + public boolean equals(Object o); + + public int hashCode(); + } + + public int size(); + + public boolean isEmpty(); + + public boolean containsKey(Object Key) + throws ClassCastException, NullPointerException; + + public boolean containsValue(Object value); + + public Object get(Object key) + throws ClassCastException, NullPointerException; + + public Object put(Object key, Object value) + throws RuntimeException, ClassCastException, IllegalArgumentException, NullPointerException; + + public Object remove(Object key) + throws RuntimeException; + + public void putAll(Map t) + throws RuntimeException, ClassCastException, IllegalArgumentException, NullPointerException; + + public void clear() + throws RuntimeException; + + public Set keySet(); + + public Collection values(); + + public Set entrySet(); + + public boolean equals(Object o); + + public int hashCode(); + +} diff --git a/crypto/j2me/java/util/Set.java b/crypto/j2me/java/util/Set.java new file mode 100644 index 000000000..6ec45c748 --- /dev/null +++ b/crypto/j2me/java/util/Set.java @@ -0,0 +1,38 @@ +package java.util; + +public interface Set + extends Collection +{ + + public int size(); + + public boolean isEmpty(); + + public boolean contains(Object o); + + public Iterator iterator(); + + public Object[] toArray(); + + public Object[] toArray(Object[] a); + + public boolean add(Object o); + + public boolean remove(Object o); + + public boolean containsAll(Collection c); + + public boolean addAll(Collection c); + + public boolean retainAll(Collection c); + + public boolean removeAll(Collection c); + + public void clear(); + + public boolean equals(Object o); + + public int hashCode(); + + +} diff --git a/crypto/j2me/java/util/Sublist.java b/crypto/j2me/java/util/Sublist.java new file mode 100644 index 000000000..48d8d8e89 --- /dev/null +++ b/crypto/j2me/java/util/Sublist.java @@ -0,0 +1,142 @@ +package java.util; + +public class Sublist + extends AbstractList +{ + AbstractList m_al = null; + int m_fromIndex = 0; + int m_toIndex = 0; + int size = 0; + + public Sublist(AbstractList ali, int fromIndex, int toIndex) + { + m_al = ali; + m_toIndex = toIndex; + m_fromIndex = fromIndex; + size = size(); + } + + public Object set(int index, Object o) + { + if (index < size) + { + o = m_al.set(index + m_fromIndex, o); + if (o != null) + { + size++; + m_toIndex++; + } + return o; + } + else + { + throw new IndexOutOfBoundsException(); + } + } + + public Object get(int index) + throws IndexOutOfBoundsException + { + if (index < size) + { + return m_al.get(index + m_fromIndex); + } + else + { + throw new IndexOutOfBoundsException(); + } + } + + public void add(int index, Object o) + { + + if (index <= size) + { + m_al.add(index + m_fromIndex, o); + m_toIndex++; + size++; + + } + else + { + throw new IndexOutOfBoundsException(); + } + + } + + public Object remove(int index, Object o) + { + if (index < size) + { + Object ob = m_al.remove(index + m_fromIndex); + if (ob != null) + { + m_toIndex--; + size--; + } + return ob; + } + else + { + throw new IndexOutOfBoundsException(); + } + } + + public boolean addAll(int index, Collection c) + { + if (index < size) + { + boolean bool = m_al.addAll(index + m_fromIndex, c); + if (bool) + { + int lange = c.size(); + m_toIndex = m_toIndex + lange; + size = size + lange; + } + return bool; + } + else + { + throw new IndexOutOfBoundsException(); + } + } + + public boolean addAll(Collection c) + { + boolean bool = m_al.addAll(m_toIndex, c); + if (bool) + { + int lange = c.size(); + m_toIndex = m_toIndex + lange; + size = size + lange; + } + return bool; + } + + public void removeRange(int from, int to) + { + if ((from <= to) && (from <= size) && (to <= size)) + { + m_al.removeRange(from, to); + int lange = to - from; + m_toIndex = m_toIndex - lange; + size = size - lange; + } + else + { + if (from > to) + { + throw new IllegalArgumentException(); + } + else + { + throw new IndexOutOfBoundsException(); + } + } + } + + public int size() + { + return (m_toIndex - m_fromIndex); + } +} |