-
-/////////////////////////////////////////////////////////////////////////////
-// AbstractList.java -- Abstract implementation of most of List
-//
-// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-
-// TO DO:
-// ~ Doc comments for almost everything.
-// ~ Better general commenting
-
-package jode.util;
-import java.util.NoSuchElementException;
-
-/**
- * A basic implementation of most of the methods in the List interface to make
- * it easier to create a List based on a random-access data structure. To
- * create an unmodifiable list, it is only necessary to override the size() and
- * get(int) methods (this contrasts with all other abstract collection classes
- * which require an iterator to be provided). To make the list modifiable, the
- * set(int, Object) method should also be overridden, and to make the list
- * resizable, the add(int, Object) and remove(int) methods should be overridden
- * too. Other methods should be overridden if the backing data structure allows
- * for a more efficient implementation. The precise implementation used by
- * AbstractList is documented, so that subclasses can tell which methods could
- * be implemented more efficiently.
- */
-public abstract class AbstractList extends AbstractCollection implements List {
-
- /**
- * A count of the number of structural modifications that have been made to
- * the list (that is, insertions and removals).
- */
- protected transient int modCount = 0;
-
- public abstract Object get(int index);
-
- public void add(int index, Object o) {
- throw new UnsupportedOperationException();
- }
-
- public boolean add(Object o) {
- add(size(), o);
- return true;
- }
-
- public boolean addAll(int index, Collection c) {
- Iterator i = c.iterator();
- if (i.hasNext()) {
- do {
- add(index++, i.next());
- } while (i.hasNext());
- return true;
- } else {
- return false;
- }
- }
-
- public void clear() {
- removeRange(0, size());
- }
-
- public boolean equals(Object o) {
- if (o == this) {
- return true;
- } else if (!(o instanceof List)) {
- return false;
- } else {
- Iterator i1 = iterator();
- Iterator i2 = ((List)o).iterator();
- while (i1.hasNext()) {
- if (!i2.hasNext()) {
- return false;
- } else {
- Object e = i1.next();
- if (e == null ? i2.next() != null : !e.equals(i2.next())) {
- return false;
- }
- }
- }
- if (i2.hasNext()) {
- return false;
- } else {
- return true;
- }
- }
- }
-
- public int hashCode() {
- int hashCode = 1;
- Iterator i = iterator();
- while (i.hasNext()) {
- Object obj = i.next();
- hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
- }
- return hashCode;
- }
-
- public int indexOf(Object o) {
- int index = 0;
- ListIterator i = listIterator();
- if (o == null) {
- while (i.hasNext()) {
- if (i.next() == null) {
- return index;
- }
- index++;
- }
- } else {
- while (i.hasNext()) {
- if (o.equals(i.next())) {
- return index;
- }
- index++;
- }
- }
- return -1;
- }
-
- public Iterator iterator() {
- return new Iterator() {
- private int knownMod = modCount;
- private int position = 0;
- boolean removed = true;
-
- private void checkMod() {
- if (knownMod != modCount) {
- throw new ConcurrentModificationException();
- }
- }
-
- public boolean hasNext() {
- checkMod();
- return position < size();
- }
-
- public Object next() {
- checkMod();
- removed = false;
- try {
- return get(position++);
- } catch (IndexOutOfBoundsException e) {
- throw new NoSuchElementException();
- }
- }
-
- public void remove() {
- checkMod();
- if (removed) {
- throw new IllegalStateException();
- }
- AbstractList.this.remove(--position);
- knownMod = modCount;
- removed = true;
- }
- };
- }
-
- public int lastIndexOf(Object o) {
- int index = size();
- ListIterator i = listIterator(index);
- if (o == null) {
- while (i.hasPrevious()) {
- if (i.previous() == null) {
- return index;
- }
- index--;
- }
- } else {
- while (i.hasPrevious()) {
- if (o.equals(i.previous())) {
- return index;
- }
- index--;
- }
- }
- return -1;
- }
-
- public ListIterator listIterator() {
- return listIterator(0);
- }
-
- public ListIterator listIterator(final int index) {
-
- if (index < 0 || index > size()) {
- throw new IndexOutOfBoundsException();
- }
-
- return new ListIterator() {
- private int knownMod = modCount;
- private int position = index;
- private int lastReturned = -1;
-
- private void checkMod() {
- if (knownMod != modCount) {
- throw new ConcurrentModificationException();
- }
- }
-
- public boolean hasNext() {
- checkMod();
- return position < size();
- }
-
- public boolean hasPrevious() {
- checkMod();
- return position > 0;
- }
-
- public Object next() {
- checkMod();
- if (hasNext()) {
- lastReturned = position++;
- return get(lastReturned);
- } else {
- throw new NoSuchElementException();
- }
- }
-
- public Object previous() {
- checkMod();
- if (hasPrevious()) {
- lastReturned = --position;
- return get(lastReturned);
- } else {
- throw new NoSuchElementException();
- }
- }
-
- public int nextIndex() {
- checkMod();
- return position;
- }
-
- public int previousIndex() {
- checkMod();
- return position - 1;
- }
-
- public void remove() {
- checkMod();
- if (lastReturned < 0) {
- throw new IllegalStateException();
- }
- AbstractList.this.remove(lastReturned);
- knownMod = modCount;
- position = lastReturned;
- lastReturned = -1;
- }
-
- public void set(Object o) {
- checkMod();
- if (lastReturned < 0) {
- throw new IllegalStateException();
- }
- AbstractList.this.set(lastReturned, o);
- }
-
- public void add(Object o) {
- checkMod();
- AbstractList.this.add(position++, o);
- lastReturned = -1;
- knownMod = modCount;
- }
- };
- }
-
- public Object remove(int index) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Remove a subsection of the list. This is called by the clear and
- * removeRange methods of the class which implements subList, which are
- * difficult for subclasses to override directly. Therefore, this method
- * should be overridden instead by the more efficient implementation, if one
- * exists.
- *
- * This implementation first checks for illegal or out of range arguments. It
- * then obtains a ListIterator over the list using listIterator(fromIndex).
- * It then calls next() and remove() on this iterator repeatedly, toIndex -
- * fromIndex times.
- *
- * @param fromIndex the index, inclusive, to remove from.
- * @param toIndex the index, exclusive, to remove to.
- * @exception UnsupportedOperationException if this list does not support
- * the removeRange operation.
- * @exception IndexOutOfBoundsException if fromIndex > toIndex || fromIndex <
- * 0 || toIndex > size().
- */
- protected void removeRange(int fromIndex, int toIndex) {
- if (fromIndex > toIndex) {
- throw new IllegalArgumentException();
- } else if (fromIndex < 0 || toIndex > size()) {
- throw new IndexOutOfBoundsException();
- } else {
- ListIterator i = listIterator(fromIndex);
- for (int index = fromIndex; index < toIndex; index++) {
- i.next();
- i.remove();
- }
- }
- }
-
- public Object set(int index, Object o) {
- throw new UnsupportedOperationException();
- }
-
- private static class SubList extends AbstractList {
-
- // Note that within this class two fields called modCount are inherited -
- // one from the superclass, and one from the backing class. These are
- // explicitly disambiguated in the code by referring to "this.modCount"
- // and "backing.modCount".
- // The code uses both these two fields and *no other* to provide fail-fast
- // behaviour. For correct operation, the two fields should contain equal
- // values. Therefore, if this.modCount != backing.modCount, there
- // has been a concurrent modification. This is all achieved purely by using
- // the modCount field, precisely according to the docs of AbstractList.
- // See the methods upMod and checkMod.
-
- // Jikes doesn't want to access outer instance with AbstractList.this,
- // since this is an AbstractList, too. I therefor changed class to static
- // and do it by hand. This makes it a lot clearer by the way.
- private AbstractList backing;
- private final int offset;
- private int size;
-
- SubList(AbstractList backing, int fromIndex, int toIndex) {
- this.backing = backing;
- this.offset = fromIndex;
- this.size = toIndex - fromIndex;
-
- upMod();
- }
-
- /**
- * This method checks the two modCount fields to ensure that there has
- * not been a concurrent modification. It throws an exception if there
- * has been, and otherwise returns normally.
- * Note that since this method is private, it will be inlined.
- *
- * @exception ConcurrentModificationException if there has been a
- * concurrent modification.
- */
- private void checkMod() {
- if (modCount != backing.modCount) {
- throw new ConcurrentModificationException();
- }
- }
-
- /**
- * This method is called after every method that causes a structural
- * modification to the backing list. It updates the local modCount field
- * to match that of the backing list.
- * Note that since this method is private, it will be inlined.
- */
- private void upMod() {
- modCount = backing.modCount;
- }
-
- /**
- * This method checks that a value is between 0 and size (inclusive). If
- * it is not, an exception is thrown.
- * Note that since this method is private, it will be inlined.
- *
- * @exception IndexOutOfBoundsException if the value is out of range.
- */
- private void checkBoundsInclusive(int index) {
- if (index < 0 || index > size) {
- throw new IndexOutOfBoundsException();
- }
- }
-
- /**
- * This method checks that a value is between 0 (inclusive) and size
- * (exclusive). If it is not, an exception is thrown.
- * Note that since this method is private, it will be inlined.
- *
- * @exception IndexOutOfBoundsException if the value is out of range.
- */
- private void checkBoundsExclusive(int index) {
- if (index < 0 || index >= size) {
- throw new IndexOutOfBoundsException();
- }
- }
-
- public int size() {
- checkMod();
- return size;
- }
-
- public Iterator iterator() {
- return listIterator();
- }
-
- public ListIterator listIterator(final int index) {
-
- checkMod();
- checkBoundsInclusive(index);
-
- return new ListIterator() {
- ListIterator i = backing.listIterator(index + offset);
- int position = index;
-
- public boolean hasNext() {
- checkMod();
- return position < size;
- }
-
- public boolean hasPrevious() {
- checkMod();
- return position > 0;
- }
-
- public Object next() {
- if (position < size) {
- Object o = i.next();
- position++;
- return o;
- } else {
- throw new NoSuchElementException();
- }
- }
-
- public Object previous() {
- if (position > 0) {
- Object o = i.previous();
- position--;
- return o;
- } else {
- throw new NoSuchElementException();
- }
- }
-
- public int nextIndex() {
- return offset + i.nextIndex();
- }
-
- public int previousIndex() {
- return offset + i.previousIndex();
- }
-
- public void remove() {
- i.remove();
- upMod();
- size--;
- position = nextIndex();
- }
-
- public void set(Object o) {
- i.set(o);
- }
-
- public void add(Object o) {
- i.add(o);
- upMod();
- size++;
- position++;
- }
-
- // Here is the reason why the various modCount fields are mostly
- // ignored in this wrapper listIterator.
- // IF the backing listIterator is failfast, then the following holds:
- // Using any other method on this list will call a corresponding
- // method on the backing list *after* the backing listIterator
- // is created, which will in turn cause a ConcurrentModException
- // when this listIterator comes to use the backing one. So it is
- // implicitly failfast.
- // If the backing listIterator is NOT failfast, then the whole of
- // this list isn't failfast, because the modCount field of the
- // backing list is not valid. It would still be *possible* to
- // make the iterator failfast wrt modifications of the sublist
- // only, but somewhat pointless when the list can be changed under
- // us.
- // Either way, no explicit handling of modCount is needed.
- // However upMod() must be called in add and remove, and size
- // must also be updated in these two methods, since they do not go
- // through the corresponding methods of the subList.
-
- };
- }
-
- public Object set(int index, Object o) {
- checkMod();
- checkBoundsExclusive(index);
- o = backing.set(index + offset, o);
- upMod();
- return o;
- }
-
- public Object get(int index) {
- checkMod();
- checkBoundsExclusive(index);
- return backing.get(index + offset);
- }
-
- public void add(int index, Object o) {
- checkMod();
- checkBoundsInclusive(index);
- backing.add(index + offset, o);
- upMod();
- size++;
- }
-
- public Object remove(int index) {
- checkMod();
- checkBoundsExclusive(index);
- Object o = backing.remove(index + offset);
- upMod();
- size--;
- return o;
- }
-
- public void removeRange(int fromIndex2, int toIndex2) {
- checkMod();
- checkBoundsExclusive(fromIndex2);
- checkBoundsInclusive(toIndex2);
-
- // this call will catch the toIndex2 < fromIndex2 condition
- backing.removeRange(offset + fromIndex2, offset + toIndex2);
- upMod();
- size -= toIndex2 - fromIndex2;
- }
-
- public boolean addAll(int index, Collection c) {
- checkMod();
- checkBoundsInclusive(index);
- int s = backing.size();
- boolean result = backing.addAll(offset + index, c);
- upMod();
- size += backing.size() - s;
- return result;
- }
- }
-
- public List subList(final int fromIndex, final int toIndex) {
- return new SubList(this, fromIndex, toIndex);
- }
-
-}
diff --git a/jode/jode/util/AbstractMap.java b/jode/jode/util/AbstractMap.java
deleted file mode 100644
index fd57b75..0000000
--- a/jode/jode/util/AbstractMap.java
+++ /dev/null
@@ -1,280 +0,0 @@
-// This interface is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// AbstractMap.java -- Abstract implementation of most of Map
-//
-// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com),
-// Free Software Foundation, Inc.
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-
-// TO DO:
-// comments
-// test suite
-
-package jode.util;
-
-public abstract class AbstractMap implements Map {
-
- public void clear()
- {
- entrySet().clear();
- }
-
- public boolean containsKey( Object key )
- {
- Object k;
- Iterator entries = entrySet().iterator();
-
- while( entries.hasNext() )
- {
- k = ((Map.Entry)entries.next()).getKey();
- if( key == null ? k == null : key.equals( k ) )
- return true;
- }
-
- return false;
- }
-
- public boolean containsValue( Object value )
- {
- Object v;
- Iterator entries = entrySet().iterator();
-
- while( entries.hasNext() )
- {
- v = ((Map.Entry)entries.next()).getValue();
- if( value == null ? v == null : value.equals( v ) )
- return true;
- }
-
- return false;
- }
-
- public abstract Set entrySet();
-
- public boolean equals( Object o )
- {
- if( this == o )
- return true;
-
- if( o == null || !( o instanceof Map ) )
- return false;
-
- Map m = (Map)o;
- if( m.size() != size() )
- return false;
-
- Object key, value1, value2;
- Map.Entry entry;
- Iterator entries = entrySet().iterator();
- while( entries.hasNext() )
- {
- entry = (Map.Entry)entries.next();
- key = entry.getKey();
- value1 = entry.getValue();
- value2 = m.get( key );
-
- if( !( ( value1 == null && value2 == null )
- || value1.equals( value2 ) ) )
- return false;
- }
-
- return true;
- }
-
- public Object get( Object key )
- {
- Object k;
- Map.Entry entry;
- Iterator entries = entrySet().iterator();
-
- while( entries.hasNext() )
- {
- entry = (Map.Entry)entries.next();
- k = entry.getKey();
- if( key == null ? k == null : key.equals( k ) )
- return entry.getValue();
- }
-
- return null;
- }
-
- public int hashCode()
- {
- int hashcode = 0;
- Iterator entries = entrySet().iterator();
-
- while( entries.hasNext() )
- hashcode += entries.next().hashCode();
-
- return hashcode;
- }
-
- public boolean isEmpty()
- {
- return size() == 0;
- }
-
- public Set keySet()
- {
- if( this.keySet == null )
- {
- this.keySet =
- new AbstractSet()
- {
- public int size()
- {
- return AbstractMap.this.size();
- }
-
- public boolean contains(Object key)
- {
- return AbstractMap.this.containsKey(key);
- }
-
- public Iterator iterator()
- {
- return new Iterator()
- {
- Iterator map_iterator = AbstractMap.this.entrySet().iterator();
-
- public boolean hasNext()
- {
- return map_iterator.hasNext();
- }
-
- public Object next()
- {
- return ((Map.Entry)map_iterator.next()).getKey();
- }
-
- public void remove()
- {
- map_iterator.remove();
- }
- };
- }
- };
- }
-
- return this.keySet;
- }
-
- public Object put( Object key, Object value )
- {
- throw new UnsupportedOperationException();
- }
-
- public void putAll( Map m )
- {
- Map.Entry entry;
- Iterator entries = m.entrySet().iterator();
- while( entries.hasNext() )
- {
- entry = (Map.Entry)entries.next();
- put( entry.getKey(), entry.getValue() );
- }
- }
-
- public Object remove( Object key )
- {
- Object k, value;
- Map.Entry entry;
- Iterator entries = entrySet().iterator();
-
- while( entries.hasNext() )
- {
- entry = (Map.Entry)entries.next();
- k = entry.getKey();
- if( key == null ? k == null : key.equals( k ) )
- {
- value = entry.getValue();
- entries.remove();
- return value;
- }
- }
-
- return null;
- }
-
- public int size()
- {
- return entrySet().size();
- }
-
- public String toString()
- {
- Map.Entry entry;
- String rep = "AbstractMap< ";
- Iterator entries = entrySet().iterator();
-
- while( entries.hasNext() )
- {
- entry = (Map.Entry)entries.next();
- rep += entry.getKey() + " -> " + entry.getValue() + ", ";
- }
-
- return rep.substring( 0, rep.length() - 2 ) + " >";
- }
-
- public Collection values()
- {
- if( this.valueCollection == null )
- {
- this.valueCollection =
- new AbstractCollection()
- {
- public int size()
- {
- return AbstractMap.this.size();
- }
-
- public Iterator iterator()
- {
- return new Iterator()
- {
- Iterator map_iterator = AbstractMap.this.entrySet().iterator();
-
- public boolean hasNext()
- {
- return map_iterator.hasNext();
- }
-
- public Object next()
- {
- return ((Map.Entry)map_iterator.next()).getValue();
- }
-
- public void remove()
- {
- map_iterator.remove();
- }
- };
- }
- };
- }
-
- return this.valueCollection;
- }
-
-
- private Collection valueCollection = null;
- private Set keySet = null;
-}
diff --git a/jode/jode/util/AbstractSequentialList.java b/jode/jode/util/AbstractSequentialList.java
deleted file mode 100644
index 03aa06e..0000000
--- a/jode/jode/util/AbstractSequentialList.java
+++ /dev/null
@@ -1,111 +0,0 @@
-// This interface is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// AbstractSequentialList.java -- List implementation for sequential access
-//
-// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-
-// TO DO:
-// ~ Lots of doc comments still missing.
-// ~ The class comment should include a description of what should be overridden
-// to provide what features, as should the listIterator comment.
-
-package jode.util;
-
-/**
- * Abstract superclass to make it easier to implement the List interface when
- * backed by a sequential-access store, such as a linked list.
- */
-public abstract class AbstractSequentialList extends AbstractList {
-
- /**
- * Returns a ListIterator over the list, starting from position index.
- * Subclasses must provide an implementation of this method.
- *
- * @exception IndexOutOfBoundsException if index < 0 || index > size()
- */
- public abstract ListIterator listIterator(int index);
-
- /**
- * Add an element to the list at a given index. This implementation obtains a
- * ListIterator positioned at the specified index, and then adds the element
- * using the ListIterator's add method.
- *
- * @param index the position to add the element
- * @param o the element to insert
- * @exception IndexOutOfBoundsException if index < 0 || index > size()
- * @exception UnsupportedOperationException if the iterator returned by
- * listIterator(index) does not support the add method.
- */
- public void add(int index, Object o) {
- ListIterator i = listIterator(index);
- i.add(o);
- }
-
- public boolean addAll(int index, Collection c) {
- boolean changed = false;
- Iterator ci = c.iterator();
- ListIterator i = listIterator(index);
- while (ci.hasNext()) {
- i.add(ci.next());
- changed = true;
- }
- return changed;
- }
-
- public Object get(int index) {
- ListIterator i = listIterator(index);
- if (!i.hasNext()) {
- throw new IndexOutOfBoundsException();
- }
- return i.next();
- }
-
- /**
- * Return an Iterator over this List. This implementation returns
- * listIterator().
- *
- * @return an Iterator over this List
- */
- public Iterator iterator() {
- return listIterator();
- }
-
- public Object remove(int index) {
- ListIterator i = listIterator(index);
- if (!i.hasNext()) {
- throw new IndexOutOfBoundsException();
- }
- Object removed = i.next();
- i.remove();
- return removed;
- }
-
- public Object set(int index, Object o) {
- ListIterator i = listIterator(index);
- if (!i.hasNext()) {
- throw new IndexOutOfBoundsException();
- }
- Object old = i.next();
- i.set(o);
- return old;
- }
-}
diff --git a/jode/jode/util/AbstractSet.java b/jode/jode/util/AbstractSet.java
deleted file mode 100644
index cc99633..0000000
--- a/jode/jode/util/AbstractSet.java
+++ /dev/null
@@ -1,78 +0,0 @@
-// This interface is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// AbstractSet.java -- Abstract implementation of most of Set
-//
-// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-
-package jode.util;
-
-/**
- * An abstract implementation of Set to make it easier to create your own
- * implementations. In order to create a Set, subclass AbstractSet and
- * implement the same methods that are required for AbstractCollection
- * (although these methods must of course meet the requirements that Set puts
- * on them - specifically, no element may be in the set more than once). This
- * class simply provides implementations of equals() and hashCode() to fulfil
- * the requirements placed on them by the Set interface.
- */
-public abstract class AbstractSet extends AbstractCollection implements Set {
-
- /**
- * Tests whether the given object is equal to this Set. This implementation
- * first checks whether this set is the given object, and returns
- * true if so. Otherwise, if o is a Set and is the same size as this one, it
- * returns the result of calling containsAll on the given Set. Otherwise, it
- * returns false.
- *
- * @param o the Object to be tested for equality with this Set
- * @return true if the given object is equal to this Set
- */
- public boolean equals(Object o) {
- if (o == this) {
- return true;
- } else if (o instanceof Set && ((Set)o).size() == size()) {
- return containsAll((Collection)o);
- } else {
- return false;
- }
- }
-
- /**
- * Returns a hash code for this Set. The hash code of a Set is the sum of the
- * hash codes of all its elements, except that the hash code of null is
- * defined to be zero. This implementation obtains an Iterator over the Set,
- * and sums the results.
- *
- * @return a hash code for this Set
- */
- public int hashCode() {
- int hash = 0;
- Iterator i = iterator();
- while (i.hasNext()) {
- try {
- hash += i.next().hashCode();
- } catch (NullPointerException e) {
- }
- }
- return hash;
- }
-}
diff --git a/jode/jode/util/ArrayList.java b/jode/jode/util/ArrayList.java
deleted file mode 100644
index 845d10d..0000000
--- a/jode/jode/util/ArrayList.java
+++ /dev/null
@@ -1,489 +0,0 @@
-// This class is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// ArrayList.java -- JDK1.2's answer to Vector; this is an array-backed
-// implementation of the List interface
-//
-// This is a JDK 1.2 compliant version of ArrayList.java
-//
-// Copyright (c) 1998 by Jon A. Zeppieri (jon@eease.com),
-// Free Software Foundation, Inc.
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-package jode.util;
-
-import java.lang.reflect.Array;
-import java.io.Serializable;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-/**
- * An array-backed implementation of the List interface. ArrayList
- * performs well on simple tasks: random access into a list, appending
- * to or removing from the end of a list, checking the size, &c.
- *
- * @author Jon A. Zeppieri
- * @version $Id$
- * @see java.util.AbstractList
- * @see java.util.List
- */
-public class ArrayList extends AbstractList
- implements List, Cloneable, Serializable
-{
- /** the default capacity for new ArrayLists */
- private static final int DEFAULT_CAPACITY = 16;
-
- /** the number of elements in this list */
- int size;
-
- /** where the data is stored */
- transient Object[] _arData;
-
- /**
- * Construct a new ArrayList with the supplied initial capacity.
- *
- * @param iCapacity
- */
- public ArrayList(int iCapacity)
- {
- _arData = new Object[iCapacity];
- }
-
-
- /**
- * Construct a new ArrayList with the default capcity
- */
- public ArrayList()
- {
- this(DEFAULT_CAPACITY);
- }
-
- /**
- * Construct a new ArrayList, and initialize it with the elements
- * in the supplied Collection; Sun specs say that the initial
- * capacity is 110% of the Collection's size.
- *
- * @param oCollection the collection whose elements will
- * initialize this list
- */
- public ArrayList(Collection oCollection)
- {
- this((int) (oCollection.size() * 1.1));
- addAll(oCollection);
- }
-
- /**
- * Guarantees that this list will have at least enough capacity to
- * hold iMinCapacity elements.
- *
- * @param iMinCapacity the minimum guaranteed capacity
- */
- public void ensureCapacity(int iMinCapacity)
- {
- Object[] arNewData;
- int iCapacity = _arData.length;
-
- if (iMinCapacity > iCapacity)
- {
- arNewData = new Object[Math.max((iCapacity * 2), iMinCapacity)];
- System.arraycopy(_arData, 0, arNewData, 0, iCapacity);
- _arData = arNewData;
- }
- }
-
- /**
- * Appends the supplied element to the end of this list.
- *
- * @param oElement the element to be appended to this list
- */
- public boolean add(Object oElement)
- {
- ensureCapacity(size + 1);
- _arData[size++] = oElement;
- modCount++;
- return true;
- }
-
- /**
- * Retrieves the element at the user-supplied index.
- *
- * @param iIndex the index of the element we are fetching
- * @throws IndexOutOfBoundsException (iIndex < 0) || (iIndex >= size())
- */
- public Object get(int iIndex)
- {
- if (iIndex >= size)
- throw new IndexOutOfBoundsException("ArrayList size=" +
- String.valueOf(size) + "; " +
- "index=" + String.valueOf(iIndex));
- return _arData[iIndex];
- }
-
- /**
- * Returns the number of elements in this list
- */
- public int size()
- {
- return size;
- }
-
- /**
- * Removes the element at the user-supplied index
- *
- * @param iIndex the index of the element to be removed
- * @return the removed Object
- * @throws IndexOutOfBoundsException (iIndex < 0) || (iIndex >= size())
- */
- public Object remove(int iIndex)
- {
- Object oResult;
-
- if (iIndex >= size)
- throw new IndexOutOfBoundsException("ArrayList size=" +
- String.valueOf(size) + "; " +
- "index=" + String.valueOf(iIndex));
-
- oResult = _arData[iIndex];
-
- if (iIndex != --size)
- System.arraycopy(_arData, (iIndex + 1), _arData, iIndex,
- (size - iIndex));
-
- modCount++;
- _arData[size] = null;
-
- return oResult;
- }
-
- /**
- * Removes all elements in the half-open interval [iFromIndex, iToIndex).
- *
- * @param iFromIndex the first index which will be removed
- * @param iToIndex one greater than the last index which will be
- * removed
- */
- public void removeRange(int iFromIndex, int iToIndex)
- {
- int iReduction;
- int i;
-
- if ((iFromIndex >= size) || (iToIndex >= size))
- {
- throw new IndexOutOfBoundsException("ArrayList size=" +
- String.valueOf(size) + "; " +
- "indices=" +
- String.valueOf(iFromIndex) + "," +
- String.valueOf(iToIndex));
- }
- else if (iFromIndex > iToIndex)
- {
- throw new IllegalArgumentException("fromIndex(" +
- String.valueOf(iFromIndex) +
- ") > toIndex(" +
- String.valueOf(iToIndex) + ")");
- }
- else if (iFromIndex != iToIndex)
- {
- iReduction = iToIndex - iFromIndex;
- System.arraycopy(_arData, (iFromIndex + iReduction), _arData,
- iFromIndex, (size - iFromIndex - iReduction));
- modCount++;
-
- for (i = (iFromIndex + iReduction); i < size; i++)
- _arData[i] = null;
-
- size -= iReduction;
- }
- }
-
- /**
- * Adds the supplied element at the specified index, shifting all
- * elements currently at that index or higher one to the right.
- *
- * @param iIndex the index at which the element is being added
- * @param oElement the element being added
- */
- public void add(int iIndex, Object oElement)
- {
- if (iIndex > size)
- throw new IndexOutOfBoundsException("ArrayList size=" +
- String.valueOf(size) + "; " +
- "index=" + String.valueOf(iIndex));
-
- ensureCapacity(size + 1);
- System.arraycopy(_arData, iIndex, _arData,
- (iIndex + 1), (size - iIndex));
- _arData[iIndex] = oElement;
- size++;
- modCount++;
- }
-
- /**
- * Add each element in the supplied Collection to this List.
- *
- * @param oCollection a Collection containing elements to be
- * added to this List
- */
- public boolean addAll(Collection oCollection)
- {
- Iterator itElements;
- int iLen = oCollection.size();
-
- if (iLen > 0)
- {
- ensureCapacity(size + iLen);
- modCount++;
-
- itElements = oCollection.iterator();
-
- while (itElements.hasNext())
- _arData[size++] = itElements.next();
-
- return true;
- }
- return false;
- }
-
- /**
- * Add all elements in the supplied collection, inserting them beginning
- * at the specified index.
- *
- * @param iIndex the index at which the elements will be inserted
- * @param oCollection the Collection containing the elements to be
- * inserted
- */
- public boolean addAll(int iIndex, Collection oCollection)
- {
- Iterator itElements;
- int iLen;
-
- if (iIndex > size)
- throw new IndexOutOfBoundsException("ArrayList size=" +
- String.valueOf(size) + "; " +
- "index=" + String.valueOf(iIndex));
-
- iLen = oCollection.size();
-
- if (iLen > 0)
- {
- ensureCapacity(size + iLen);
-
- System.arraycopy(_arData, iIndex, _arData,
- (iIndex + iLen), (size - iIndex));
- modCount++;
- size += iLen;
-
- itElements = oCollection.iterator();
- while (itElements.hasNext())
- _arData[iIndex++] = itElements.next();
-
- return true;
- }
- return false;
- }
-
- /**
- * Creates a shallow copy of this ArrayList
- */
- public Object clone()
- {
- ArrayList oClone;
-
- try
- {
- oClone = (ArrayList) super.clone();
- oClone._arData = _arData;
- oClone.size = size;
- }
- catch(CloneNotSupportedException e)
- {
- oClone = null;
- }
- return oClone;
- }
-
- /**
- * Returns true iff oElement is in this ArrayList.
- *
- * @param oElement the element whose inclusion in the List is being
- * tested
- */
- public boolean contains(Object oElement)
- {
- return (indexOf(oElement) != -1);
- }
-
- /**
- * Returns the lowest index at which oElement appears in this List, or
- * -1 if it does not appear.
- *
- * @param oElement the element whose inclusion in the List is being
- * tested
- */
- public int indexOf(Object oElement)
- {
- int i;
-
- for (i = 0; i < size; i++)
- {
- if (doesEqual(oElement, _arData[i]))
- return i;
- }
- return -1;
- }
-
- /**
- * Returns the highest index at which oElement appears in this List, or
- * -1 if it does not appear.
- *
- * @param oElement the element whose inclusion in the List is being
- * tested
- */
- public int lastIndexOf(Object oElement)
- {
- int i;
-
- for (i = size - 1; i >= 0; i--)
- {
- if (doesEqual(oElement, _arData[i]))
- return i;
- }
- return -1;
- }
-
- /**
- * Removes all elements from this List
- */
- public void clear()
- {
- int i;
-
- if (size > 0)
- {
- modCount++;
- size = 0;
-
- for (i = 0; i < size; i++)
- _arData[i] = null;
- }
- }
-
- /**
- * Sets the element at the specified index.
- *
- * @param iIndex the index at which the element is being set
- * @param oElement the element to be set
- * @return the element previously at the specified index, or null if
- * none was there
- */
- public Object set(int iIndex, Object oElement)
- {
- Object oResult;
-
- if (iIndex >= size)
- throw new IndexOutOfBoundsException("ArrayList size=" +
- String.valueOf(size) + "; " +
- "index=" + String.valueOf(iIndex));
- oResult = _arData[iIndex];
- modCount++;
- _arData[iIndex] = oElement;
-
- return oResult;
- }
-
- /**
- * Returns an Object Array containing all of the elements in this ArrayList
- */
- public Object[] toArray()
- {
- Object[] arObjects = new Object[size];
- System.arraycopy(_arData, 0, arObjects, 0, size);
- return arObjects;
- }
-
- /**
- * Returns an Array whse component type is the runtime component type of
- * the passes-in Array. The returned Array is populated with all of the
- * elements in this ArrayList. If the passed-in Array is not large enough
- * to store all of the elements in this List, a new Array will be created
- * and returned; if the passed-in Array is larger than the size
- * of this List, then size() + 1 index will be set to null.
- *
- * @param arObjects the passed-in Array
- */
- public Object[] toArray(Object[] arObjects)
- {
- Object[] arReturn = (arObjects.length >= size)
- ? arObjects
- : (Object[])
- Array.newInstance(arObjects.getClass().getComponentType(), size);
-
- System.arraycopy(_arData, 0, arReturn, 0, size);
-
- if (arReturn.length > size)
- arReturn[size] = null;
-
- return arReturn;
- }
-
- /**
- * Trims the capacity of tjis List to be equal to its size;
- * a memory saver.
- */
- public void trimToSize()
- {
- Object[] arNewData = new Object[size];
- System.arraycopy(_arData, 0, arNewData, 0, size);
- modCount++;
- _arData = arNewData;
- }
-
- private void writeObject(ObjectOutputStream oOut)
- throws IOException
- {
- int i;
-
- oOut.defaultWriteObject();
-
- oOut.writeInt(_arData.length);
- for (i = 0; i < _arData.length; i++)
- oOut.writeObject(_arData[i]);
- }
-
- private void readObject(ObjectInputStream oIn)
- throws IOException, ClassNotFoundException
- {
- int i;
- int iCapacity;
- oIn.defaultReadObject();
-
- iCapacity = oIn.readInt();
- _arData = new Object[iCapacity];
-
- for (i = 0; i < iCapacity; i++)
- _arData[i] = oIn.readObject();
- }
-
- private static final boolean doesEqual(Object oOne, Object oTwo)
- {
- return ((oOne == null) ? (oTwo == null) : oOne.equals(oTwo));
- }
-}
-
diff --git a/jode/jode/util/Arrays.java b/jode/jode/util/Arrays.java
deleted file mode 100644
index 1949ac9..0000000
--- a/jode/jode/util/Arrays.java
+++ /dev/null
@@ -1,1685 +0,0 @@
-// This interface is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// Arrays.java -- Utility class with methods to operate on arrays
-//
-// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-
-// TO DO:
-// ~ Fix the behaviour of sort and binarySearch as applied to float and double
-// arrays containing NaN values. See the JDC, bug ID 4143272.
-
-package jode.util;
-
-/**
- * This class contains various static utility methods performing operations on
- * arrays, and a method to provide a List "view" of an array to facilitate
- * using arrays with Collection-based APIs.
- */
-public class Arrays {
-
- /**
- * This class is non-instantiable.
- */
- private Arrays() {
- }
-
- /**
- * Perform a binary search of a byte array for a key. The array must be
- * sorted (as by the sort() method) - if it is not, the behaviour of this
- * method is undefined, and may be an infinite loop. If the array contains
- * the key more than once, any one of them may be found. Note: although the
- * specification allows for an infinite loop if the array is unsorted, it
- * will not happen in this implementation.
- *
- * @param a the array to search (must be sorted)
- * @param key the value to search for
- * @returns the index at which the key was found, or -n-1 if it was not
- * found, where n is the index of the first value higher than key or
- * a.length if there is no such value.
- */
- public static int binarySearch(byte[] a, byte key) {
- int low = 0;
- int hi = a.length - 1;
- int mid = 0;
- while (low <= hi) {
- mid = (low + hi) >> 1;
- final byte d = a[mid];
- if (d == key) {
- return mid;
- } else if (d > key) {
- hi = mid - 1;
- } else {
- low = ++mid; // This gets the insertion point right on the last loop
- }
- }
- return -mid - 1;
- }
-
- /**
- * Perform a binary search of a char array for a key. The array must be
- * sorted (as by the sort() method) - if it is not, the behaviour of this
- * method is undefined, and may be an infinite loop. If the array contains
- * the key more than once, any one of them may be found. Note: although the
- * specification allows for an infinite loop if the array is unsorted, it
- * will not happen in this implementation.
- *
- * @param a the array to search (must be sorted)
- * @param key the value to search for
- * @returns the index at which the key was found, or -n-1 if it was not
- * found, where n is the index of the first value higher than key or
- * a.length if there is no such value.
- */
- public static int binarySearch(char[] a, char key) {
- int low = 0;
- int hi = a.length - 1;
- int mid = 0;
- while (low <= hi) {
- mid = (low + hi) >> 1;
- final char d = a[mid];
- if (d == key) {
- return mid;
- } else if (d > key) {
- hi = mid - 1;
- } else {
- low = ++mid; // This gets the insertion point right on the last loop
- }
- }
- return -mid - 1;
- }
-
- /**
- * Perform a binary search of a double array for a key. The array must be
- * sorted (as by the sort() method) - if it is not, the behaviour of this
- * method is undefined, and may be an infinite loop. If the array contains
- * the key more than once, any one of them may be found. Note: although the
- * specification allows for an infinite loop if the array is unsorted, it
- * will not happen in this implementation.
- *
- * @param a the array to search (must be sorted)
- * @param key the value to search for
- * @returns the index at which the key was found, or -n-1 if it was not
- * found, where n is the index of the first value higher than key or
- * a.length if there is no such value.
- */
- public static int binarySearch(double[] a, double key) {
- int low = 0;
- int hi = a.length - 1;
- int mid = 0;
- while (low <= hi) {
- mid = (low + hi) >> 1;
- final double d = a[mid];
- if (d == key) {
- return mid;
- } else if (d > key) {
- hi = mid - 1;
- } else {
- low = ++mid; // This gets the insertion point right on the last loop
- }
- }
- return -mid - 1;
- }
-
- /**
- * Perform a binary search of a float array for a key. The array must be
- * sorted (as by the sort() method) - if it is not, the behaviour of this
- * method is undefined, and may be an infinite loop. If the array contains
- * the key more than once, any one of them may be found. Note: although the
- * specification allows for an infinite loop if the array is unsorted, it
- * will not happen in this implementation.
- *
- * @param a the array to search (must be sorted)
- * @param key the value to search for
- * @returns the index at which the key was found, or -n-1 if it was not
- * found, where n is the index of the first value higher than key or
- * a.length if there is no such value.
- */
- public static int binarySearch(float[] a, float key) {
- int low = 0;
- int hi = a.length - 1;
- int mid = 0;
- while (low <= hi) {
- mid = (low + hi) >> 1;
- final float d = a[mid];
- if (d == key) {
- return mid;
- } else if (d > key) {
- hi = mid - 1;
- } else {
- low = ++mid; // This gets the insertion point right on the last loop
- }
- }
- return -mid - 1;
- }
-
- /**
- * Perform a binary search of an int array for a key. The array must be
- * sorted (as by the sort() method) - if it is not, the behaviour of this
- * method is undefined, and may be an infinite loop. If the array contains
- * the key more than once, any one of them may be found. Note: although the
- * specification allows for an infinite loop if the array is unsorted, it
- * will not happen in this implementation.
- *
- * @param a the array to search (must be sorted)
- * @param key the value to search for
- * @returns the index at which the key was found, or -n-1 if it was not
- * found, where n is the index of the first value higher than key or
- * a.length if there is no such value.
- */
- public static int binarySearch(int[] a, int key) {
- int low = 0;
- int hi = a.length - 1;
- int mid = 0;
- while (low <= hi) {
- mid = (low + hi) >> 1;
- final int d = a[mid];
- if (d == key) {
- return mid;
- } else if (d > key) {
- hi = mid - 1;
- } else {
- low = ++mid; // This gets the insertion point right on the last loop
- }
- }
- return -mid - 1;
- }
-
- /**
- * Perform a binary search of a long array for a key. The array must be
- * sorted (as by the sort() method) - if it is not, the behaviour of this
- * method is undefined, and may be an infinite loop. If the array contains
- * the key more than once, any one of them may be found. Note: although the
- * specification allows for an infinite loop if the array is unsorted, it
- * will not happen in this implementation.
- *
- * @param a the array to search (must be sorted)
- * @param key the value to search for
- * @returns the index at which the key was found, or -n-1 if it was not
- * found, where n is the index of the first value higher than key or
- * a.length if there is no such value.
- */
- public static int binarySearch(long[] a, long key) {
- int low = 0;
- int hi = a.length - 1;
- int mid = 0;
- while (low <= hi) {
- mid = (low + hi) >> 1;
- final long d = a[mid];
- if (d == key) {
- return mid;
- } else if (d > key) {
- hi = mid - 1;
- } else {
- low = ++mid; // This gets the insertion point right on the last loop
- }
- }
- return -mid - 1;
- }
-
- /**
- * Perform a binary search of a short array for a key. The array must be
- * sorted (as by the sort() method) - if it is not, the behaviour of this
- * method is undefined, and may be an infinite loop. If the array contains
- * the key more than once, any one of them may be found. Note: although the
- * specification allows for an infinite loop if the array is unsorted, it
- * will not happen in this implementation.
- *
- * @param a the array to search (must be sorted)
- * @param key the value to search for
- * @returns the index at which the key was found, or -n-1 if it was not
- * found, where n is the index of the first value higher than key or
- * a.length if there is no such value.
- */
- public static int binarySearch(short[] a, short key) {
- int low = 0;
- int hi = a.length - 1;
- int mid = 0;
- while (low <= hi) {
- mid = (low + hi) >> 1;
- final short d = a[mid];
- if (d == key) {
- return mid;
- } else if (d > key) {
- hi = mid - 1;
- } else {
- low = ++mid; // This gets the insertion point right on the last loop
- }
- }
- return -mid - 1;
- }
-
- /**
- * Compare two objects with or without a Comparator. If c is null, uses the
- * natural ordering. Slightly slower than doing it inline if the JVM isn't
- * clever, but worth it for removing a duplicate of the sort and search code.
- * Note: This same code is used in Collections
- */
- private static int compare(Object o1, Object o2, Comparator c) {
- if (c == null) {
- return ((Comparable)o1).compareTo(o2);
- } else {
- return c.compare(o1, o2);
- }
- }
-
- /**
- * This method does the work for the Object binary search methods. If the
- * specified comparator is null, uses the natural ordering.
- */
- private static int objectSearch(Object[] a, Object key, final Comparator c) {
- int low = 0;
- int hi = a.length - 1;
- int mid = 0;
- while (low <= hi) {
- mid = (low + hi) >> 1;
- final int d = compare(key, a[mid], c);
- if (d == 0) {
- return mid;
- } else if (d < 0) {
- hi = mid - 1;
- } else {
- low = ++mid; // This gets the insertion point right on the last loop
- }
- }
- return -mid - 1;
- }
-
- /**
- * Perform a binary search of an Object array for a key, using the natural
- * ordering of the elements. The array must be sorted (as by the sort()
- * method) - if it is not, the behaviour of this method is undefined, and may
- * be an infinite loop. Further, the key must be comparable with every item
- * in the array. If the array contains the key more than once, any one of
- * them may be found. Note: although the specification allows for an infinite
- * loop if the array is unsorted, it will not happen in this (JCL)
- * implementation.
- *
- * @param a the array to search (must be sorted)
- * @param key the value to search for
- * @returns the index at which the key was found, or -n-1 if it was not
- * found, where n is the index of the first value higher than key or
- * a.length if there is no such value.
- * @exception ClassCastException if key could not be compared with one of the
- * elements of a
- * @exception NullPointerException if a null element has compareTo called
- */
- public static int binarySearch(Object[] a, Object key) {
- return objectSearch(a, key, null);
- }
-
- /**
- * Perform a binary search of an Object array for a key, using a supplied
- * Comparator. The array must be sorted (as by the sort() method with the
- * same Comparator) - if it is not, the behaviour of this method is
- * undefined, and may be an infinite loop. Further, the key must be
- * comparable with every item in the array. If the array contains the key
- * more than once, any one of them may be found. Note: although the
- * specification allows for an infinite loop if the array is unsorted, it
- * will not happen in this (JCL) implementation.
- *
- * @param a the array to search (must be sorted)
- * @param key the value to search for
- * @param c the comparator by which the array is sorted
- * @returns the index at which the key was found, or -n-1 if it was not
- * found, where n is the index of the first value higher than key or
- * a.length if there is no such value.
- * @exception ClassCastException if key could not be compared with one of the
- * elements of a
- */
- public static int binarySearch(Object[] a, Object key, Comparator c) {
- if (c == null) {
- throw new NullPointerException();
- }
- return objectSearch(a, key, c);
- }
-
- /**
- * Compare two byte arrays for equality.
- *
- * @param a1 the first array to compare
- * @param a2 the second array to compare
- * @returns true if a1 and a2 are both null, or if a2 is of the same length
- * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i]
- */
- public static boolean equals(byte[] a1, byte[] a2) {
-
- // Quick test which saves comparing elements of the same array, and also
- // catches the case that both are null.
- if (a1 == a2) {
- return true;
- }
- try {
-
- // If they're the same length, test each element
- if (a1.length == a2.length) {
- for (int i = 0; i < a1.length; i++) {
- if (a1[i] != a2[i]) {
- return false;
- }
- }
- return true;
- }
-
- // If a1 == null or a2 == null but not both then we will get a NullPointer
- } catch (NullPointerException e) {
- }
-
- return false;
- }
-
- /**
- * Compare two char arrays for equality.
- *
- * @param a1 the first array to compare
- * @param a2 the second array to compare
- * @returns true if a1 and a2 are both null, or if a2 is of the same length
- * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i]
- */
- public static boolean equals(char[] a1, char[] a2) {
-
- // Quick test which saves comparing elements of the same array, and also
- // catches the case that both are null.
- if (a1 == a2) {
- return true;
- }
- try {
-
- // If they're the same length, test each element
- if (a1.length == a2.length) {
- for (int i = 0; i < a1.length; i++) {
- if (a1[i] != a2[i]) {
- return false;
- }
- }
- return true;
- }
-
- // If a1 == null or a2 == null but not both then we will get a NullPointer
- } catch (NullPointerException e) {
- }
-
- return false;
- }
-
- /**
- * Compare two double arrays for equality.
- *
- * @param a1 the first array to compare
- * @param a2 the second array to compare
- * @returns true if a1 and a2 are both null, or if a2 is of the same length
- * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i]
- */
- public static boolean equals(double[] a1, double[] a2) {
-
- // Quick test which saves comparing elements of the same array, and also
- // catches the case that both are null.
- if (a1 == a2) {
- return true;
- }
- try {
-
- // If they're the same length, test each element
- if (a1.length == a2.length) {
- for (int i = 0; i < a1.length; i++) {
- if (a1[i] != a2[i]) {
- return false;
- }
- }
- return true;
- }
-
- // If a1 == null or a2 == null but not both then we will get a NullPointer
- } catch (NullPointerException e) {
- }
-
- return false;
- }
-
- /**
- * Compare two float arrays for equality.
- *
- * @param a1 the first array to compare
- * @param a2 the second array to compare
- * @returns true if a1 and a2 are both null, or if a2 is of the same length
- * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i]
- */
- public static boolean equals(float[] a1, float[] a2) {
-
- // Quick test which saves comparing elements of the same array, and also
- // catches the case that both are null.
- if (a1 == a2) {
- return true;
- }
- try {
-
- // If they're the same length, test each element
- if (a1.length == a2.length) {
- for (int i = 0; i < a1.length; i++) {
- if (a1[i] != a2[i]) {
- return false;
- }
- }
- return true;
- }
-
- // If a1 == null or a2 == null but not both then we will get a NullPointer
- } catch (NullPointerException e) {
- }
-
- return false;
- }
-
- /**
- * Compare two long arrays for equality.
- *
- * @param a1 the first array to compare
- * @param a2 the second array to compare
- * @returns true if a1 and a2 are both null, or if a2 is of the same length
- * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i]
- */
- public static boolean equals(long[] a1, long[] a2) {
-
- // Quick test which saves comparing elements of the same array, and also
- // catches the case that both are null.
- if (a1 == a2) {
- return true;
- }
- try {
-
- // If they're the same length, test each element
- if (a1.length == a2.length) {
- for (int i = 0; i < a1.length; i++) {
- if (a1[i] != a2[i]) {
- return false;
- }
- }
- return true;
- }
-
- // If a1 == null or a2 == null but not both then we will get a NullPointer
- } catch (NullPointerException e) {
- }
-
- return false;
- }
-
- /**
- * Compare two short arrays for equality.
- *
- * @param a1 the first array to compare
- * @param a2 the second array to compare
- * @returns true if a1 and a2 are both null, or if a2 is of the same length
- * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i]
- */
- public static boolean equals(short[] a1, short[] a2) {
-
- // Quick test which saves comparing elements of the same array, and also
- // catches the case that both are null.
- if (a1 == a2) {
- return true;
- }
- try {
-
- // If they're the same length, test each element
- if (a1.length == a2.length) {
- for (int i = 0; i < a1.length; i++) {
- if (a1[i] != a2[i]) {
- return false;
- }
- }
- return true;
- }
-
- // If a1 == null or a2 == null but not both then we will get a NullPointer
- } catch (NullPointerException e) {
- }
-
- return false;
- }
-
- /**
- * Compare two boolean arrays for equality.
- *
- * @param a1 the first array to compare
- * @param a2 the second array to compare
- * @returns true if a1 and a2 are both null, or if a2 is of the same length
- * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i]
- */
- public static boolean equals(boolean[] a1, boolean[] a2) {
-
- // Quick test which saves comparing elements of the same array, and also
- // catches the case that both are null.
- if (a1 == a2) {
- return true;
- }
- try {
-
- // If they're the same length, test each element
- if (a1.length == a2.length) {
- for (int i = 0; i < a1.length; i++) {
- if (a1[i] != a2[i]) {
- return false;
- }
- }
- return true;
- }
-
- // If a1 == null or a2 == null but not both then we will get a NullPointer
- } catch (NullPointerException e) {
- }
-
- return false;
- }
-
- /**
- * Compare two int arrays for equality.
- *
- * @param a1 the first array to compare
- * @param a2 the second array to compare
- * @returns true if a1 and a2 are both null, or if a2 is of the same length
- * as a1, and for each 0 <= i < a1.length, a1[i] == a2[i]
- */
- public static boolean equals(int[] a1, int[] a2) {
-
- // Quick test which saves comparing elements of the same array, and also
- // catches the case that both are null.
- if (a1 == a2) {
- return true;
- }
- try {
-
- // If they're the same length, test each element
- if (a1.length == a2.length) {
- for (int i = 0; i < a1.length; i++) {
- if (a1[i] != a2[i]) {
- return false;
- }
- }
- return true;
- }
-
- // If a1 == null or a2 == null but not both then we will get a NullPointer
- } catch (NullPointerException e) {
- }
-
- return false;
- }
-
- /**
- * Compare two Object arrays for equality.
- *
- * @param a1 the first array to compare
- * @param a2 the second array to compare
- * @returns true if a1 and a2 are both null, or if a1 is of the same length
- * as a2, and for each 0 <= i < a.length, a1[i] == null ? a2[i] == null :
- * a1[i].equals(a2[i]).
- */
- public static boolean equals(Object[] a1, Object[] a2) {
-
- // Quick test which saves comparing elements of the same array, and also
- // catches the case that both are null.
- if (a1 == a2) {
- return true;
- }
- try {
-
- // If they're the same length, test each element
- if (a1.length == a2.length) {
- for (int i = 0; i < a1.length; i++) {
- if (!(a1[i] == null ? a2[i] == null : a1[i].equals(a2[i]))) {
- return false;
- }
- }
- return true;
- }
-
- // If a1 == null or a2 == null but not both then we will get a NullPointer
- } catch (NullPointerException e) {
- }
-
- return false;
- }
-
- /**
- * Fill an array with a boolean value.
- *
- * @param a the array to fill
- * @param val the value to fill it with
- */
- public static void fill(boolean[] a, boolean val) {
- // This implementation is slightly inefficient timewise, but the extra
- // effort over inlining it is O(1) and small, and I refuse to repeat code
- // if it can be helped.
- fill(a, 0, a.length, val);
- }
-
- /**
- * Fill a range of an array with a boolean value.
- *
- * @param a the array to fill
- * @param fromIndex the index to fill from, inclusive
- * @param toIndex the index to fill to, exclusive
- * @param val the value to fill with
- */
- public static void fill(boolean[] a, int fromIndex, int toIndex,
- boolean val) {
- for (int i = fromIndex; i < toIndex; i++) {
- a[i] = val;
- }
- }
-
- /**
- * Fill an array with a byte value.
- *
- * @param a the array to fill
- * @param val the value to fill it with
- */
- public static void fill(byte[] a, byte val) {
- // This implementation is slightly inefficient timewise, but the extra
- // effort over inlining it is O(1) and small, and I refuse to repeat code
- // if it can be helped.
- fill(a, 0, a.length, val);
- }
-
- /**
- * Fill a range of an array with a byte value.
- *
- * @param a the array to fill
- * @param fromIndex the index to fill from, inclusive
- * @param toIndex the index to fill to, exclusive
- * @param val the value to fill with
- */
- public static void fill(byte[] a, int fromIndex, int toIndex, byte val) {
- for (int i = fromIndex; i < toIndex; i++) {
- a[i] = val;
- }
- }
-
- /**
- * Fill an array with a char value.
- *
- * @param a the array to fill
- * @param val the value to fill it with
- */
- public static void fill(char[] a, char val) {
- // This implementation is slightly inefficient timewise, but the extra
- // effort over inlining it is O(1) and small, and I refuse to repeat code
- // if it can be helped.
- fill(a, 0, a.length, val);
- }
-
- /**
- * Fill a range of an array with a char value.
- *
- * @param a the array to fill
- * @param fromIndex the index to fill from, inclusive
- * @param toIndex the index to fill to, exclusive
- * @param val the value to fill with
- */
- public static void fill(char[] a, int fromIndex, int toIndex, char val) {
- for (int i = fromIndex; i < toIndex; i++) {
- a[i] = val;
- }
- }
-
- /**
- * Fill an array with a double value.
- *
- * @param a the array to fill
- * @param val the value to fill it with
- */
- public static void fill(double[] a, double val) {
- // This implementation is slightly inefficient timewise, but the extra
- // effort over inlining it is O(1) and small, and I refuse to repeat code
- // if it can be helped.
- fill(a, 0, a.length, val);
- }
-
- /**
- * Fill a range of an array with a double value.
- *
- * @param a the array to fill
- * @param fromIndex the index to fill from, inclusive
- * @param toIndex the index to fill to, exclusive
- * @param val the value to fill with
- */
- public static void fill(double[] a, int fromIndex, int toIndex, double val) {
- for (int i = fromIndex; i < toIndex; i++) {
- a[i] = val;
- }
- }
-
- /**
- * Fill an array with a float value.
- *
- * @param a the array to fill
- * @param val the value to fill it with
- */
- public static void fill(float[] a, float val) {
- // This implementation is slightly inefficient timewise, but the extra
- // effort over inlining it is O(1) and small, and I refuse to repeat code
- // if it can be helped.
- fill(a, 0, a.length, val);
- }
-
- /**
- * Fill a range of an array with a float value.
- *
- * @param a the array to fill
- * @param fromIndex the index to fill from, inclusive
- * @param toIndex the index to fill to, exclusive
- * @param val the value to fill with
- */
- public static void fill(float[] a, int fromIndex, int toIndex, float val) {
- for (int i = fromIndex; i < toIndex; i++) {
- a[i] = val;
- }
- }
-
- /**
- * Fill an array with an int value.
- *
- * @param a the array to fill
- * @param val the value to fill it with
- */
- public static void fill(int[] a, int val) {
- // This implementation is slightly inefficient timewise, but the extra
- // effort over inlining it is O(1) and small, and I refuse to repeat code
- // if it can be helped.
- fill(a, 0, a.length, val);
- }
-
- /**
- * Fill a range of an array with an int value.
- *
- * @param a the array to fill
- * @param fromIndex the index to fill from, inclusive
- * @param toIndex the index to fill to, exclusive
- * @param val the value to fill with
- */
- public static void fill(int[] a, int fromIndex, int toIndex, int val) {
- for (int i = fromIndex; i < toIndex; i++) {
- a[i] = val;
- }
- }
-
- /**
- * Fill an array with a long value.
- *
- * @param a the array to fill
- * @param val the value to fill it with
- */
- public static void fill(long[] a, long val) {
- // This implementation is slightly inefficient timewise, but the extra
- // effort over inlining it is O(1) and small, and I refuse to repeat code
- // if it can be helped.
- fill(a, 0, a.length, val);
- }
-
- /**
- * Fill a range of an array with a long value.
- *
- * @param a the array to fill
- * @param fromIndex the index to fill from, inclusive
- * @param toIndex the index to fill to, exclusive
- * @param val the value to fill with
- */
- public static void fill(long[] a, int fromIndex, int toIndex, long val) {
- for (int i = fromIndex; i < toIndex; i++) {
- a[i] = val;
- }
- }
-
- /**
- * Fill an array with a short value.
- *
- * @param a the array to fill
- * @param val the value to fill it with
- */
- public static void fill(short[] a, short val) {
- // This implementation is slightly inefficient timewise, but the extra
- // effort over inlining it is O(1) and small, and I refuse to repeat code
- // if it can be helped.
- fill(a, 0, a.length, val);
- }
-
- /**
- * Fill a range of an array with a short value.
- *
- * @param a the array to fill
- * @param fromIndex the index to fill from, inclusive
- * @param toIndex the index to fill to, exclusive
- * @param val the value to fill with
- */
- public static void fill(short[] a, int fromIndex, int toIndex, short val) {
- for (int i = fromIndex; i < toIndex; i++) {
- a[i] = val;
- }
- }
-
- /**
- * Fill an array with an Object value.
- *
- * @param a the array to fill
- * @param val the value to fill it with
- * @exception ClassCastException if val is not an instance of the element
- * type of a.
- */
- public static void fill(Object[] a, Object val) {
- // This implementation is slightly inefficient timewise, but the extra
- // effort over inlining it is O(1) and small, and I refuse to repeat code
- // if it can be helped.
- fill(a, 0, a.length, val);
- }
-
- /**
- * Fill a range of an array with an Object value.
- *
- * @param a the array to fill
- * @param fromIndex the index to fill from, inclusive
- * @param toIndex the index to fill to, exclusive
- * @param val the value to fill with
- * @exception ClassCastException if val is not an instance of the element
- * type of a.
- */
- public static void fill(Object[] a, int fromIndex, int toIndex, Object val) {
- for (int i = fromIndex; i < toIndex; i++) {
- a[i] = val;
- }
- }
-
- // Thanks to Paul Fisher for finding this quicksort algorithm
- // as specified by Sun and porting it to Java.
-
- /**
- * Sort a byte array into ascending order. The sort algorithm is an optimised
- * quicksort, as described in Jon L. Bentley and M. Douglas McIlroy's
- * "Engineering a Sort Function", Software-Practice and Experience, Vol.
- * 23(11) P. 1249-1265 (November 1993). This algorithm gives nlog(n)
- * performance on many arrays that would take quadratic time with a standard
- * quicksort.
- *
- * @param a the array to sort
- */
- public static void sort(byte[] a) {
- qsort(a, 0, a.length);
- }
-
- private static short cmp(byte i, byte j) {
- return (short)(i-j);
- }
-
- private static int med3(int a, int b, int c, byte[] d) {
- return cmp(d[a], d[b]) < 0 ?
- (cmp(d[b], d[c]) < 0 ? b : cmp(d[a], d[c]) < 0 ? c : a)
- : (cmp(d[b], d[c]) > 0 ? b : cmp(d[a], d[c]) > 0 ? c : a);
- }
-
- private static void swap(int i, int j, byte[] a) {
- byte c = a[i];
- a[i] = a[j];
- a[j] = c;
- }
-
- private static void qsort(byte[] a, int start, int n) {
- // use an insertion sort on small arrays
- if (n < 7) {
- for (int i = start + 1; i < start + n; i++)
- for (int j = i; j > 0 && cmp(a[j-1], a[j]) > 0; j--)
- swap(j, j-1, a);
- return;
- }
-
- int pm = n/2; // small arrays, middle element
- if (n > 7) {
- int pl = start;
- int pn = start + n-1;
-
- if (n > 40) { // big arrays, pseudomedian of 9
- int s = n/8;
- pl = med3(pl, pl+s, pl+2*s, a);
- pm = med3(pm-s, pm, pm+s, a);
- pn = med3(pn-2*s, pn-s, pn, a);
- }
- pm = med3(pl, pm, pn, a); // mid-size, med of 3
- }
-
- int pa, pb, pc, pd, pv;
- short r;
-
- pv = start; swap(pv, pm, a);
- pa = pb = start;
- pc = pd = start + n-1;
-
- for (;;) {
- while (pb <= pc && (r = cmp(a[pb], a[pv])) <= 0) {
- if (r == 0) { swap(pa, pb, a); pa++; }
- pb++;
- }
- while (pc >= pb && (r = cmp(a[pc], a[pv])) >= 0) {
- if (r == 0) { swap(pc, pd, a); pd--; }
- pc--;
- }
- if (pb > pc) break;
- swap(pb, pc, a);
- pb++;
- pc--;
- }
- int pn = start + n;
- int s;
- s = Math.min(pa-start, pb-pa); vecswap(start, pb-s, s, a);
- s = Math.min(pd-pc, pn-pd-1); vecswap(pb, pn-s, s, a);
- if ((s = pb-pa) > 1) qsort(a, start, s);
- if ((s = pd-pc) > 1) qsort(a, pn-s, s);
- }
-
- private static void vecswap(int i, int j, int n, byte[] a) {
- for (; n > 0; i++, j++, n--)
- swap(i, j, a);
- }
-
- /**
- * Sort a char array into ascending order. The sort algorithm is an optimised
- * quicksort, as described in Jon L. Bentley and M. Douglas McIlroy's
- * "Engineering a Sort Function", Software-Practice and Experience, Vol.
- * 23(11) P. 1249-1265 (November 1993). This algorithm gives nlog(n)
- * performance on many arrays that would take quadratic time with a standard
- * quicksort.
- *
- * @param a the array to sort
- */
- public static void sort(char[] a) {
- qsort(a, 0, a.length);
- }
-
- private static int cmp(char i, char j) {
- return i-j;
- }
-
- private static int med3(int a, int b, int c, char[] d) {
- return cmp(d[a], d[b]) < 0 ?
- (cmp(d[b], d[c]) < 0 ? b : cmp(d[a], d[c]) < 0 ? c : a)
- : (cmp(d[b], d[c]) > 0 ? b : cmp(d[a], d[c]) > 0 ? c : a);
- }
-
- private static void swap(int i, int j, char[] a) {
- char c = a[i];
- a[i] = a[j];
- a[j] = c;
- }
-
- private static void qsort(char[] a, int start, int n) {
- // use an insertion sort on small arrays
- if (n < 7) {
- for (int i = start + 1; i < start + n; i++)
- for (int j = i; j > 0 && cmp(a[j-1], a[j]) > 0; j--)
- swap(j, j-1, a);
- return;
- }
-
- int pm = n/2; // small arrays, middle element
- if (n > 7) {
- int pl = start;
- int pn = start + n-1;
-
- if (n > 40) { // big arrays, pseudomedian of 9
- int s = n/8;
- pl = med3(pl, pl+s, pl+2*s, a);
- pm = med3(pm-s, pm, pm+s, a);
- pn = med3(pn-2*s, pn-s, pn, a);
- }
- pm = med3(pl, pm, pn, a); // mid-size, med of 3
- }
-
- int pa, pb, pc, pd, pv;
- int r;
-
- pv = start; swap(pv, pm, a);
- pa = pb = start;
- pc = pd = start + n-1;
-
- for (;;) {
- while (pb <= pc && (r = cmp(a[pb], a[pv])) <= 0) {
- if (r == 0) { swap(pa, pb, a); pa++; }
- pb++;
- }
- while (pc >= pb && (r = cmp(a[pc], a[pv])) >= 0) {
- if (r == 0) { swap(pc, pd, a); pd--; }
- pc--;
- }
- if (pb > pc) break;
- swap(pb, pc, a);
- pb++;
- pc--;
- }
- int pn = start + n;
- int s;
- s = Math.min(pa-start, pb-pa); vecswap(start, pb-s, s, a);
- s = Math.min(pd-pc, pn-pd-1); vecswap(pb, pn-s, s, a);
- if ((s = pb-pa) > 1) qsort(a, start, s);
- if ((s = pd-pc) > 1) qsort(a, pn-s, s);
- }
-
- private static void vecswap(int i, int j, int n, char[] a) {
- for (; n > 0; i++, j++, n--)
- swap(i, j, a);
- }
-
- /**
- * Sort a double array into ascending order. The sort algorithm is an
- * optimised quicksort, as described in Jon L. Bentley and M. Douglas
- * McIlroy's "Engineering a Sort Function", Software-Practice and Experience,
- * Vol. 23(11) P. 1249-1265 (November 1993). This algorithm gives nlog(n)
- * performance on many arrays that would take quadratic time with a standard
- * quicksort. Note that this implementation, like Sun's, has undefined
- * behaviour if the array contains any NaN values.
- *
- * @param a the array to sort
- */
- public static void sort(double[] a) {
- qsort(a, 0, a.length);
- }
-
- private static double cmp(double i, double j) {
- return i-j;
- }
-
- private static int med3(int a, int b, int c, double[] d) {
- return cmp(d[a], d[b]) < 0 ?
- (cmp(d[b], d[c]) < 0 ? b : cmp(d[a], d[c]) < 0 ? c : a)
- : (cmp(d[b], d[c]) > 0 ? b : cmp(d[a], d[c]) > 0 ? c : a);
- }
-
- private static void swap(int i, int j, double[] a) {
- double c = a[i];
- a[i] = a[j];
- a[j] = c;
- }
-
- private static void qsort(double[] a, int start, int n) {
- // use an insertion sort on small arrays
- if (n < 7) {
- for (int i = start + 1; i < start + n; i++)
- for (int j = i; j > 0 && cmp(a[j-1], a[j]) > 0; j--)
- swap(j, j-1, a);
- return;
- }
-
- int pm = n/2; // small arrays, middle element
- if (n > 7) {
- int pl = start;
- int pn = start + n-1;
-
- if (n > 40) { // big arrays, pseudomedian of 9
- int s = n/8;
- pl = med3(pl, pl+s, pl+2*s, a);
- pm = med3(pm-s, pm, pm+s, a);
- pn = med3(pn-2*s, pn-s, pn, a);
- }
- pm = med3(pl, pm, pn, a); // mid-size, med of 3
- }
-
- int pa, pb, pc, pd, pv;
- double r;
-
- pv = start; swap(pv, pm, a);
- pa = pb = start;
- pc = pd = start + n-1;
-
- for (;;) {
- while (pb <= pc && (r = cmp(a[pb], a[pv])) <= 0) {
- if (r == 0) { swap(pa, pb, a); pa++; }
- pb++;
- }
- while (pc >= pb && (r = cmp(a[pc], a[pv])) >= 0) {
- if (r == 0) { swap(pc, pd, a); pd--; }
- pc--;
- }
- if (pb > pc) break;
- swap(pb, pc, a);
- pb++;
- pc--;
- }
- int pn = start + n;
- int s;
- s = Math.min(pa-start, pb-pa); vecswap(start, pb-s, s, a);
- s = Math.min(pd-pc, pn-pd-1); vecswap(pb, pn-s, s, a);
- if ((s = pb-pa) > 1) qsort(a, start, s);
- if ((s = pd-pc) > 1) qsort(a, pn-s, s);
- }
-
- private static void vecswap(int i, int j, int n, double[] a) {
- for (; n > 0; i++, j++, n--)
- swap(i, j, a);
- }
-
- /**
- * Sort a float array into ascending order. The sort algorithm is an
- * optimised quicksort, as described in Jon L. Bentley and M. Douglas
- * McIlroy's "Engineering a Sort Function", Software-Practice and Experience,
- * Vol. 23(11) P. 1249-1265 (November 1993). This algorithm gives nlog(n)
- * performance on many arrays that would take quadratic time with a standard
- * quicksort. Note that this implementation, like Sun's, has undefined
- * behaviour if the array contains any NaN values.
- *
- * @param a the array to sort
- */
- public static void sort(float[] a) {
- qsort(a, 0, a.length);
- }
-
- private static float cmp(float i, float j) {
- return i-j;
- }
-
- private static int med3(int a, int b, int c, float[] d) {
- return cmp(d[a], d[b]) < 0 ?
- (cmp(d[b], d[c]) < 0 ? b : cmp(d[a], d[c]) < 0 ? c : a)
- : (cmp(d[b], d[c]) > 0 ? b : cmp(d[a], d[c]) > 0 ? c : a);
- }
-
- private static void swap(int i, int j, float[] a) {
- float c = a[i];
- a[i] = a[j];
- a[j] = c;
- }
-
- private static void qsort(float[] a, int start, int n) {
- // use an insertion sort on small arrays
- if (n < 7) {
- for (int i = start + 1; i < start + n; i++)
- for (int j = i; j > 0 && cmp(a[j-1], a[j]) > 0; j--)
- swap(j, j-1, a);
- return;
- }
-
- int pm = n/2; // small arrays, middle element
- if (n > 7) {
- int pl = start;
- int pn = start + n-1;
-
- if (n > 40) { // big arrays, pseudomedian of 9
- int s = n/8;
- pl = med3(pl, pl+s, pl+2*s, a);
- pm = med3(pm-s, pm, pm+s, a);
- pn = med3(pn-2*s, pn-s, pn, a);
- }
- pm = med3(pl, pm, pn, a); // mid-size, med of 3
- }
-
- int pa, pb, pc, pd, pv;
- float r;
-
- pv = start; swap(pv, pm, a);
- pa = pb = start;
- pc = pd = start + n-1;
-
- for (;;) {
- while (pb <= pc && (r = cmp(a[pb], a[pv])) <= 0) {
- if (r == 0) { swap(pa, pb, a); pa++; }
- pb++;
- }
- while (pc >= pb && (r = cmp(a[pc], a[pv])) >= 0) {
- if (r == 0) { swap(pc, pd, a); pd--; }
- pc--;
- }
- if (pb > pc) break;
- swap(pb, pc, a);
- pb++;
- pc--;
- }
- int pn = start + n;
- int s;
- s = Math.min(pa-start, pb-pa); vecswap(start, pb-s, s, a);
- s = Math.min(pd-pc, pn-pd-1); vecswap(pb, pn-s, s, a);
- if ((s = pb-pa) > 1) qsort(a, start, s);
- if ((s = pd-pc) > 1) qsort(a, pn-s, s);
- }
-
- private static void vecswap(int i, int j, int n, float[] a) {
- for (; n > 0; i++, j++, n--)
- swap(i, j, a);
- }
-
- /**
- * Sort an int array into ascending order. The sort algorithm is an optimised
- * quicksort, as described in Jon L. Bentley and M. Douglas McIlroy's
- * "Engineering a Sort Function", Software-Practice and Experience, Vol.
- * 23(11) P. 1249-1265 (November 1993). This algorithm gives nlog(n)
- * performance on many arrays that would take quadratic time with a standard
- * quicksort.
- *
- * @param a the array to sort
- */
- public static void sort(int[] a) {
- qsort(a, 0, a.length);
- }
-
- private static long cmp(int i, int j) {
- return (long)i-(long)j;
- }
-
- private static int med3(int a, int b, int c, int[] d) {
- return cmp(d[a], d[b]) < 0 ?
- (cmp(d[b], d[c]) < 0 ? b : cmp(d[a], d[c]) < 0 ? c : a)
- : (cmp(d[b], d[c]) > 0 ? b : cmp(d[a], d[c]) > 0 ? c : a);
- }
-
- private static void swap(int i, int j, int[] a) {
- int c = a[i];
- a[i] = a[j];
- a[j] = c;
- }
-
- private static void qsort(int[] a, int start, int n) {
- // use an insertion sort on small arrays
- if (n < 7) {
- for (int i = start + 1; i < start + n; i++)
- for (int j = i; j > 0 && cmp(a[j-1], a[j]) > 0; j--)
- swap(j, j-1, a);
- return;
- }
-
- int pm = n/2; // small arrays, middle element
- if (n > 7) {
- int pl = start;
- int pn = start + n-1;
-
- if (n > 40) { // big arrays, pseudomedian of 9
- int s = n/8;
- pl = med3(pl, pl+s, pl+2*s, a);
- pm = med3(pm-s, pm, pm+s, a);
- pn = med3(pn-2*s, pn-s, pn, a);
- }
- pm = med3(pl, pm, pn, a); // mid-size, med of 3
- }
-
- int pa, pb, pc, pd, pv;
- long r;
-
- pv = start; swap(pv, pm, a);
- pa = pb = start;
- pc = pd = start + n-1;
-
- for (;;) {
- while (pb <= pc && (r = cmp(a[pb], a[pv])) <= 0) {
- if (r == 0) { swap(pa, pb, a); pa++; }
- pb++;
- }
- while (pc >= pb && (r = cmp(a[pc], a[pv])) >= 0) {
- if (r == 0) { swap(pc, pd, a); pd--; }
- pc--;
- }
- if (pb > pc) break;
- swap(pb, pc, a);
- pb++;
- pc--;
- }
- int pn = start + n;
- int s;
- s = Math.min(pa-start, pb-pa); vecswap(start, pb-s, s, a);
- s = Math.min(pd-pc, pn-pd-1); vecswap(pb, pn-s, s, a);
- if ((s = pb-pa) > 1) qsort(a, start, s);
- if ((s = pd-pc) > 1) qsort(a, pn-s, s);
- }
-
- private static void vecswap(int i, int j, int n, int[] a) {
- for (; n > 0; i++, j++, n--)
- swap(i, j, a);
- }
-
- /**
- * Sort a long array into ascending order. The sort algorithm is an optimised
- * quicksort, as described in Jon L. Bentley and M. Douglas McIlroy's
- * "Engineering a Sort Function", Software-Practice and Experience, Vol.
- * 23(11) P. 1249-1265 (November 1993). This algorithm gives nlog(n)
- * performance on many arrays that would take quadratic time with a standard
- * quicksort.
- *
- * @param a the array to sort
- */
- public static void sort(long[] a) {
- qsort(a, 0, a.length);
- }
-
- // The "cmp" method has been removed from here and replaced with direct
- // compares in situ, to avoid problems with overflow if the difference
- // between two numbers is bigger than a long will hold.
- // One particular change as a result is the use of r1 and r2 in qsort
-
- private static int med3(int a, int b, int c, long[] d) {
- return d[a] < d[b] ?
- (d[b] < d[c] ? b : d[a] < d[c] ? c : a)
- : (d[b] > d[c] ? b : d[a] > d[c] ? c : a);
- }
-
- private static void swap(int i, int j, long[] a) {
- long c = a[i];
- a[i] = a[j];
- a[j] = c;
- }
-
- private static void qsort(long[] a, int start, int n) {
- // use an insertion sort on small arrays
- if (n < 7) {
- for (int i = start + 1; i < start + n; i++)
- for (int j = i; j > 0 && a[j-1] > a[j]; j--)
- swap(j, j-1, a);
- return;
- }
-
- int pm = n/2; // small arrays, middle element
- if (n > 7) {
- int pl = start;
- int pn = start + n-1;
-
- if (n > 40) { // big arrays, pseudomedian of 9
- int s = n/8;
- pl = med3(pl, pl+s, pl+2*s, a);
- pm = med3(pm-s, pm, pm+s, a);
- pn = med3(pn-2*s, pn-s, pn, a);
- }
- pm = med3(pl, pm, pn, a); // mid-size, med of 3
- }
-
- int pa, pb, pc, pd, pv;
- long r1, r2;
-
- pv = start; swap(pv, pm, a);
- pa = pb = start;
- pc = pd = start + n-1;
-
- for (;;) {
- while (pb <= pc && (r1 = a[pb]) <= (r2 = a[pv])) {
- if (r1 == r2) { swap(pa, pb, a); pa++; }
- pb++;
- }
- while (pc >= pb && (r1 = a[pc]) >= (r2 = a[pv])) {
- if (r1 == r2) { swap(pc, pd, a); pd--; }
- pc--;
- }
- if (pb > pc) break;
- swap(pb, pc, a);
- pb++;
- pc--;
- }
- int pn = start + n;
- int s;
- s = Math.min(pa-start, pb-pa); vecswap(start, pb-s, s, a);
- s = Math.min(pd-pc, pn-pd-1); vecswap(pb, pn-s, s, a);
- if ((s = pb-pa) > 1) qsort(a, start, s);
- if ((s = pd-pc) > 1) qsort(a, pn-s, s);
- }
-
- private static void vecswap(int i, int j, int n, long[] a) {
- for (; n > 0; i++, j++, n--)
- swap(i, j, a);
- }
-
- /**
- * Sort a short array into ascending order. The sort algorithm is an
- * optimised quicksort, as described in Jon L. Bentley and M. Douglas
- * McIlroy's "Engineering a Sort Function", Software-Practice and Experience,
- * Vol. 23(11) P. 1249-1265 (November 1993). This algorithm gives nlog(n)
- * performance on many arrays that would take quadratic time with a standard
- * quicksort.
- *
- * @param a the array to sort
- */
- public static void sort(short[] a) {
- qsort(a, 0, a.length);
- }
-
- private static int cmp(short i, short j) {
- return i-j;
- }
-
- private static int med3(int a, int b, int c, short[] d) {
- return cmp(d[a], d[b]) < 0 ?
- (cmp(d[b], d[c]) < 0 ? b : cmp(d[a], d[c]) < 0 ? c : a)
- : (cmp(d[b], d[c]) > 0 ? b : cmp(d[a], d[c]) > 0 ? c : a);
- }
-
- private static void swap(int i, int j, short[] a) {
- short c = a[i];
- a[i] = a[j];
- a[j] = c;
- }
-
- private static void qsort(short[] a, int start, int n) {
- // use an insertion sort on small arrays
- if (n < 7) {
- for (int i = start + 1; i < start + n; i++)
- for (int j = i; j > 0 && cmp(a[j-1], a[j]) > 0; j--)
- swap(j, j-1, a);
- return;
- }
-
- int pm = n/2; // small arrays, middle element
- if (n > 7) {
- int pl = start;
- int pn = start + n-1;
-
- if (n > 40) { // big arrays, pseudomedian of 9
- int s = n/8;
- pl = med3(pl, pl+s, pl+2*s, a);
- pm = med3(pm-s, pm, pm+s, a);
- pn = med3(pn-2*s, pn-s, pn, a);
- }
- pm = med3(pl, pm, pn, a); // mid-size, med of 3
- }
-
- int pa, pb, pc, pd, pv;
- int r;
-
- pv = start; swap(pv, pm, a);
- pa = pb = start;
- pc = pd = start + n-1;
-
- for (;;) {
- while (pb <= pc && (r = cmp(a[pb], a[pv])) <= 0) {
- if (r == 0) { swap(pa, pb, a); pa++; }
- pb++;
- }
- while (pc >= pb && (r = cmp(a[pc], a[pv])) >= 0) {
- if (r == 0) { swap(pc, pd, a); pd--; }
- pc--;
- }
- if (pb > pc) break;
- swap(pb, pc, a);
- pb++;
- pc--;
- }
- int pn = start + n;
- int s;
- s = Math.min(pa-start, pb-pa); vecswap(start, pb-s, s, a);
- s = Math.min(pd-pc, pn-pd-1); vecswap(pb, pn-s, s, a);
- if ((s = pb-pa) > 1) qsort(a, start, s);
- if ((s = pd-pc) > 1) qsort(a, pn-s, s);
- }
-
- private static void vecswap(int i, int j, int n, short[] a) {
- for (; n > 0; i++, j++, n--)
- swap(i, j, a);
- }
-
- /**
- * The bulk of the work for the object sort routines. If c is null,
- * uses the natural ordering.
- * In general, the code attempts to be simple rather than fast, the idea
- * being that a good optimising JIT will be able to optimise it better than I
- * can, and if I try it will make it more confusing for the JIT. The
- * exception is in declaring values "final", which I do whenever there is no
- * need for them ever to change - this may give slight speedups.
- */
- private static void mergeSort(Object[] a, final Comparator c) {
- final int n = a.length;
- Object[] x = a;
- Object[] y = new Object[n];
- Object[] t = null; // t is used for swapping x and y
-
- // The merges are done in this loop
- for (int sizenf = 1; sizenf < n; sizenf <<= 1) {
- final int size = sizenf; // Slightly inelegant but probably speeds us up
-
- for (int startnf = 0; startnf < n; startnf += size << 1) {
- final int start = startnf; // see above with size and sizenf
-
- // size2 is the size of the second sublist, which may not be the same
- // as the first if we are at the end of the list.
- final int size2 = n - start - size < size ? n - start - size : size;
-
- // The second list is empty or the elements are already in order - no
- // need to merge
- if (size2 <= 0 ||
- compare(x[start + size - 1], x[start + size], c) <= 0) {
- System.arraycopy(x, start, y, start, size + size2);
-
- // The two halves just need swapping - no need to merge
- } else if (compare(x[start], x[start + size + size2 - 1], c) >= 0) {
- System.arraycopy(x, start, y, start + size2, size);
- System.arraycopy(x, start + size, y, start, size2);
-
- } else {
- // Declare a lot of variables to save repeating calculations.
- // Hopefully a decent JIT will put these in registers and make this
- // fast
- int p1 = start;
- int p2 = start + size;
- int i = start;
- int d1;
-
- // initial value added to placate javac
- int d2 = -1;
-
- // The main merge loop; terminates as soon as either half is ended
- // You'd think you needed to use & rather than && to make sure d2
- // gets calculated even if d1 == 0, but in fact if this is the case,
- // d2 hasn't changed since the last iteration.
- while ((d1 = start + size - p1) > 0 &&
- (d2 = start + size + size2 - p2) > 0) {
- y[i++] = x[(compare(x[p1], x[p2], c) <= 0) ? p1++ : p2++];
- }
-
- // Finish up by copying the remainder of whichever half wasn't
- // finished.
- System.arraycopy(x, d1 > 0 ? p1 : p2, y, i, d1 > 0 ? d1 : d2);
- }
- }
- t = x; x = y; y = t; // swap x and y ready for the next merge
- }
-
- // make sure the result ends up back in the right place.
- if (x != a) {
- System.arraycopy(x, 0, a, 0, n);
- }
- }
-
- /**
- * Sort an array of Objects according to their natural ordering. The sort is
- * guaranteed to be stable, that is, equal elements will not be reordered.
- * The sort algorithm is a mergesort with the merge omitted if the last
- * element of one half comes before the first element of the other half. This
- * algorithm gives guaranteed O(nlog(n)) time, at the expense of making a
- * copy of the array.
- *
- * @param a the array to be sorted
- * @exception ClassCastException if any two elements are not mutually
- * comparable
- * @exception NullPointerException if an element is null (since
- * null.compareTo cannot work)
- */
- public static void sort(Object[] a) {
- mergeSort(a, null);
- }
-
- /**
- * Sort an array of Objects according to a Comparator. The sort is
- * guaranteed to be stable, that is, equal elements will not be reordered.
- * The sort algorithm is a mergesort with the merge omitted if the last
- * element of one half comes before the first element of the other half. This
- * algorithm gives guaranteed O(nlog(n)) time, at the expense of making a
- * copy of the array.
- *
- * @param a the array to be sorted
- * @param c a Comparator to use in sorting the array
- * @exception ClassCastException if any two elements are not mutually
- * comparable by the Comparator provided
- */
- public static void sort(Object[] a, Comparator c) {
-
- // Passing null to mergeSort would use the natural ordering. This is wrong
- // by the spec and not in the reference implementation.
- if (c == null) {
- throw new NullPointerException();
- }
- mergeSort(a, c);
- }
-
- /**
- * Returns a list "view" of the specified array. This method is intended to
- * make it easy to use the Collections API with existing array-based APIs and
- * programs.
- *
- * @param a the array to return a view of
- * @returns a fixed-size list, changes to which "write through" to the array
- */
- public static List asList(final Object[] a) {
-
- // Check for a null argument
- if (a == null) {
- throw new NullPointerException();
- }
-
- return new ListImpl( a );
- }
-
-
- /**
- * Inner class used by asList(Object[]) to provide a list interface
- * to an array. The methods are all simple enough to be self documenting.
- * Note: When Sun fully specify serialized forms, this class will have to
- * be renamed.
- */
- private static class ListImpl extends AbstractList {
-
- ListImpl(Object[] a) {
- this.a = a;
- }
-
- public Object get(int index) {
- return a[index];
- }
-
- public int size() {
- return a.length;
- }
-
- public Object set(int index, Object element) {
- Object old = a[index];
- a[index] = element;
- return old;
- }
-
- private Object[] a;
- }
-
-}
diff --git a/jode/jode/util/BasicMapEntry.java b/jode/jode/util/BasicMapEntry.java
deleted file mode 100644
index 83aaafe..0000000
--- a/jode/jode/util/BasicMapEntry.java
+++ /dev/null
@@ -1,138 +0,0 @@
-// This class is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// BasicMapEntry.java -- a class providing a plain-vanilla implementation of
-// the Map.Entry interface; could be used anywhere in
-// java.util
-//
-// Copyright (c) 1998 by Jon A. Zeppieri (jon@eease.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-
-package jode.util;
-///#ifdef JDK12
-///import java.lang.UnsupportedOperationException;
-///import java.util.Map;
-///#endif
-
-/**
- * a class which implements Map.Entry
- *
- * @author Jon Zeppieri
- * @version $Revision$
- * @modified $Id$
- */
-class BasicMapEntry implements Map.Entry
-{
- /** the key */
- Object key;
- /** the value */
- Object value;
-
- /**
- * construct a new BasicMapEntry with the given key and value
- *
- * @param newKey the key of this Entry
- * @param newValue the value of this Entry
- */
- BasicMapEntry(Object newKey, Object newValue)
- {
- key = newKey;
- value = newValue;
- }
-
- /**
- * returns true if o
is a Map.Entry and
- *
- * (((o.getKey == null) ? (key == null) :
- * o.getKey().equals(key)) &&
- * ((o.getValue() == null) ? (value == null) :
- * o.getValue().equals(value)))
- *
- *
- * NOTE: the calls to getKey() and getValue() in this implementation
- * are NOT superfluous and should not be removed. They insure
- * that subclasses such as HashMapEntry work correctly
- *
- * @param o the Object being tested for equality
- */
- public boolean equals(Object o)
- {
- Map.Entry tester;
- Object oTestingKey, oTestingValue;
- Object oKey, oValue;
- if (o instanceof Map.Entry)
- {
- tester = (Map.Entry) o;
- oKey = getKey();
- oValue = getValue();
- oTestingKey = tester.getKey();
- oTestingValue = tester.getValue();
- return (((oTestingKey == null) ? (oKey == null) :
- oTestingKey.equals(oKey)) &&
- ((oTestingValue == null) ? (oValue == null) :
- oTestingValue.equals(oValue)));
- }
- return false;
- }
-
- /** returns the key */
- public Object getKey()
- {
- return key;
- }
-
- /** returns the value */
- public Object getValue()
- {
- return value;
- }
-
- /** the hashCode() for a Map.Entry is
- *
- * ((getKey() == null) ? 0 : getKey().hashCode()) ^
- * ((getValue() == null) ? 0 : getValue().hashCode());
- *
- *
- * NOTE: the calls to getKey() and getValue() in this implementation
- * are NOT superfluous and should not be removed. They insure
- * that subclasses such as HashMapEntry work correctly
- */
- public int hashCode()
- {
- Object oKey = getKey();
- Object oValue = getValue();
- return ((oKey == null) ? 0 : oKey.hashCode()) ^
- ((oValue == null) ? 0 : oValue.hashCode());
- }
-
- /**
- * sets the value of this Map.Entry
- *
- * @param newValue the new value of this Map.Entry
- */
- public Object setValue(Object newValue)
- throws UnsupportedOperationException, ClassCastException,
- IllegalArgumentException, NullPointerException
- {
- Object oVal = value;
- value = newValue;
- return oVal;
- }
-}
diff --git a/jode/jode/util/Bucket.java b/jode/jode/util/Bucket.java
deleted file mode 100644
index 4ce894b..0000000
--- a/jode/jode/util/Bucket.java
+++ /dev/null
@@ -1,198 +0,0 @@
-// This class is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// Bucket.java -- a class providing a hash-bucket data structure (a lightweight
-// linked list)
-//
-// Copyright (c) 1998 by Jon A. Zeppieri (jon@eease.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-
-package jode.util;
-
-/**
- * a class representing a simple, lightweight linked-list, using Node
- * objects as its linked nodes; this is used by Hashtable and HashMap
- *
- * @author Jon Zeppieri
- * @version $Revision$
- * @modified $Id$
- */
-class Bucket
-{
- /** the first node of the lined list, originally null */
- Node first;
-
- /** trivial constructor for a Bucket */
- Bucket()
- {
- }
-
- /** add this key / value pair to the list
- *
- * @param entry a Map.Entry object to be added to this list
- */
- Map.Entry add(Node newNode)
- {
- Object oKey;
- Object oTestKey = newNode.getKey();
- Node it = first;
- Node prev = null;
- if (it == null) // if the list is empty (the ideal case), we make a new single-node list
- {
- first = newNode;
- return null;
- }
- else // otherwise try to find where this key already exists in the list,
- {// and if it does, replace the value with the new one (and return the old one)
- while (it != null)
- {
- oKey = it.getKey();
- if ((oKey == null) ? (oTestKey == null) :
- oKey.equals(oTestKey))
- {
- if (prev != null)
- prev.next = newNode;
- else
- first = newNode;
- newNode.next = it.next;
- return it;
- }
- prev = it;
- it = it.next;
- }
- prev.next = newNode; // otherwise, just stick this at the
- return null; // end of the list
- }
- }
-
- /**
- * remove a Map.Entry in this list with the supplied key and return its value,
- * if it exists, else return null
- *
- * @param key the key we are looking for in this list
- */
- Object removeByKey(Object key)
- {
- Object oEntryKey;
- Node prev = null;
- Node it = first;
- while (it != null)
- {
- oEntryKey = it.getKey();
- if ((oEntryKey == null) ? (key == null) : oEntryKey.equals(key))
- {
- if (prev == null) // we are removing the first element
- first = it.next;
- else
- prev.next = it.next;
- return it.getValue();
- }
- else
- {
- prev = it;
- it = it.next;
- }
- }
- return null;
- }
-
- /**
- * return the value which the supplied key maps to, if it maps to anything in this list,
- * otherwise, return null
- *
- * @param key the key mapping to a value that we are looking for
- */
- Object getValueByKey(Object key)
- {
- Node entry = getEntryByKey(key);
- return (entry == null) ? null : entry.getValue();
- }
-
- /**
- * return the Map.Entry which the supplied key is a part of, if such a Map.Entry exists,
- * null otherwise
- *
- * this method is important for HashMap, which can hold null values and the null key
- *
- * @param key the key for which we are finding the corresponding Map.Entry
- */
- Node getEntryByKey(Object key)
- {
- Object oEntryKey;
- Node it = first;
- while (it != null)
- {
- oEntryKey = it.getKey();
- if ((oEntryKey == null) ? (key == null) : oEntryKey.equals(key))
- return it;
- it = it.next;
- }
- return null;
- }
-
- /**
- * return true if this list has a Map.Entry whose value equals() the supplied value
- *
- * @param value the value we are looking to match in this list
- */
- boolean containsValue(Object value)
- {
- Object oEntryValue;
- Node it = first;
- while (it != null)
- {
- oEntryValue = it.getValue();
- if ((oEntryValue == null) ? (value == null) : oEntryValue.equals(value))
- return true;
- it = it.next;
- }
- return false;
- }
-
- // INNSER CLASSES ----------------------------------------------------------
-
- /**
- * a class represnting a node in our lightweight linked-list
- * that we use for hash buckets; a Node object contains a Map.Entry as its
- * value
property and a reference (possibly, even hopefully, null)
- * to another Node as its next
property.
- *
- * There is a reason for not using a highly generic "LinkedNode" type
- * class: we want to eliminate runtime typechecks.
- *
- * @author Jon Zeppieri
- * @version $Revision$
- * @modified $Id$
- */
- static class Node extends BasicMapEntry implements Map.Entry
- {
- /** a reference to the next node in the linked list */
- Node next;
-
- /** non-trivial contructor -- sets the value
of the Bucket upon instantiation */
- Node(Object key, Object value)
- {
- super(key, value);
- }
-
-
- }
- // EOF ------------------------------------------------------------------------
-}
diff --git a/jode/jode/util/Collection.java b/jode/jode/util/Collection.java
deleted file mode 100644
index 9279326..0000000
--- a/jode/jode/util/Collection.java
+++ /dev/null
@@ -1,234 +0,0 @@
-// This interface is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// Collection.java -- Interface that represents a collection of objects
-//
-// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-
-// TO DO:
-// ~ Maybe some more @see clauses would be helpful.
-
-package jode.util;
-
-/**
- * Interface that represents a collection of objects. This interface is the
- * root of the collection hierarchy, and does not provide any guarantees about
- * the order of its elements or whether or not duplicate elements are
- * permitted.
- *
- * All methods of this interface that are defined to modify the collection are
- * defined as optional. An optional operation may throw an
- * UnsupportedOperationException if the data backing this collection does not
- * support such a modification. This may mean that the data structure is
- * immutable, or that it is read-only but may change ("unmodifiable"), or
- * that it is modifiable but of fixed size (such as an array), or any number
- * of other combinations.
- *
- * A class that wishes to implement this interface should consider subclassing
- * AbstractCollection, which provides basic implementations of most of the
- * methods of this interface. Classes that are prepared to make guarantees
- * about ordering or about absence of duplicate elements should consider
- * implementing List or Set respectively, both of which are subinterfaces of
- * Collection.
- *
- * A general-purpose implementation of the Collection interface should in most
- * cases provide at least two constructors: One which takes no arguments and
- * creates an empty collection, and one which takes a Collection as an argument
- * and returns a collection containing the same elements (that is, creates a
- * copy of the argument using its own implementation).
- *
- * @see java.util.List
- * @see java.util.Set
- * @see java.util.AbstractCollection
- */
-public interface Collection {
-
- /**
- * Add an element to this collection.
- *
- * @param o the object to add.
- * @returns true if the collection was modified as a result of this action.
- * @exception UnsupportedOperationException if this collection does not
- * support the add operation.
- * @exception ClassCastException if o cannot be added to this collection due
- * to its type.
- * @exception IllegalArgumentException if o cannot be added to this
- * collection for some other reason.
- */
- boolean add(Object o);
-
- /**
- * Add the contents of a given collection to this collection.
- *
- * @param c the collection to add.
- * @returns true if the collection was modified as a result of this action.
- * @exception UnsupportedOperationException if this collection does not
- * support the addAll operation.
- * @exception ClassCastException if some element of c cannot be added to this
- * collection due to its type.
- * @exception IllegalArgumentException if some element of c cannot be added
- * to this collection for some other reason.
- */
- boolean addAll(Collection c);
-
- /**
- * Clear the collection, such that a subsequent call to isEmpty() would
- * return true.
- *
- * @exception UnsupportedOperationException if this collection does not
- * support the clear operation.
- */
- void clear();
-
- /**
- * Test whether this collection contains a given object as one of its
- * elements.
- *
- * @param o the element to look for.
- * @returns true if this collection contains at least one element e such that
- * o == null ? e == null : o.equals(e)
.
- */
- boolean contains(Object o);
-
- /**
- * Test whether this collection contains every element in a given collection.
- *
- * @param c the collection to test for.
- * @returns true if for every element o in c, contains(o) would return true.
- */
- boolean containsAll(Collection c);
-
- /**
- * Test whether this collection is equal to some object. The Collection
- * interface does not explicitly require any behaviour from this method, and
- * it may be left to the default implementation provided by Object. The Set
- * and List interfaces do, however, require specific behaviour from this
- * method.
- *
- * If an implementation of Collection, which is not also an implementation of
- * Set or List, should choose to implement this method, it should take care
- * to obey the contract of the equals method of Object. In particular, care
- * should be taken to return false when o is a Set or a List, in order to
- * preserve the symmetry of the relation.
- *
- * @param o the object to compare to this collection.
- * @returns true if the o is equal to this collection.
- */
- boolean equals(Object o);
-
- /**
- * Obtain a hash code for this collection. The Collection interface does not
- * explicitly require any behaviour from this method, and it may be left to
- * the default implementation provided by Object. The Set and List interfaces
- * do, however, require specific behaviour from this method.
- *
- * If an implementation of Collection, which is not also an implementation of
- * Set or List, should choose to implement this method, it should take care
- * to obey the contract of the hashCode method of Object. Note that this
- * method renders it impossible to correctly implement both Set and List, as
- * the required implementations are mutually exclusive.
- *
- * @returns a hash code for this collection.
- */
- int hashCode();
-
- /**
- * Test whether this collection is empty, that is, if size() == 0.
- *
- * @returns true if this collection contains no elements.
- */
- boolean isEmpty();
-
- /**
- * Obtain an Iterator over this collection.
- *
- * @returns an Iterator over the elements of this collection, in any order.
- */
- Iterator iterator();
-
- /**
- * Remove a single occurrence of an object from this collection. That is,
- * remove an element e, if one exists, such that o == null ? e == null
- * : o.equals(e)
.
- *
- * @param o the object to remove.
- * @returns true if the collection changed as a result of this call, that is,
- * if the collection contained at least one occurrence of o.
- * @exception UnsupportedOperationException if this collection does not
- * support the remove operation.
- */
- boolean remove(Object o);
-
- /**
- * Remove all elements of a given collection from this collection. That is,
- * remove every element e such that c.contains(e).
- *
- * @returns true if this collection was modified as a result of this call.
- * @exception UnsupportedOperationException if this collection does not
- * support the removeAll operation.
- */
- boolean removeAll(Collection c);
-
- /**
- * Remove all elements of this collection that are not contained in a given
- * collection. That is, remove every element e such that !c.contains(e).
- *
- * @returns true if this collection was modified as a result of this call.
- * @exception UnsupportedOperationException if this collection does not
- * support the retainAll operation.
- */
- boolean retainAll(Collection c);
-
- /**
- * Get the number of elements in this collection.
- *
- * @returns the number of elements in the collection.
- */
- int size();
-
- /**
- * Copy the current contents of this collection into an array.
- *
- * @returns an array of type Object[] and length equal to the size of this
- * collection, containing the elements currently in this collection, in
- * any order.
- */
- Object[] toArray();
-
- /**
- * Copy the current contents of this collection into an array. If the array
- * passed as an argument has length less than the size of this collection, an
- * array of the same run-time type as a, and length equal to the size of this
- * collection, is allocated using Reflection. Otherwise, a itself is used.
- * The elements of this collection are copied into it, and if there is space
- * in the array, the following element is set to null. The resultant array is
- * returned.
- * Note: The fact that the following element is set to null is only useful
- * if it is known that this collection does not contain any null elements.
- *
- * @param a the array to copy this collection into.
- * @returns an array containing the elements currently in this collection, in
- * any order.
- * @exception ArrayStoreException if the type of any element of the
- * collection is not a subtype of the element type of a.
- */
- Object[] toArray(Object[] a);
-}
diff --git a/jode/jode/util/Collections.java b/jode/jode/util/Collections.java
deleted file mode 100644
index 9bcdfd4..0000000
--- a/jode/jode/util/Collections.java
+++ /dev/null
@@ -1,1413 +0,0 @@
-// This class is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// Collections.java -- Utility class with methods to operate on collections
-//
-// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-
-// TO DO:
-// ~ Serialization is very much broken. Blame Sun for not specifying it.
-// ~ The synchronized* and unmodifiable* methods don't have doc-comments.
-
-package jode.util;
-
-import java.io.Serializable;
-import java.util.Enumeration;
-import java.util.Random;
-import java.util.NoSuchElementException;
-
-/**
- * Utility class consisting of static methods that operate on, or return
- * Collections. Contains methods to sort, search, reverse, fill and shuffle
- * Collections, methods to facilitate interoperability with legacy APIs that
- * are unaware of collections, a method to return a list which consists of
- * multiple copies of one element, and methods which "wrap" collections to give
- * them extra properties, such as thread-safety and unmodifiability.
- */
-public class Collections {
-
- /**
- * This class is non-instantiable.
- */
- private Collections() {
- }
-
- /**
- * An immutable, empty Set.
- * Note: This implementation isn't Serializable, although it should be by the
- * spec.
- */
- public static final Set EMPTY_SET = new AbstractSet() {
-
- public int size() {
- return 0;
- }
-
- // This is really cheating! I think it's perfectly valid, though - the
- // more conventional code is here, commented out, in case anyone disagrees.
- public Iterator iterator() {
- return EMPTY_LIST.iterator();
- }
-
- // public Iterator iterator() {
- // return new Iterator() {
- //
- // public boolean hasNext() {
- // return false;
- // }
- //
- // public Object next() {
- // throw new NoSuchElementException();
- // }
- //
- // public void remove() {
- // throw new UnsupportedOperationException();
- // }
- // };
- // }
-
- };
-
- /**
- * An immutable, empty List.
- * Note: This implementation isn't serializable, although it should be by the
- * spec.
- */
- public static final List EMPTY_LIST = new AbstractList() {
-
- public int size() {
- return 0;
- }
-
- public Object get(int index) {
- throw new IndexOutOfBoundsException();
- }
- };
-
- /**
- * Compare two objects with or without a Comparator. If c is null, uses the
- * natural ordering. Slightly slower than doing it inline if the JVM isn't
- * clever, but worth it for removing a duplicate of the search code.
- * Note: This same code is used in Arrays (for sort as well as search)
- */
- private static int compare(Object o1, Object o2, Comparator c) {
- if (c == null) {
- return ((Comparable)o1).compareTo(o2);
- } else {
- return c.compare(o1, o2);
- }
- }
-
- /**
- * The hard work for the search routines. If the Comparator given is null,
- * uses the natural ordering of the elements.
- */
- private static int search(List l, Object key, final Comparator c) {
-
- int pos = 0;
-
- // We use a linear search using an iterator if we can guess that the list
- // is sequential-access.
- if (l instanceof AbstractSequentialList) {
- ListIterator i = l.listIterator();
- while (i.hasNext()) {
- final int d = compare(key, i.next(), c);
- if (d == 0) {
- return pos;
- } else if (d < 0) {
- return -pos - 1;
- }
- pos++;
- }
-
- // We assume the list is random-access, and use a binary search
- } else {
- int low = 0;
- int hi = l.size() - 1;
- while (low <= hi) {
- pos = (low + hi) >> 1;
- final int d = compare(key, l.get(pos), c);
- if (d == 0) {
- return pos;
- } else if (d < 0) {
- hi = pos - 1;
- } else {
- low = ++pos; // This gets the insertion point right on the last loop
- }
- }
- }
-
- // If we failed to find it, we do the same whichever search we did.
- return -pos - 1;
- }
-
- /**
- * Perform a binary search of a List for a key, using the natural ordering of
- * the elements. The list must be sorted (as by the sort() method) - if it is
- * not, the behaviour of this method is undefined, and may be an infinite
- * loop. Further, the key must be comparable with every item in the list. If
- * the list contains the key more than once, any one of them may be found. To
- * avoid pathological behaviour on sequential-access lists, a linear search
- * is used if (l instanceof AbstractSequentialList). Note: although the
- * specification allows for an infinite loop if the list is unsorted, it will
- * not happen in this (Classpath) implementation.
- *
- * @param l the list to search (must be sorted)
- * @param key the value to search for
- * @returns the index at which the key was found, or -n-1 if it was not
- * found, where n is the index of the first value higher than key or
- * a.length if there is no such value.
- * @exception ClassCastException if key could not be compared with one of the
- * elements of l
- * @exception NullPointerException if a null element has compareTo called
- */
- public static int binarySearch(List l, Object key) {
- return search(l, key, null);
- }
-
- /**
- * Perform a binary search of a List for a key, using a supplied Comparator.
- * The list must be sorted (as by the sort() method with the same Comparator)
- * - if it is not, the behaviour of this method is undefined, and may be an
- * infinite loop. Further, the key must be comparable with every item in the
- * list. If the list contains the key more than once, any one of them may be
- * found. To avoid pathological behaviour on sequential-access lists, a
- * linear search is used if (l instanceof AbstractSequentialList). Note:
- * although the specification allows for an infinite loop if the list is
- * unsorted, it will not happen in this (Classpath) implementation.
- *
- * @param l the list to search (must be sorted)
- * @param key the value to search for
- * @param c the comparator by which the list is sorted
- * @returns the index at which the key was found, or -n-1 if it was not
- * found, where n is the index of the first value higher than key or
- * a.length if there is no such value.
- * @exception ClassCastException if key could not be compared with one of the
- * elements of l
- */
- public static int binarySearch(List l, Object key, Comparator c) {
- if (c == null) {
- throw new NullPointerException();
- }
- return search(l, key, c);
- }
-
- /**
- * Copy one list to another. If the destination list is longer than the
- * source list, the remaining elements are unaffected. This method runs in
- * linear time.
- *
- * @param dest the destination list.
- * @param source the source list.
- * @exception IndexOutOfBoundsException if the destination list is shorter
- * than the source list (the elements that can be copied will be, prior to
- * the exception being thrown).
- * @exception UnsupportedOperationException if dest.listIterator() does not
- * support the set operation.
- */
- public static void copy(List dest, List source) {
- Iterator i1 = source.iterator();
- ListIterator i2 = dest.listIterator();
- while (i1.hasNext()) {
- i2.next();
- i2.set(i1.next());
- }
- }
-
- /**
- * Returns an Enumeration over a collection. This allows interoperability
- * with legacy APIs that require an Enumeration as input.
- *
- * @param c the Collection to iterate over
- * @returns an Enumeration backed by an Iterator over c
- */
- public static Enumeration enumeration(Collection c) {
- final Iterator i = c.iterator();
- return new Enumeration() {
- public final boolean hasMoreElements() {
- return i.hasNext();
- }
- public final Object nextElement() {
- return i.next();
- }
- };
- }
-
- /**
- * Replace every element of a list with a given value. This method runs in
- * linear time.
- *
- * @param l the list to fill.
- * @param val the object to vill the list with.
- * @exception UnsupportedOperationException if l.listIterator() does not
- * support the set operation.
- */
- public static void fill(List l, Object val) {
- ListIterator i = l.listIterator();
- while (i.hasNext()) {
- i.next();
- i.set(val);
- }
- }
-
- /**
- * Find the maximum element in a Collection, according to the natural
- * ordering of the elements. This implementation iterates over the
- * Collection, so it works in linear time.
- *
- * @param c the Collection to find the maximum element of
- * @returns the maximum element of c
- * @exception NoSuchElementException if c is empty
- * @exception ClassCastException if elements in c are not mutually comparable
- * @exception NullPointerException if null.compareTo is called
- */
- public static Object max(Collection c) {
- Iterator i = c.iterator();
- Comparable max = (Comparable)i.next(); // throws NoSuchElementException
- while (i.hasNext()) {
- Object o = i.next();
- if (max.compareTo(o) < 0) {
- max = (Comparable)o;
- }
- }
- return max;
- }
-
- /**
- * Find the maximum element in a Collection, according to a specified
- * Comparator. This implementation iterates over the Collection, so it
- * works in linear time.
- *
- * @param c the Collection to find the maximum element of
- * @param order the Comparator to order the elements by
- * @returns the maximum element of c
- * @exception NoSuchElementException if c is empty
- * @exception ClassCastException if elements in c are not mutually comparable
- */
- public static Object max(Collection c, Comparator order) {
- Iterator i = c.iterator();
- Object max = i.next(); // throws NoSuchElementException
- while (i.hasNext()) {
- Object o = i.next();
- if (order.compare(max, o) < 0) {
- max = o;
- }
- }
- return max;
- }
-
- /**
- * Find the minimum element in a Collection, according to the natural
- * ordering of the elements. This implementation iterates over the
- * Collection, so it works in linear time.
- *
- * @param c the Collection to find the minimum element of
- * @returns the minimum element of c
- * @exception NoSuchElementException if c is empty
- * @exception ClassCastException if elements in c are not mutually comparable
- * @exception NullPointerException if null.compareTo is called
- */
- public static Object min(Collection c) {
- Iterator i = c.iterator();
- Comparable min = (Comparable)i.next(); // throws NoSuchElementException
- while (i.hasNext()) {
- Object o = i.next();
- if (min.compareTo(o) > 0) {
- min = (Comparable)o;
- }
- }
- return min;
- }
-
- /**
- * Find the minimum element in a Collection, according to a specified
- * Comparator. This implementation iterates over the Collection, so it
- * works in linear time.
- *
- * @param c the Collection to find the minimum element of
- * @param order the Comparator to order the elements by
- * @returns the minimum element of c
- * @exception NoSuchElementException if c is empty
- * @exception ClassCastException if elements in c are not mutually comparable
- */
- public static Object min(Collection c, Comparator order) {
- Iterator i = c.iterator();
- Object min = i.next(); // throws NoSuchElementExcception
- while (i.hasNext()) {
- Object o = i.next();
- if (order.compare(min, o) > 0) {
- min = o;
- }
- }
- return min;
- }
-
- /**
- * Creates an immutable list consisting of the same object repeated n times.
- * The returned object is tiny, consisting of only a single reference to the
- * object and a count of the number of elements. It is Serializable.
- *
- * @param n the number of times to repeat the object
- * @param o the object to repeat
- * @returns a List consisting of n copies of o
- * @throws IllegalArgumentException if n < 0
- */
- // It's not Serializable, because the serialized form is unspecced.
- // Also I'm only assuming that it should be because I don't think it's
- // stated - I just would be amazed if it isn't...
- public static List nCopies(final int n, final Object o) {
-
- // Check for insane arguments
- if (n < 0) {
- throw new IllegalArgumentException();
- }
-
- // Create a minimal implementation of List
- return new AbstractList() {
-
- public int size() {
- return n;
- }
-
- public Object get(int index) {
- if (index < 0 || index >= n) {
- throw new IndexOutOfBoundsException();
- }
- return o;
- }
- };
- }
-
- /**
- * Reverse a given list. This method works in linear time.
- *
- * @param l the list to reverse.
- * @exception UnsupportedOperationException if l.listIterator() does not
- * support the set operation.
- */
- public static void reverse(List l) {
- ListIterator i1 = l.listIterator();
- ListIterator i2 = l.listIterator(l.size());
- while (i1.nextIndex() < i2.previousIndex()) {
- Object o = i1.next();
- i1.set(i2.previous());
- i2.set(o);
- }
- }
-
- /**
- * Get a comparator that implements the reverse of natural ordering. This is
- * intended to make it easy to sort into reverse order, by simply passing
- * Collections.reverseOrder() to the sort method. The return value of this
- * method is Serializable.
- */
- // The return value isn't Serializable, because the spec is broken.
- public static Comparator reverseOrder() {
- return new Comparator() {
- public int compare(Object a, Object b) {
- return -((Comparable)a).compareTo(b);
- }
- };
- }
-
- /**
- * Shuffle a list according to a default source of randomness. The algorithm
- * used would result in a perfectly fair shuffle (that is, each element would
- * have an equal chance of ending up in any position) with a perfect source
- * of randomness; in practice the results are merely very close to perfect.
- *
- * This method operates in linear time on a random-access list, but may take
- * quadratic time on a sequential-access list.
- * Note: this (classpath) implementation will never take quadratic time, but
- * it does make a copy of the list. This is in line with the behaviour of the
- * sort methods and seems preferable.
- *
- * @param l the list to shuffle.
- * @exception UnsupportedOperationException if l.listIterator() does not
- * support the set operation.
- */
- public static void shuffle(List l) {
- shuffle(l, new Random());
- }
-
- /**
- * Shuffle a list according to a given source of randomness. The algorithm
- * used iterates backwards over the list, swapping each element with an
- * element randomly selected from the elements in positions less than or
- * equal to it (using r.nextInt(int)).
- *
- * This algorithm would result in a perfectly fair shuffle (that is, each
- * element would have an equal chance of ending up in any position) if r were
- * a perfect source of randomness. In practise (eg if r = new Random()) the
- * results are merely very close to perfect.
- *
- * This method operates in linear time on a random-access list, but may take
- * quadratic time on a sequential-access list.
- * Note: this (classpath) implementation will never take quadratic time, but
- * it does make a copy of the list. This is in line with the behaviour of the
- * sort methods and seems preferable.
- *
- * @param l the list to shuffle.
- * @param r the source of randomness to use for the shuffle.
- * @exception UnsupportedOperationException if l.listIterator() does not
- * support the set operation.
- */
- public static void shuffle(List l, Random r) {
- Object[] a = l.toArray(); // Dump l into an array
- ListIterator i = l.listIterator(l.size());
-
- // Iterate backwards over l
- while (i.hasPrevious()) {
-
- // Obtain a random position to swap with. nextIndex is used so that the
- // range of the random number includes the current position.
-// int swap = r.nextInt(i.nextIndex());
- // Change for jode by
- int swap = Math.abs(r.nextInt()) % i.nextIndex();
-
- // Swap the swapth element of the array with the next element of the
- // list.
- Object o = i.previous();
- i.set(a[swap]);
- a[swap] = o;
- }
- }
-
- /**
- * Obtain an immutable Set consisting of a single element. The return value
- * of this method is Serializable.
- *
- * @param o the single element.
- * @returns an immutable Set containing only o.
- */
- // It's not serializable because the spec is broken.
- public static Set singleton(final Object o) {
-
- return new AbstractSet() {
-
- public int size() {
- return 1;
- }
-
- public Iterator iterator() {
- return new Iterator() {
-
- private boolean hasNext = true;
-
- public boolean hasNext() {
- return hasNext;
- }
-
- public Object next() {
- if (hasNext) {
- hasNext = false;
- return o;
- } else {
- throw new NoSuchElementException();
- }
- }
-
- public void remove() {
- throw new UnsupportedOperationException();
- }
- };
- }
- };
- }
-
- /**
- * Sort a list according to the natural ordering of its elements. The list
- * must be modifiable, but can be of fixed size. The sort algorithm is
- * precisely that used by Arrays.sort(Object[]), which offers guaranteed
- * nlog(n) performance. This implementation dumps the list into an array,
- * sorts the array, and then iterates over the list setting each element from
- * the array.
- *
- * @param l the List to sort
- * @exception ClassCastException if some items are not mutually comparable
- * @exception UnsupportedOperationException if the List is not modifiable
- */
- public static void sort(List l) {
- Object[] a = l.toArray();
- Arrays.sort(a);
- ListIterator i = l.listIterator();
- for (int pos = 0; pos < a.length; pos++) {
- i.next();
- i.set(a[pos]);
- }
- }
-
- /**
- * Sort a list according to a specified Comparator. The list must be
- * modifiable, but can be of fixed size. The sort algorithm is precisely that
- * used by Arrays.sort(Object[], Comparator), which offers guaranteed
- * nlog(n) performance. This implementation dumps the list into an array,
- * sorts the array, and then iterates over the list setting each element from
- * the array.
- *
- * @param l the List to sort
- * @param c the Comparator specifying the ordering for the elements
- * @exception ClassCastException if c will not compare some pair of items
- * @exception UnsupportedOperationException if the List is not modifiable
- */
- public static void sort(List l, Comparator c) {
- Object[] a = l.toArray();
- Arrays.sort(a, c);
- ListIterator i = l.listIterator();
- for (int pos = 0; pos < a.length; pos++) {
- i.next();
- i.set(a[pos]);
- }
- }
-
- // All the methods from here on in require doc-comments.
-
- public static Collection synchronizedCollection(Collection c) {
- return new SynchronizedCollection(c);
- }
- public static List synchronizedList(List l) {
- return new SynchronizedList(l);
- }
- public static Map synchronizedMap(Map m) {
- return new SynchronizedMap(m);
- }
- public static Set synchronizedSet(Set s) {
- return new SynchronizedSet(s);
- }
- public static SortedMap synchronizedSortedMap(SortedMap m) {
- return new SynchronizedSortedMap(m);
- }
- public static SortedSet synchronizedSortedSet(SortedSet s) {
- return new SynchronizedSortedSet(s);
- }
- public static Collection unmodifiableCollection(Collection c) {
- return new UnmodifiableCollection(c);
- }
- public static List unmodifiableList(List l) {
- return new UnmodifiableList(l);
- }
- public static Map unmodifiableMap(Map m) {
- return new UnmodifiableMap(m);
- }
- public static Set unmodifiableSet(Set s) {
- return new UnmodifiableSet(s);
- }
- public static SortedMap unmodifiableSortedMap(SortedMap m) {
- return new UnmodifiableSortedMap(m);
- }
- public static SortedSet unmodifiableSortedSet(SortedSet s) {
- return new UnmodifiableSortedSet(s);
- }
-
- // Sun's spec will need to be checked for the precise names of these
- // classes, for serializability's sake. However, from what I understand,
- // serialization is broken for these classes anyway.
-
- // Note: although this code is largely uncommented, it is all very
- // mechanical and there's nothing really worth commenting.
- // When serialization of these classes works, we'll need doc-comments on
- // them to document the serialized form.
-
- private static class UnmodifiableIterator implements Iterator {
- private Iterator i;
-
- public UnmodifiableIterator(Iterator i) {
- this.i = i;
- }
-
- public Object next() {
- return i.next();
- }
- public boolean hasNext() {
- return i.hasNext();
- }
- public void remove() {
- throw new UnsupportedOperationException();
- }
- }
-
- private static class UnmodifiableListIterator extends UnmodifiableIterator
- implements ListIterator {
-
- // This is stored both here and in the superclass, to avoid excessive
- // casting.
- private ListIterator li;
-
- public UnmodifiableListIterator(ListIterator li) {
- super(li);
- this.li = li;
- }
-
- public boolean hasPrevious() {
- return li.hasPrevious();
- }
- public Object previous() {
- return li.previous();
- }
- public int nextIndex() {
- return li.nextIndex();
- }
- public int previousIndex() {
- return li.previousIndex();
- }
- public void add(Object o) {
- throw new UnsupportedOperationException();
- }
- public void set(Object o) {
- throw new UnsupportedOperationException();
- }
- }
-
- private static class UnmodifiableCollection implements Collection, Serializable {
- Collection c;
-
- public UnmodifiableCollection(Collection c) {
- this.c = c;
- }
-
- public boolean add(Object o) {
- throw new UnsupportedOperationException();
- }
- public boolean addAll(Collection c) {
- throw new UnsupportedOperationException();
- }
- public void clear() {
- throw new UnsupportedOperationException();
- }
- public boolean contains(Object o) {
- return c.contains(o);
- }
- public boolean containsAll(Collection c1) {
- return c.containsAll(c1);
- }
- public boolean isEmpty() {
- return c.isEmpty();
- }
- public Iterator iterator() {
- return new UnmodifiableIterator(c.iterator());
- }
- public boolean remove(Object o) {
- throw new UnsupportedOperationException();
- }
- public boolean removeAll(Collection c) {
- throw new UnsupportedOperationException();
- }
- public boolean retainAll(Collection c) {
- throw new UnsupportedOperationException();
- }
- public int size() {
- return c.size();
- }
- public Object[] toArray() {
- return c.toArray();
- }
- public Object[] toArray(Object[] a) {
- return c.toArray(a);
- }
- }
-
- private static class UnmodifiableList extends UnmodifiableCollection
- implements List {
-
- // This is stored both here and in the superclass, to avoid excessive
- // casting.
- List l;
-
- public UnmodifiableList(List l) {
- super(l);
- this.l = l;
- }
-
- public void add(int index, Object o) {
- l.add(index, o);
- }
- public boolean addAll(int index, Collection c) {
- return l.addAll(index, c);
- }
- public boolean equals(Object o) {
- return l.equals(o);
- }
- public Object get(int index) {
- return l.get(index);
- }
- public int hashCode() {
- return l.hashCode();
- }
- public int indexOf(Object o) {
- return l.indexOf(o);
- }
- public int lastIndexOf(Object o) {
- return l.lastIndexOf(o);
- }
- public ListIterator listIterator() {
- return new UnmodifiableListIterator(l.listIterator());
- }
- public ListIterator listIterator(int index) {
- return new UnmodifiableListIterator(l.listIterator(index));
- }
- public Object remove(int index) {
- return l.remove(index);
- }
- public boolean remove(Object o) {
- return l.remove(o);
- }
- public Object set(int index, Object o) {
- return l.set(index, o);
- }
- public List subList(int fromIndex, int toIndex) {
- return new UnmodifiableList(l.subList(fromIndex, toIndex));
- }
- }
-
- private static class UnmodifiableSet extends UnmodifiableCollection implements Set {
- public UnmodifiableSet(Set s) {
- super(s);
- }
- public boolean equals(Object o) {
- return c.equals(o);
- }
- public int hashCode() {
- return c.hashCode();
- }
- }
-
- private static class UnmodifiableSortedSet extends UnmodifiableSet
- implements SortedSet {
-
- // This is stored both here and in the superclass, to avoid excessive
- // casting.
- private SortedSet ss;
-
- public UnmodifiableSortedSet(SortedSet ss) {
- super(ss);
- this.ss = ss;
- }
-
- public Comparator comparator() {
- return ss.comparator();
- }
- public Object first() {
- return ss.first();
- }
- public Object last() {
- return ss.last();
- }
- public SortedSet headSet(Object toElement) {
- return new UnmodifiableSortedSet(ss.headSet(toElement));
- }
- public SortedSet tailSet(Object fromElement) {
- return new UnmodifiableSortedSet(ss.tailSet(fromElement));
- }
- public SortedSet subSet(Object fromElement, Object toElement) {
- return new UnmodifiableSortedSet(ss.subSet(fromElement, toElement));
- }
- }
-
- private static class UnmodifiableMap implements Map, Serializable {
-
- Map m;
-
- public UnmodifiableMap(Map m) {
- this.m = m;
- }
-
- public void clear() {
- throw new UnsupportedOperationException();
- }
- public boolean containsKey(Object key) {
- return m.containsKey(key);
- }
- public boolean containsValue(Object value) {
- return m.containsValue(value);
- }
-
- // This is one of the ickiest cases of nesting I've ever seen. It just
- // means "return an UnmodifiableSet, except that the iterator() method
- // returns an UnmodifiableIterator whos next() method returns an
- // unmodifiable wrapper around its normal return value".
- public Set entrySet() {
- return new UnmodifiableSet(m.entrySet()) {
- public Iterator iterator() {
- return new UnmodifiableIterator(c.iterator()) {
- public Object next() {
- final Map.Entry e = (Map.Entry)super.next();
- return new Map.Entry() {
- public Object getKey() {
- return e.getKey();
- }
- public Object getValue() {
- return e.getValue();
- }
- public Object setValue(Object value) {
- throw new UnsupportedOperationException();
- }
- public int hashCode() {
- return e.hashCode();
- }
- public boolean equals(Object o) {
- return e.equals(o);
- }
- };
- }
- };
- }
- };
- }
- public boolean equals(Object o) {
- return m.equals(o);
- }
- public Object get(Object key) {
- return m.get(key);
- }
- public Object put(Object key, Object value) {
- throw new UnsupportedOperationException();
- }
- public int hashCode() {
- return m.hashCode();
- }
- public boolean isEmpty() {
- return m.isEmpty();
- }
- public Set keySet() {
- return new UnmodifiableSet(m.keySet());
- }
- public void putAll(Map m) {
- throw new UnsupportedOperationException();
- }
- public Object remove(Object o) {
- throw new UnsupportedOperationException();
- }
- public int size() {
- return m.size();
- }
- public Collection values() {
- return new UnmodifiableCollection(m.values());
- }
- }
-
- private static class UnmodifiableSortedMap extends UnmodifiableMap
- implements SortedMap {
-
- // This is stored both here and in the superclass, to avoid excessive
- // casting.
- private SortedMap sm;
-
- public UnmodifiableSortedMap(SortedMap sm) {
- super(sm);
- this.sm = sm;
- }
-
- public Comparator comparator() {
- return sm.comparator();
- }
- public Object firstKey() {
- return sm.firstKey();
- }
- public Object lastKey() {
- return sm.lastKey();
- }
- public SortedMap headMap(Object toKey) {
- return new UnmodifiableSortedMap(sm.headMap(toKey));
- }
- public SortedMap tailMap(Object fromKey) {
- return new UnmodifiableSortedMap(sm.tailMap(fromKey));
- }
- public SortedMap subMap(Object fromKey, Object toKey) {
- return new UnmodifiableSortedMap(sm.subMap(fromKey, toKey));
- }
- }
-
- // All the "Synchronized" wrapper objects include a "sync" field which
- // specifies what object to synchronize on. That way, nested wrappers such as
- // UnmodifiableMap.keySet synchronize on the right things.
-
- private static class SynchronizedIterator implements Iterator {
- Object sync;
- private Iterator i;
-
- public SynchronizedIterator(Object sync, Iterator i) {
- this.sync = sync;
- this.i = i;
- }
-
- public Object next() {
- synchronized (sync) {
- return i.next();
- }
- }
- public boolean hasNext() {
- synchronized (sync) {
- return i.hasNext();
- }
- }
- public void remove() {
- synchronized (sync) {
- i.remove();
- }
- }
- }
-
- private static class SynchronizedListIterator extends SynchronizedIterator
- implements ListIterator {
-
- // This is stored both here and in the superclass, to avoid excessive
- // casting.
- private ListIterator li;
-
- public SynchronizedListIterator(Object sync, ListIterator li) {
- super(sync, li);
- this.li = li;
- }
-
- public boolean hasPrevious() {
- synchronized (sync) {
- return li.hasPrevious();
- }
- }
- public Object previous() {
- synchronized (sync) {
- return li.previous();
- }
- }
- public int nextIndex() {
- synchronized (sync) {
- return li.nextIndex();
- }
- }
- public int previousIndex() {
- synchronized (sync) {
- return li.previousIndex();
- }
- }
- public void add(Object o) {
- synchronized (sync) {
- li.add(o);
- }
- }
- public void set(Object o) {
- synchronized (sync) {
- li.set(o);
- }
- }
- }
-
- private static class SynchronizedCollection implements Collection, Serializable {
- Object sync;
- Collection c;
-
- public SynchronizedCollection(Collection c) {
- this.sync = this;
- this.c = c;
- }
- public SynchronizedCollection(Object sync, Collection c) {
- this.c = c;
- this.sync = sync;
- }
-
- public boolean add(Object o) {
- synchronized (sync) {
- return c.add(o);
- }
- }
- public boolean addAll(Collection col) {
- synchronized (sync) {
- return c.addAll(col);
- }
- }
- public void clear() {
- synchronized (sync) {
- c.clear();
- }
- }
- public boolean contains(Object o) {
- synchronized (sync) {
- return c.contains(o);
- }
- }
- public boolean containsAll(Collection c1) {
- synchronized (sync) {
- return c.containsAll(c1);
- }
- }
- public boolean isEmpty() {
- synchronized (sync) {
- return c.isEmpty();
- }
- }
- public Iterator iterator() {
- synchronized (sync) {
- return new SynchronizedIterator(sync, c.iterator());
- }
- }
- public boolean remove(Object o) {
- synchronized (sync) {
- return c.remove(o);
- }
- }
- public boolean removeAll(Collection col) {
- synchronized (sync) {
- return c.removeAll(col);
- }
- }
- public boolean retainAll(Collection col) {
- synchronized (sync) {
- return c.retainAll(col);
- }
- }
- public int size() {
- synchronized (sync) {
- return c.size();
- }
- }
- public Object[] toArray() {
- synchronized (sync) {
- return c.toArray();
- }
- }
- public Object[] toArray(Object[] a) {
- synchronized (sync) {
- return c.toArray(a);
- }
- }
- }
-
- private static class SynchronizedList extends SynchronizedCollection
- implements List {
-
- // This is stored both here and in the superclass, to avoid excessive
- // casting.
- List l;
-
- public SynchronizedList(Object sync, List l) {
- super(sync, l);
- this.l = l;
- }
- public SynchronizedList(List l) {
- super(l);
- }
-
- public void add(int index, Object o) {
- synchronized (sync) {
- l.add(index, o);
- }
- }
- public boolean addAll(int index, Collection c) {
- synchronized (sync) {
- return l.addAll(index, c);
- }
- }
- public boolean equals(Object o) {
- synchronized (sync) {
- return l.equals(o);
- }
- }
- public Object get(int index) {
- synchronized (sync) {
- return l.get(index);
- }
- }
- public int hashCode() {
- synchronized (sync) {
- return l.hashCode();
- }
- }
- public int indexOf(Object o) {
- synchronized (sync) {
- return l.indexOf(o);
- }
- }
- public int lastIndexOf(Object o) {
- synchronized (sync) {
- return l.lastIndexOf(o);
- }
- }
- public ListIterator listIterator() {
- synchronized (sync) {
- return new SynchronizedListIterator(sync, l.listIterator());
- }
- }
- public ListIterator listIterator(int index) {
- synchronized (sync) {
- return new SynchronizedListIterator(sync, l.listIterator(index));
- }
- }
- public Object remove(int index) {
- synchronized (sync) {
- return l.remove(index);
- }
- }
- public boolean remove(Object o) {
- synchronized (sync) {
- return l.remove(o);
- }
- }
- public Object set(int index, Object o) {
- synchronized (sync) {
- return l.set(index, o);
- }
- }
- public List subList(int fromIndex, int toIndex) {
- synchronized (sync) {
- return new SynchronizedList(l.subList(fromIndex, toIndex));
- }
- }
- }
-
- private static class SynchronizedSet extends SynchronizedCollection implements Set {
-
- public SynchronizedSet(Object sync, Set s) {
- super(sync, s);
- }
- public SynchronizedSet(Set s) {
- super(s);
- }
-
- public boolean equals(Object o) {
- synchronized (sync) {
- return c.equals(o);
- }
- }
- public int hashCode() {
- synchronized (sync) {
- return c.hashCode();
- }
- }
- }
-
- private static class SynchronizedSortedSet extends SynchronizedSet
- implements SortedSet {
-
- // This is stored both here and in the superclass, to avoid excessive
- // casting.
- private SortedSet ss;
-
- public SynchronizedSortedSet(Object sync, SortedSet ss) {
- super(sync, ss);
- this.ss = ss;
- }
- public SynchronizedSortedSet(SortedSet ss) {
- super(ss);
- }
-
- public Comparator comparator() {
- synchronized (sync) {
- return ss.comparator();
- }
- }
- public Object first() {
- synchronized (sync) {
- return ss.first();
- }
- }
- public Object last() {
- synchronized (sync) {
- return ss.last();
- }
- }
- public SortedSet headSet(Object toElement) {
- synchronized (sync) {
- return new SynchronizedSortedSet(sync, ss.headSet(toElement));
- }
- }
- public SortedSet tailSet(Object fromElement) {
- synchronized (sync) {
- return new SynchronizedSortedSet(sync, ss.tailSet(fromElement));
- }
- }
- public SortedSet subSet(Object fromElement, Object toElement) {
- synchronized (sync) {
- return new SynchronizedSortedSet(sync, ss.subSet(fromElement, toElement));
- }
- }
- }
-
- private static class SynchronizedMap implements Map, Serializable {
-
- Object sync;
- Map m;
-
- public SynchronizedMap(Object sync, Map m) {
- this.sync = sync;
- this.m = m;
- }
- public SynchronizedMap(Map m) {
- this.m = m;
- this.sync = this;
- }
-
- public void clear() {
- synchronized (sync) {
- m.clear();
- }
- }
- public boolean containsKey(Object key) {
- synchronized (sync) {
- return m.containsKey(key);
- }
- }
- public boolean containsValue(Object value) {
- synchronized (sync) {
- return m.containsValue(value);
- }
- }
-
- // This is one of the ickiest cases of nesting I've ever seen. It just
- // means "return an SynchronizedSet, except that the iterator() method
- // returns an SynchronizedIterator whos next() method returns a
- // synchronized wrapper around its normal return value".
- public Set entrySet() {
- synchronized (sync) {
- return new SynchronizedSet(sync, m.entrySet()) {
- public Iterator iterator() {
- synchronized (SynchronizedMap.this.sync) {
- return new SynchronizedIterator(SynchronizedMap.this.sync, c.iterator()) {
- public Object next() {
- synchronized (SynchronizedMap.this.sync) {
- final Map.Entry e = (Map.Entry)super.next();
- return new Map.Entry() {
- public Object getKey() {
- synchronized (SynchronizedMap.this.sync) {
- return e.getKey();
- }
- }
- public Object getValue() {
- synchronized (SynchronizedMap.this.sync) {
- return e.getValue();
- }
- }
- public Object setValue(Object value) {
- synchronized (SynchronizedMap.this.sync) {
- return e.setValue(value);
- }
- }
- public int hashCode() {
- synchronized (SynchronizedMap.this.sync) {
- return e.hashCode();
- }
- }
- public boolean equals(Object o) {
- synchronized (SynchronizedMap.this.sync) {
- return e.equals(o);
- }
- }
- };
- }
- }
- };
- }
- }
- };
- }
- }
- public boolean equals(Object o) {
- synchronized (sync) {
- return m.equals(o);
- }
- }
- public Object get(Object key) {
- synchronized (sync) {
- return m.get(key);
- }
- }
- public Object put(Object key, Object value) {
- synchronized (sync) {
- return m.put(key, value);
- }
- }
- public int hashCode() {
- synchronized (sync) {
- return m.hashCode();
- }
- }
- public boolean isEmpty() {
- synchronized (sync) {
- return m.isEmpty();
- }
- }
- public Set keySet() {
- synchronized (sync) {
- return new SynchronizedSet(sync, m.keySet());
- }
- }
- public void putAll(Map map) {
- synchronized (sync) {
- m.putAll(map);
- }
- }
- public Object remove(Object o) {
- synchronized (sync) {
- return m.remove(o);
- }
- }
-
- public int size() {
- synchronized (sync) {
- return m.size();
- }
- }
- public Collection values() {
- synchronized (sync) {
- return new SynchronizedCollection(sync, m.values());
- }
- }
- }
-
- private static class SynchronizedSortedMap extends SynchronizedMap
- implements SortedMap {
-
- // This is stored both here and in the superclass, to avoid excessive
- // casting.
- private SortedMap sm;
-
- public SynchronizedSortedMap(Object sync, SortedMap sm) {
- super(sync, sm);
- this.sm = sm;
- }
- public SynchronizedSortedMap(SortedMap sm) {
- super(sm);
- }
-
- public Comparator comparator() {
- synchronized (sync) {
- return sm.comparator();
- }
- }
- public Object firstKey() {
- synchronized (sync) {
- return sm.firstKey();
- }
- }
- public Object lastKey() {
- synchronized (sync) {
- return sm.lastKey();
- }
- }
- public SortedMap headMap(Object toKey) {
- return new SynchronizedSortedMap(sync, sm.headMap(toKey));
- }
- public SortedMap tailMap(Object fromKey) {
- return new SynchronizedSortedMap(sync, sm.tailMap(fromKey));
- }
- public SortedMap subMap(Object fromKey, Object toKey) {
- return new SynchronizedSortedMap(sync, sm.subMap(fromKey, toKey));
- }
- }
-}
diff --git a/jode/jode/util/Comparable.java b/jode/jode/util/Comparable.java
deleted file mode 100644
index f2a7315..0000000
--- a/jode/jode/util/Comparable.java
+++ /dev/null
@@ -1,51 +0,0 @@
-// This interface is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/*************************************************************************
-/* Comparable.java -- Interface for comparaing objects to obtain an ordering
-/*
-/* Copyright (c) 1998 by Free Software Foundation, Inc.
-/*
-/* This program is free software; you can redistribute it and/or modify
-/* it under the terms of the GNU Library General Public License as published
-/* by the Free Software Foundation, version 2. (see COPYING.LIB)
-/*
-/* This program is distributed in the hope that it will be useful, but
-/* WITHOUT ANY WARRANTY; without even the implied warranty of
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-/* GNU General Public License for more details.
-/*
-/* You should have received a copy of the GNU General Public License
-/* along with this program; if not, write to the Free Software Foundation
-/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/*************************************************************************/
-
-package jode.util;
-
-/**
- ** Interface for objects that can be ordering among other
- ** objects. The ordering can be total, such that two objects
- ** only compare equal if they are equal by the equals method, or
- ** partial such that this is not necessarily true. For
- ** example, a case-sensitive dictionary order comparison of Strings
- ** is total, but if it is case-insensitive it is partial, because
- ** "abc" and "ABC" compare as equal even though "abc".equals("ABC")
- ** returns false.
- **
- ** @author Geoff Berry
- **
- ** @since JDK1.2
- ** @see java.util.Comparator
- **/
-public interface Comparable
-{
- /**
- ** @return a negative integer if this object is less than
- ** o, zero if this object is equal to o
, or
- ** a positive integer if this object is greater than o
- **/
- public int compareTo( Object o );
-}
diff --git a/jode/jode/util/Comparator.java b/jode/jode/util/Comparator.java
deleted file mode 100644
index 9247812..0000000
--- a/jode/jode/util/Comparator.java
+++ /dev/null
@@ -1,62 +0,0 @@
-// This interface is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// Comparator.java -- Interface for objects that specify an ordering
-//
-// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-
-package jode.util;
-
-/**
- * Interface for objects that specify an ordering between objects. The ordering
- * can be total, such that two objects only compare equal if they are
- * equal by the equals method, or partial such that this is not
- * necessarily true. For example, a case-sensitive dictionary order comparison
- * of Strings is total, but if it is case-insensitive it is partial, because
- * "abc" and "ABC" compare as equal even though "abc".equals("ABC") returns
- * false.
- *
- * In general, Comparators should be Serializable, because when they are passed
- * to Serializable data structures such as SortedMap or SortedSet, the entire
- * data structure will only serialize correctly if the comparator is
- * Serializable.
- */
-public interface Comparator {
-
- /**
- * Return an integer that is negative, zero or positive depending on whether
- * the first argument is less than, equal to or greater than the second
- * according to this ordering. This method should obey the following contract:
- *
- * - if compare(a, b) < 0 then compare(b, a) > 0
- * - if compare(a, b) throws an exception, so does compare(b, a)
- * - if compare(a, b) < 0 and compare(b, c) < 0 then compare(a, c)
- * < 0
- * - if a.equals(b) or both a and b are null, then compare(a, b) == 0.
- * The converse need not be true, but if it is, this Comparator
- * specifies a total ordering.
- *
- *
- * @throws ClassCastException if the elements are not of types that can be
- * compared by this ordering.
- */
- int compare(Object o1, Object o2);
-}
diff --git a/jode/jode/util/ConcurrentModificationException.java b/jode/jode/util/ConcurrentModificationException.java
deleted file mode 100644
index 3e3bd4c..0000000
--- a/jode/jode/util/ConcurrentModificationException.java
+++ /dev/null
@@ -1,53 +0,0 @@
-// This interface is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// ConcurrentModificationException.java -- Data structure concurrently modified
-//
-// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-
-package jode.util;
-
-/**
- * Exception that is thrown by the collections classes when it is detected that
- * a modification has been made to a data structure when this is not allowed,
- * such as when a collection is structurally modified while an Iterator is
- * operating over it. In cases where this can be detected, a
- * ConcurrentModificationException will be thrown. An Iterator that detects this
- * condition is referred to as fail-fast.
- */
-public class ConcurrentModificationException extends RuntimeException {
-
- /**
- * Constructs a ConcurrentModificationException with no detail message.
- */
- public ConcurrentModificationException() {
- super();
- }
-
- /**
- * Constructs a ConcurrentModificationException with a detail message.
- *
- * @param detail the detail message for the exception
- */
- public ConcurrentModificationException(String detail) {
- super(detail);
- }
-}
diff --git a/jode/jode/util/HashMap.java b/jode/jode/util/HashMap.java
deleted file mode 100644
index f949f9b..0000000
--- a/jode/jode/util/HashMap.java
+++ /dev/null
@@ -1,876 +0,0 @@
-// This class is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// HashMap.java -- a class providing a basic hashtable data structure,
-// mapping Object --> Object; part of the JDK1.2 collections
-// API
-//
-// This is a JDK 1.2 compliant version of HashMap.java
-//
-// Copyright (c) 1998 by Jon A. Zeppieri (jon@eease.com),
-// Free Software Foundation, Inc.
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-package jode.util;
-import java.util.NoSuchElementException;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-/**
- * This class provides a hashtable-backed implementation of the
- * Map interface.
- *
- * It uses a hash-bucket approach; that is, hash
- * collisions are handled by linking the new node off of the
- * pre-existing node (or list of nodes). In this manner, techniques
- * such as linear probing (which can casue primary clustering) and
- * rehashing (which does not fit very well with Java's method of
- * precomputing hash codes) are avoided.
- *
- * Under ideal circumstances (no collisions, HashMap offers O(1)
- * performance on most operations (containsValue()
is,
- * of course, O(n)). In the worst case (all keys map to the same
- * hash code -- very unlikely), most operations are O(n).
- *
- * HashMap is part of the JDK1.2 Collections API. It differs from
- * Hashtable in that it accepts the null key and null values, and it
- * does not support "Enumeration views."
- *
- * @author Jon Zeppieri
- * @version $Revision$
- * @modified $Id$
- */
-public class HashMap extends AbstractMap
- implements Map, Cloneable, Serializable
-{
- // STATIC (CLASS) VARIABLES ------------------------------------------
-
- /**
- * the default capacity for an instance of HashMap -- I think this
- * is low, and perhaps it shoudl be raised; Sun's documentation mildly
- * suggests that this (11) is the correct value, though
- */
- private static final int DEFAULT_CAPACITY = 11;
-
- /** the default load factor of a HashMap */
- private static final float DEFAULT_LOAD_FACTOR = 0.75F;
-
- /** used internally to represent the null key */
- private static final HashMap.Null NULL_KEY = new HashMap.Null();
-
- /** used internally to parameterize the creation of set/collection views */
- private static final int KEYS = 0;
-
- /** used internally to parameterize the creation of set/collection views */
- private static final int VALUES = 1;
-
- /** used internally to parameterize the creation of set/collection views */
- private static final int ENTRIES = 2;
-
- private static final long serialVersionUID = 362498820763181265L;
-
- // INSTANCE VARIABLES -------------------------------------------------
-
- /** the capacity of this HashMap: denotes the size of the bucket array */
- transient int capacity;
-
- /** the size of this HashMap: denotes the number of key-value pairs */
- private transient int size;
-
- /** the load factor of this HashMap: used in computing the threshold
- * @serial
- */
- float loadFactor;
-
- /* the rounded product of the capacity and the load factor; when the number of
- * elements exceeds the threshold, the HashMap calls rehash()
- * @serial
- */
- private int threshold;
-
- /**
- * this data structure contains the actual key-value mappings; a
- * BucketList
is a lightweight linked list of "Buckets",
- * which, in turn, are linked nodes containing a key-value mapping
- * and a reference to the "next" Bucket in the list
- */
- private transient Bucket[] buckets;
-
- /**
- * counts the number of modifications this HashMap has undergone; used by Iterators
- * to know when to throw ConcurrentModificationExceptions (idea ripped-off from
- * Stuart Ballard's AbstractList implementation)
- */
- private transient int modCount;
-
-
- // CONSTRUCTORS ---------------------------------------------------------
-
- /**
- * construct a new HashMap with the default capacity and the default
- * load factor
- */
- public HashMap()
- {
- init(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR);
- }
-
- /**
- * construct a new HashMap with a specific inital capacity and load factor
- *
- * @param initialCapacity the initial capacity of this HashMap (>=0)
- * @param initialLoadFactor the load factor of this HashMap
- * (a misnomer, really, since the load factor of
- * a HashMap does not change)
- *
- * @throws IllegalArgumentException if (initialCapacity < 0) ||
- * (initialLoadFactor > 1.0) ||
- * (initialLoadFactor <= 0.0)
- */
- public HashMap(int initialCapacity, float initialLoadFactor)
- throws IllegalArgumentException
- {
- if (initialCapacity < 0 || initialLoadFactor <= 0 || initialLoadFactor > 1)
- throw new IllegalArgumentException();
- else
- init(initialCapacity, initialLoadFactor);
- }
-
- /**
- * construct a new HashMap with a specific inital capacity
- *
- * @param initialCapacity the initial capacity of this HashMap (>=0)
- *
- * @throws IllegalArgumentException if (initialCapacity < 0)
- */
- public HashMap(int initialCapacity)
- throws IllegalArgumentException
- {
- if (initialCapacity < 0)
- throw new IllegalArgumentException();
- else
- init(initialCapacity, DEFAULT_LOAD_FACTOR);
- }
-
- /**
- * construct a new HashMap from the given Map
- *
- * every element in Map t will be put into this new HashMap
- *
- * @param t a Map whose key / value pairs will be put into
- * the new HashMap. NOTE: key / value pairs
- * are not cloned in this constructor
- */
- public HashMap(Map t)
- {
- int mapSize = t.size() * 2;
- init(((mapSize > DEFAULT_CAPACITY) ? mapSize : DEFAULT_CAPACITY), DEFAULT_LOAD_FACTOR);
- putAll(t);
- }
-
-
- // PUBLIC METHODS ---------------------------------------------------------
-
- /** returns the number of kay-value mappings currently in this Map */
- public int size()
- {
- return size;
- }
-
- /** returns true if there are no key-value mappings currently in this Map */
- public boolean isEmpty()
- {
- return size == 0;
- }
-
- /** empties this HashMap of all elements */
- public void clear()
- {
- size = 0;
- modCount++;
- buckets = new Bucket[capacity];
- }
-
- /**
- * returns a shallow clone of this HashMap (i.e. the Map itself is cloned, but
- * its contents are not)
- */
- public Object clone()
- {
- Map.Entry entry;
- Iterator it = entrySet().iterator();
- HashMap clone = new HashMap(capacity, loadFactor);
- while (it.hasNext())
- {
- entry = (Map.Entry) it.next();
- clone.internalPut(entry.getKey(), entry.getValue());
- }
- return clone;
- }
-
- /** returns a "set view" of this HashMap's keys */
- public Set keySet()
- {
- return new HashMapSet(KEYS);
- }
-
- /** returns a "set view" of this HashMap's entries */
- public Set entrySet()
- {
- return new HashMapSet(ENTRIES);
- }
-
- /** returns a "collection view" (or "bag view") of this HashMap's values */
- public Collection values()
- {
- return new HashMapCollection();
- }
-
- /**
- * returns true if the supplied object equals (equals()
) a key
- * in this HashMap
- *
- * @param key the key to search for in this HashMap
- */
- public boolean containsKey(Object key)
- {
- return (internalGet(key) != null);
- }
-
- /**
- * returns true if this HashMap contains a value o
, such that
- * o.equals(value)
.
- *
- * @param value the value to search for in this Hashtable
- */
- public boolean containsValue(Object value)
- {
- int i;
- Bucket list;
-
- for (i = 0; i < capacity; i++)
- {
- list = buckets[i];
- if (list != null && list.containsValue(value))
- return true;
- }
- return false;
- }
-
- /*
- * return the value in this Hashtable associated with the supplied key, or null
- * if the key maps to nothing
- *
- * @param key the key for which to fetch an associated value
- */
- public Object get(Object key)
- {
- Map.Entry oResult = internalGet(key);
- return (oResult == null) ? null : oResult.getValue();
- }
-
- /**
- * puts the supplied value into the Map, mapped by the supplied key
- *
- * @param key the HashMap key used to locate the value
- * @param value the value to be stored in the HashMap
- */
- public Object put(Object key, Object value)
- {
- return internalPut(key, value);
- }
-
- /**
- * part of the Map interface; for each Map.Entry in t, the key / value pair is
- * added to this Map, using the put()
method -- this may not be
- * you want, so be warned (if you override the put() method, this could lead to
- * off behavior)
- *
- * @param t a Map whose key / value pairs will be added to this Hashtable
- */
- public void putAll(Map t)
- {
- Map.Entry entry;
- Iterator it = t.entrySet().iterator();
- while (it.hasNext())
- {
- entry = (Map.Entry) it.next();
- put(entry.getKey(), entry.getValue());
- }
- }
-
- /**
- * removes from the HashMap and returns the value which is mapped by the
- * supplied key; if the key maps to nothing, then the HashMap remains unchanged,
- * and null
is returned
- *
- * @param key the key used to locate the value to remove from the HashMap
- */
- public Object remove(Object key)
- {
- Bucket list;
- int index;
- Object result = null;
- if (size > 0)
- {
- index = hash(((key == null) ? NULL_KEY : key));
- list = buckets[index];
- if (list != null)
- {
- result = list.removeByKey(key);
- if (result != null)
- {
- size--;
- modCount++;
- if (list.first == null)
- buckets[index] = null;
- }
- }
- }
- return result;
- }
-
-
- // PRIVATE METHODS -----------------------------------------------------------
-
- /**
- * puts the given key-value pair into this HashMap; a private method is used
- * because it is called by the rehash() method as well as the put() method,
- * and if a subclass overrides put(), then rehash would do funky things
- * if it called put()
- *
- * @param key the HashMap key used to locate the value
- * @param value the value to be stored in the HashMap
- */
- private Object internalPut(Object key, Object value)
- {
- HashMapEntry entry;
- Bucket list;
- int hashIndex;
- Object oResult;
- Object oRealKey = ((key == null) ? NULL_KEY : key);
-
- modCount++;
- if (size == threshold)
- rehash();
- entry = new HashMapEntry(oRealKey, value);
- hashIndex = hash(oRealKey);
- list = buckets[hashIndex];
- if (list == null)
- {
- list = new Bucket();
- buckets[hashIndex] = list;
- }
- oResult = list.add(entry);
- if (oResult == null)
- {
- size++;
- return null;
- }
- else
- {
- return ((Map.Entry) oResult).getValue();
- }
- }
-
- /**
- * a private method, called by all of the constructors to initialize a new HashMap
- *
- * @param initialCapacity the initial capacity of this HashMap (>=0)
- * @param initialLoadFactor the load factor of this HashMap
- * (a misnomer, really, since the load factor of
- * a HashMap does not change)
- */
- private void init(int initialCapacity, float initialLoadFactor)
- {
- size = 0;
- modCount = 0;
- capacity = initialCapacity;
- loadFactor = initialLoadFactor;
- threshold = (int) ((float) capacity * loadFactor);
- buckets = new Bucket[capacity];
- }
-
- /** private -- simply hashes a non-null Object to its array index */
- private int hash(Object key)
- {
- return Math.abs(key.hashCode() % capacity);
- }
-
- /**
- * increases the size of the HashMap and rehashes all keys to new array indices;
- * this is called when the addition of a new value would cause size() > threshold
- */
- private void rehash()
- {
- int i;
- Bucket[] data = buckets;
- Bucket.Node node;
-
- modCount++;
- capacity = (capacity * 2) + 1;
- size = 0;
- threshold = (int) ((float) capacity * loadFactor);
- buckets = new Bucket[capacity];
- for (i = 0; i < data.length; i++)
- {
- if (data[i] != null)
- {
- node = data[i].first;
- while (node != null)
- {
- internalPut(node.getKey(), node.getValue());
- node = node.next;
- }
- }
- }
- }
-
- /**
- * a private method which does the "dirty work" (or some of it anyway) of fetching a value
- * with a key
- *
- * @param key the key for which to fetch an associated value
- */
- private Map.Entry internalGet(Object key)
- {
- Bucket list;
- if (size == 0)
- {
- return null;
- }
- else
- {
- list = buckets[hash(((key == null) ? NULL_KEY : key))];
- return (list == null) ? null : list.getEntryByKey(key);
- }
- }
-
- /**
- * a private method used by inner class HashMapSet to implement its own
- * contains(Map.Entry)
method; returns true if the supplied
- * key / value pair is found in this HashMap (again, using equals()
,
- * rather than ==
)
- *
- * @param entry a Map.Entry to match against key / value pairs in
- * this HashMap
- */
- private boolean containsEntry(Map.Entry entry)
- {
- Map.Entry oInternalEntry;
- if (entry == null)
- {
- return false;
- }
- else
- {
- oInternalEntry = internalGet(entry.getKey());
- return (oInternalEntry != null && oInternalEntry.equals(entry));
- }
- }
-
- /**
- * Serializes this object to the given stream.
- * @serialdata the capacity(int) that is the length of the
- * bucket array, the size(int) of the hash map are emitted
- * first. They are followed by size entries, each consisting of
- * a key (Object) and a value (Object).
- */
- private void writeObject(ObjectOutputStream s)
- throws IOException
- {
- // the fields
- s.defaultWriteObject();
-
- s.writeInt(capacity);
- s.writeInt(size);
- Iterator it = entrySet().iterator();
- while (it.hasNext())
- {
- Map.Entry oEntry = (Map.Entry) it.next();
- s.writeObject(oEntry.getKey());
- s.writeObject(oEntry.getValue());
- }
- }
-
- /**
- * Deserializes this object from the given stream.
- * @serialdata the capacity(int) that is the length of the
- * bucket array, the size(int) of the hash map are emitted
- * first. They are followed by size entries, each consisting of
- * a key (Object) and a value (Object).
- */
- private void readObject(ObjectInputStream s)
- throws IOException, ClassNotFoundException
- {
- // the fields
- s.defaultReadObject();
-
- capacity = s.readInt();
- int iLen = s.readInt();
- size = 0;
- modCount = 0;
- buckets = new Bucket[capacity];
-
- for (int i = 0; i < iLen; i++)
- {
- Object oKey = s.readObject();
- Object oValue = s.readObject();
- internalPut(oKey, oValue);
- }
- }
-
- // INNER CLASSES -------------------------------------------------------------
- // ---------------------------------------------------------------------------
-
- /**
- * an inner class providing a Set view of a HashMap; this implementation is
- * parameterized to view either a Set of keys or a Set of Map.Entry objects
- *
- * Note: a lot of these methods are implemented by AbstractSet, and would work
- * just fine without any meddling, but far greater efficiency can be gained by
- * overriding a number of them. And so I did.
- *
- * @author Jon Zeppieri
- * @version $Revision$
- * @modified $Id$
- */
- private class HashMapSet extends AbstractSet
- implements Set
- {
- /** the type of this Set view: KEYS or ENTRIES */
- private int setType;
-
- /** construct a new HashtableSet with the supplied view type */
- HashMapSet(int type)
- {
- setType = type;
- }
-
- /**
- * adding an element is unsupported; this method simply throws an exception
- *
- * @throws UnsupportedOperationException
- */
- public boolean add(Object o) throws UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * adding an element is unsupported; this method simply throws an exception
- *
- * @throws UnsupportedOperationException
- */
- public boolean addAll(Collection c) throws UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * clears the backing HashMap; this is a prime example of an overridden implementation
- * which is far more efficient than its superclass implementation (which uses an iterator
- * and is O(n) -- this is an O(1) call)
- */
- public void clear()
- {
- HashMap.this.clear();
- }
-
- /**
- * returns true if the supplied object is contained by this Set
- *
- * @param o an Object being testing to see if it is in this Set
- */
- public boolean contains(Object o)
- {
- if (setType == KEYS)
- return HashMap.this.containsKey(o);
- else
- return (o instanceof Map.Entry) ? HashMap.this.containsEntry((Map.Entry) o) : false;
- }
-
- /**
- * returns true if the backing HashMap is empty (which is the only case either a KEYS
- * Set or an ENTRIES Set would be empty)
- */
- public boolean isEmpty()
- {
- return HashMap.this.isEmpty();
- }
-
- /**
- * removes the supplied Object from the Set
- *
- * @param o the Object to be removed
- */
- public boolean remove(Object o)
- {
- if (setType == KEYS)
- return (HashMap.this.remove(o) != null);
- else
- return (o instanceof Map.Entry) ?
- (HashMap.this.remove(((Map.Entry) o).getKey()) != null) : false;
- }
-
- /** returns the size of this Set (always equal to the size of the backing Hashtable) */
- public int size()
- {
- return HashMap.this.size();
- }
-
- /** returns an Iterator over the elements of this Set */
- public Iterator iterator()
- {
- return new HashMapIterator(setType);
- }
- }
-
- /**
- * Like the above Set view, except this one if for values, which are not
- * guaranteed to be unique in a Map; this prvides a Bag of values
- * in the HashMap
- *
- * @author Jon Zeppieri
- * @version $Revision$
- * @modified $Id$
- */
- private class HashMapCollection extends AbstractCollection
- implements Collection
- {
- /** a trivial contructor for HashMapCollection */
- HashMapCollection()
- {
- }
-
- /**
- * adding elements is not supported by this Collection;
- * this method merely throws an exception
- *
- * @throws UnsupportedOperationException
- */
- public boolean add(Object o) throws UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * adding elements is not supported by this Collection;
- * this method merely throws an exception
- *
- * @throws UnsupportedOperationException
- */
- public boolean addAll(Collection c) throws UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-
- /** removes all elements from this Collection (and from the backing HashMap) */
- public void clear()
- {
- HashMap.this.clear();
- }
-
- /**
- * returns true if this Collection contains at least one Object which equals() the
- * supplied Object
- *
- * @param o the Object to compare against those in the Set
- */
- public boolean contains(Object o)
- {
- return HashMap.this.containsValue(o);
- }
-
- /** returns true IFF the Collection has no elements */
- public boolean isEmpty()
- {
- return HashMap.this.isEmpty();
- }
-
- /** returns the size of this Collection */
- public int size()
- {
- return HashMap.this.size();
- }
-
- /** returns an Iterator over the elements in this Collection */
- public Iterator iterator()
- {
- return new HashMapIterator(VALUES);
- }
- }
-
- /**
- * a class which implements the Iterator interface and is used for
- * iterating over HashMaps;
- * this implementation is parameterized to give a sequential view of
- * keys, values, or entries; it also allows the removal of elements,
- * as per the Javasoft spec.
- *
- * @author Jon Zeppieri
- * @version $Revision$
- * @modified $Id$
- */
- class HashMapIterator implements Iterator
- {
- /** the type of this Iterator: KEYS, VALUES, or ENTRIES */
- private int myType;
- /**
- * the number of modifications to the backing Hashtable for which
- * this Iterator can account (idea ripped off from Stuart Ballard)
- */
- private int knownMods;
- /** the location of our sequential "cursor" */
- private int position;
- /** the current index of the BucketList array */
- private int bucketIndex;
- /** a reference, originally null, to the specific Bucket our "cursor" is pointing to */
- private Bucket.Node currentNode;
- /** a reference to the current key -- used fro removing elements via the Iterator */
- private Object currentKey;
-
- /** construct a new HashtableIterator with the supllied type: KEYS, VALUES, or ENTRIES */
- HashMapIterator(int type)
- {
- myType = type;
- knownMods = HashMap.this.modCount;
- position = 0;
- bucketIndex = -1;
- currentNode = null;
- currentKey = null;
- }
-
- /**
- * Stuart Ballard's code: if the backing HashMap has been altered through anything
- * but this Iterator's remove()
method, we will give up right here,
- * rather than risking undefined behavior
- *
- * @throws ConcurrentModificationException
- */
- private void checkMod()
- {
- if (knownMods != HashMap.this.modCount)
- throw new ConcurrentModificationException();
- }
-
- /** returns true if the Iterator has more elements */
- public boolean hasNext()
- {
- checkMod();
- return position < HashMap.this.size();
- }
-
- /** returns the next element in the Iterator's sequential view */
- public Object next()
- {
- Bucket list = null;
- Object result;
- checkMod();
- try
- {
- while (currentNode == null)
- {
- while (list == null)
- list = HashMap.this.buckets[++bucketIndex];
- currentNode = list.first;
- }
- currentKey = currentNode.getKey();
- result = (myType == KEYS) ? currentKey :
- ((myType == VALUES) ? currentNode.getValue() : currentNode);
- currentNode = currentNode.next;
- }
- catch(Exception e)
- {
- throw new NoSuchElementException();
- }
- position++;
- return result;
- }
-
- /**
- * removes from the backing HashMap the last element which was fetched with the
- * next()
method
- */
- public void remove()
- {
- checkMod();
- if (currentKey == null)
- {
- throw new IllegalStateException();
- }
- else
- {
- HashMap.this.remove(currentKey);
- knownMods++;
- currentKey = null;
- }
- }
- }
-
- /**
- * a singleton instance of this class (HashMap.NULL_KEY)
- * is used to represent the null key in HashMap objects
- *
- * @author Jon Zeppieri
- * @version $Revision$
- * @modified $Id$
- */
- private static class Null
- {
- /** trivial constructor */
- Null()
- {
- }
- }
-
- /**
- * a HashMap version of Map.Entry -- one thing in this implementation is
- * HashMap-specific: if the key is HashMap.NULL_KEY, getKey() will return
- * null
- *
- * Simply, a key / value pair
- *
- * @author Jon Zeppieri
- * @version $Revision$
- * @modified $Id$
- */
- private static class HashMapEntry extends Bucket.Node implements Map.Entry
- {
- /** construct a new HashMapEntry with the given key and value */
- public HashMapEntry(Object key, Object value)
- {
- super(key, value);
- }
-
- /**
- * if the key == HashMap.NULL_KEY, null is returned, otherwise the actual
- * key is returned
- */
- public Object getKey()
- {
- Object oResult = super.getKey();
- return (oResult == HashMap.NULL_KEY) ? null : oResult;
- }
- }
- // EOF -----------------------------------------------------------------------
-}
diff --git a/jode/jode/util/HashSet.java b/jode/jode/util/HashSet.java
deleted file mode 100644
index 98b9bd1..0000000
--- a/jode/jode/util/HashSet.java
+++ /dev/null
@@ -1,238 +0,0 @@
-// This class is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// HashSet.java -- a class providing a HashMap-backet Set
-//
-// Copyright (c) 1998 by Jon A. Zeppieri (jon@eease.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-package jode.util;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-/**
- * This class provides a HashMap-backed implementation of the
- * Set interface.
- *
- * Each element in the Set is a key in the backing HashMap; each key
- * maps to a static token, denoting that the key does, in fact, exist.
- *
- * Most operations are O(1), assuming no hash collisions. In the worst
- * case (where all hases collide), operations are O(n).
- *
- * HashSet is a part of the JDK1.2 Collections API.
- *
- * @author Jon Zeppieri
- * @version $Revision$
- * @modified $Id$
- */
-public class HashSet extends AbstractSet
- implements Set, Cloneable, Serializable
-{
- // INSTANCE VARIABLES -------------------------------------------------
- /** the HashMap which backs this Set */
- private transient HashMap map;
- static final long serialVersionUID = -5024744406713321676L;
-
- // CONSTRUCTORS ---------------------------------------------------------
-
- /**
- * construct a new, empty HashSet whose backing HashMap has the default
- * capacity and loadFacor
- */
- public HashSet()
- {
- map = new HashMap();
- }
-
- /**
- * construct a new, empty HashSet whose backing HashMap has the supplied
- * capacity and the default load factor
- *
- * @param initialCapacity the initial capacity of the backing
- * HashMap
- */
- public HashSet(int initialCapacity)
- {
- map = new HashMap(initialCapacity);
- }
-
- /**
- * construct a new, empty HashSet whose backing HashMap has the supplied
- * capacity and load factor
- *
- * @param initialCapacity the initial capacity of the backing
- * HashMap
- * @param loadFactor the load factor of the backing HashMap
- */
- public HashSet(int initialCapacity, float loadFactor)
- {
- map = new HashMap(initialCapacity, loadFactor);
- }
-
- /**
- * construct a new HashSet with the same elements as are in the supplied
- * collection (eliminating any duplicates, of course; the backing HashMap
- * will have the default capacity and load factor
- *
- * @param c a collection containing the elements with
- * which this set will be initialized
- */
- public HashSet(Collection c)
- {
- map = new HashMap();
- addAll(c);
- }
-
-
- // PUBLIC METHODS ---------------------------------------------------------
-
- /**
- * adds the given Object to the set if it is not already in the Set,
- * returns true if teh element was added, false otherwise
- *
- * @param o the Object to add to this Set
- */
- public boolean add(Object o)
- {
- if (map.containsKey(o))
- {
- return false;
- }
- else
- {
- internalAdd(o);
- return true;
- }
- }
-
- /**
- * empties this Set of all elements; this is a fast operation [O(1)]
- */
- public void clear()
- {
- map.clear();
- }
-
- /**
- * returns a shallow copy of this Set (the Set itself is cloned; its
- * elements are not)
- */
- public Object clone()
- {
- Iterator it = iterator();
- HashSet clone = new HashSet(map.capacity, map.loadFactor);
- while (it.hasNext())
- clone.internalAdd(it.next());
- return clone;
- }
-
- /**
- * returns true if the supplied element is in this Set, false otherwise
- *
- * @param o the Object whose presence in this Set we are testing for
- */
- public boolean contains(Object o)
- {
- return map.containsKey(o);
- }
-
- /**
- * returns true if this set has no elements in it (size() == 0)
- */
- public boolean isEmpty()
- {
- return map.isEmpty();
- }
-
- /**
- * returns an Iterator over the elements of this Set; the Iterator allows
- * removal of elements
- */
- public Iterator iterator()
- {
- return map.keySet().iterator();
- }
-
- /**
- * removes the supplied Object from this Set if it is in the Set; returns
- * true if an element was removed, false otherwise
- */
- public boolean remove(Object o)
- {
- return (map.remove(o) != null);
- }
-
- /**
- * returns the number of elements in this Set
- */
- public int size()
- {
- return map.size();
- }
-
-
- // PRIVATE METHODS -----------------------------------------------------------
-
- /**
- * adds the supplied element to this Set; this private method is used
- * internally [clone()] instead of add(), because add() can be overridden
- * to do unexpected things
- *
- * @param o the Object to add to this Set
- */
- private void internalAdd(Object o)
- {
- map.put(o, Boolean.TRUE);
- }
-
- /** Serialize this Object in a manner which is binary-compatible with the JDK */
- private void writeObject(ObjectOutputStream s) throws IOException
- {
- Iterator it = iterator();
- s.writeInt(map.capacity);
- s.writeFloat(map.loadFactor);
- s.writeInt(size());
- while (it.hasNext())
- s.writeObject(it.next());
- }
-
- /** Deserialize this Object in a manner which is binary-compatible with the JDK */
- private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
- {
- int i, iSize, iCapacity;
- float fLoadFactor;
- Object oElement;
-
- iCapacity = s.readInt();
- fLoadFactor = s.readFloat();
- iSize = s.readInt();
-
- map = new HashMap(iCapacity, fLoadFactor);
-
- for (i = 0; i < iSize; i++)
- {
- oElement = s.readObject();
- internalAdd(oElement);
- }
- }
-}
diff --git a/jode/jode/util/Iterator.java b/jode/jode/util/Iterator.java
deleted file mode 100644
index 2984f16..0000000
--- a/jode/jode/util/Iterator.java
+++ /dev/null
@@ -1,66 +0,0 @@
-// This interface is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// Iterator.java -- Interface for iterating over collections
-//
-// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-
-package jode.util;
-
-/**
- * An object which iterates over a collection. An Iterator is used to return the
- * items once only, in sequence, by successive calls to the next method. It is
- * also possible to remove elements from the underlying collection by using the
- * optional remove method. Iterator is intended as a replacement for the
- * Enumeration interface of previous versions of Java, which did not have the
- * remove method and had less conveniently named methods.
- */
-public interface Iterator {
-
- /**
- * Tests whether there are elements remaining in the collection.
- *
- * @return true if there is at least one more element in the collection,
- * that is, if the next call to next will not throw NoSuchElementException.
- */
- boolean hasNext();
-
- /**
- * Obtain the next element in the collection.
- *
- * @return the next element in the collection
- * @exception NoSuchElementException if there are no more elements
- */
- Object next();
-
- /**
- * Remove from the underlying collection the last element returned by next.
- * This method can be called only once after each call to next. It does not
- * affect what will be returned by subsequent calls to next. This operation is
- * optional, it may throw an UnsupportedOperationException.
- *
- * @exception IllegalStateException if next has not yet been called or remove
- * has already been called since the last call to next.
- * @exception UnsupportedOperationException if this Iterator does not support
- * the remove operation.
- */
- void remove();
-}
diff --git a/jode/jode/util/LinkedList.java b/jode/jode/util/LinkedList.java
deleted file mode 100644
index 9fe6cce..0000000
--- a/jode/jode/util/LinkedList.java
+++ /dev/null
@@ -1,581 +0,0 @@
-// This class is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// LinkedList.java -- Linked list implementation of the List interface
-//
-// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-
-package jode.util;
-import java.util.NoSuchElementException;
-import java.io.Serializable;
-import java.io.ObjectOutputStream;
-import java.io.ObjectInputStream;
-import java.io.IOException;
-
-// TO DO:
-// ~ Doc comment for the class.
-// ~ Doc comments for the non-list methods.
-// ~ Some commenting on the Backing API and other general implementation notes.
-
-/**
- * Linked list implementation of the List interface.
- */
-public class LinkedList extends AbstractSequentialList
- implements Serializable, Cloneable
-{
- static final long serialVersionUID = 876323262645176354L;
-
- /**
- * An Entry containing the head (in the next field) and the tail (in the
- * previous field) of the list. The data field is null. If the list is empty,
- * both the head and the tail point to ends itself.
- */
- transient Entry ends = new Entry();
-
- /**
- * The current length of the list.
- */
- transient int size = 0;
-
- /**
- * Class to represent an entry in the list. Holds a single element.
- */
- private static class Entry {
-
- /**
- * The list element.
- */
- Object data = null;
-
- /**
- * The next entry in the list. If this is the last entry in the list, the
- * ends field of the list is held here.
- */
- Entry next;
-
- /**
- * The previous entry in the list. If this is the first entry in the list,
- * the ends field of the list is held here.
- */
- Entry previous;
-
- /**
- * Create an entry with given data and linkage.
- */
- Entry(Object d, Entry n, Entry p) {
- data = d;
- next = n;
- previous = p;
- }
-
- /**
- * Create an entry with no data and linking to itself, for use as the ends
- * field of the list.
- */
- Entry() {
- next = previous = this;
- }
-
- /**
- * Remove this entry.
- */
- Object remove() {
- previous.next = next;
- next.previous = previous;
- return data;
- }
- }
-
- private static interface Backing {
- void checkMod(int known);
- void upMod();
- void incSize(int by);
- void decSize(int by);
- }
-
- private final Backing back = new Backing() {
- public void checkMod(int known) {
- if (known != modCount) {
- throw new ConcurrentModificationException();
- }
- }
- public void upMod() {
- modCount++;
- }
- public void incSize(int by) {
- size += by;
- }
- public void decSize(int by) {
- size -= by;
- }
- };
-
- /** A ListIterator over the list. This class keeps track of its
- * position in the list, the size of the list, and the two list
- * entries it is between. This enables it to be used identically
- * for both the list itself and a sublist of the list.
- */
- private static class Iter implements ListIterator {
-
- /**
- * The index of the element that will be returned by next().
- */
- int pos;
-
- /**
- * The size of the backing list.
- */
- int size;
-
- /**
- * The entry containing the element that will be returned by next().
- */
- Entry next;
-
- /**
- * The entry containing the element that will be returned by previous().
- */
- Entry previous;
-
- /**
- * The entry that will be affected by remove() or set().
- */
- Entry recent;
-
- /**
- * The known value of the modCount of the backing list.
- */
- int knownMod;
-
- private final Backing b;
-
- /**
- * Create a new Iter starting at a given Entry within the list, at a given
- * position, in a list of given size.
- *
- * @param index the index to begin iteration.
- * @exception IndexOutOfBoundsException if index < 0 || index > size.
- */
- Iter(Backing backing, Entry n, int index, int s, int mc) {
- b = backing;
- pos = index;
- size = s;
- next = n;
- previous = n.previous;
- knownMod = mc;
- }
-
- public int nextIndex() {
- b.checkMod(knownMod);
- return pos;
- }
-
- public int previousIndex() {
- b.checkMod(knownMod);
- return pos - 1;
- }
-
- public boolean hasNext() {
- b.checkMod(knownMod);
- return pos < size;
- }
-
- public boolean hasPrevious() {
- b.checkMod(knownMod);
- return pos > 0;
- }
-
- public Object next() {
- b.checkMod(knownMod);
- if (pos >= size) {
- throw new NoSuchElementException();
- } else {
- pos++;
- recent = previous = next;
- next = recent.next;
- return recent.data;
- }
- }
-
- public Object previous() {
- b.checkMod(knownMod);
- if (pos <= 0) {
- throw new NoSuchElementException();
- } else {
- pos--;
- recent = next = previous;
- previous = recent.previous;
- return recent.data;
- }
- }
-
- public void remove() {
- b.checkMod(knownMod);
- if (recent == null) {
- throw new IllegalStateException();
- }
-
- // Adjust the position to before the removed element
- if (recent == previous) pos--;
-
- // Could use recent.remove() but this way is quicker, and also correctly
- // fixes next and previous.
- next = recent.previous.next = recent.next;
- previous = recent.next.previous = recent.previous;
- size--;
- b.decSize(1);
- knownMod++;
- b.upMod();
- recent = null;
- }
-
- public void add(Object o) {
- b.checkMod(knownMod);
- previous.next = next.previous = new Entry(o, next, previous);
-
- // New for 1.2RC1 - the semantics changed so that the iterator is
- // positioned *after* the new element.
- previous = next;
- next = previous.next;
- pos++;
-
- size++;
- b.incSize(1);
- knownMod++;
- b.upMod();
- recent = null;
- }
-
- public void set(Object o) {
- b.checkMod(knownMod);
- if (recent == null) {
- throw new IllegalStateException();
- }
- recent.data = o;
- }
- }
-
- /**
- * Obtain the Entry at a given position in a list. This method of course
- * takes linear time, but it is intelligent enough to take the shorter of the
- * paths to get to the Entry required. This implies that the first or last
- * entry in the list is obtained in constant time, which is a very desirable
- * property.
- * For speed and flexibility in which ranges are valid, range checking is not
- * done in this method, and if n is outside the range -1 <= n <= size, the
- * result will be wrong (but no exception will be thrown).
- * Note that you *can* obtain entries at position -1 and size, which are
- * equal to prehead and posttail respectively.
- * This method is static so that it can also be used in subList.
- *
- * @param n the number of the entry to get.
- * @param size the size of the list to get the entry in.
- * @param head the entry before the first element of the list (usually ends).
- * @param tail the entry after the last element of the list (usually ends).
- */
- static Entry getEntry(int n, int size, Entry head, Entry tail) {
-
- // n less than size/2, iterate from start
- if (n < size >> 1) {
- while (n-- >= 0) {
- head = head.next;
- }
- return head;
-
- // n greater than size/2, iterate from end
- } else {
- while (++n <= size) {
- tail = tail.previous;
- }
- return tail;
- }
- }
-
- /**
- * Create an empty linked list.
- */
- public LinkedList() {
- super();
- }
-
- /**
- * Create a linked list containing the elements, in order, of a given
- * collection.
- *
- * @param c the collection to populate this list from.
- */
- public LinkedList(Collection c) {
- super();
- // Note: addAll could be made slightly faster, but not enough so to justify
- // re-implementing it from scratch. It is just a matter of a relatively
- // small constant factor.
- addAll(c);
- }
-
- public Object getFirst() {
- if (size == 0) {
- throw new NoSuchElementException();
- }
- return ends.next.data;
- }
-
- public Object getLast() {
- if (size == 0) {
- throw new NoSuchElementException();
- }
- return ends.previous.data;
- }
-
- public Object removeFirst() {
- if (size == 0) {
- throw new NoSuchElementException();
- }
- size--;
- modCount++;
- return ends.next.remove();
- }
-
- public Object removeLast() {
- if (size == 0) {
- throw new NoSuchElementException();
- }
- size--;
- modCount++;
- return ends.previous.remove();
- }
-
- public void addFirst(Object o) {
- ends.next.previous = ends.next = new Entry(o, ends.next, ends);
- size++;
- modCount++;
- }
-
- public void addLast(Object o) {
- ends.previous.next = ends.previous = new Entry(o, ends, ends.previous);
- size++;
- modCount++;
- }
-
- /**
- * Obtain the number of elements currently in this list.
- *
- * @returns the number of elements currently in this list.
- */
- public int size() {
- return size;
- }
-
- /**
- * Remove a range of elements from this list.
- *
- * @param fromIndex the index, inclusive, to remove from.
- * @param toIndex the index, exclusive, to remove to.
- * @exception IndexOutOfBoundsException if fromIndex > toIndex || fromIndex <
- * 0 || toIndex > size().
- */
- // Note: normally removeRange is provided to allow efficient ways to
- // implement clear() on subLists. However, in this case clear on subLists
- // works anyway, so this implementation is included just for completeness
- // and because subclasses might try to use it.
- protected void removeRange(int fromIndex, int toIndex) {
- subList(fromIndex, toIndex).clear();
- }
-
- /**
- * Clear the list.
- */
- public void clear() {
- ends.next = ends.previous = ends;
- modCount++;
- size = 0;
- }
-
- /**
- * Obtain a ListIterator over this list, starting at a given index. The
- * ListIterator returned by this method supports the add, remove and set
- * methods.
- *
- * @param index the index of the element to be returned by the first call to
- * next(), or size() to be initially positioned at the end of the list.
- * @exception IndexOutOfBoundsException if index < 0 || index > size().
- */
- public ListIterator listIterator(int index) {
-
- // Check bounds
- if (index < 0 || index > size) {
- throw new IndexOutOfBoundsException();
- }
-
- return new Iter(back, getEntry(index, size, ends, ends),
- index, size, modCount);
- }
-
- /**
- * Obtain a List view of a subsection of this list, from fromIndex
- * (inclusive) to toIndex (exclusive). The returned list is modifiable in
- * every respect. Changes to the returned list are reflected in this list. If
- * this list is structurally modified is any way other than through the
- * returned list, any subsequent operations on the returned list will result
- * in a ConcurrentModificationException (that is, the returned list is
- * fail-fast).
- *
- * @param fromIndex the index that the returned list should start from
- * (inclusive).
- * @param toIndex the index that the returned list should go to (exclusive).
- * @returns a List backed by a subsection of this list.
- * @exception IndexOutOfBoundsException if fromIndex < 0 || toIndex > size()
- * || fromIndex > toIndex.
- */
- public List subList(int fromIndex, int toIndex) {
-
- // Check bounds
- if (fromIndex > toIndex || fromIndex < 0 || toIndex > size) {
- throw new IndexOutOfBoundsException();
- }
-
- return new SubLinkedList(back, getEntry(fromIndex - 1, size, ends, ends),
- getEntry(toIndex, size, ends, ends),
- toIndex - fromIndex);
- }
-
- private static class SubLinkedList extends AbstractSequentialList {
-
- Entry head; // entry before the beginning
- Entry tail; // entry after the end
- int size;
- private final Backing b;
-
- private final Backing back = new Backing() {
- public void checkMod(int known) {
- if (known != modCount) {
- throw new ConcurrentModificationException();
- }
- }
- public void upMod() {
- modCount++;
- }
- public void incSize(int by) {
- size += by;
- }
- public void decSize(int by) {
- size -= by;
- }
- };
-
- SubLinkedList(Backing backing, Entry h, Entry t, int s) {
- b = backing;
- head = h;
- tail = t;
- size = s;
- }
-
- public int size() {
- b.checkMod(this.modCount);
- return size;
- }
-
- public ListIterator listIterator(int index) {
- b.checkMod(this.modCount);
-
- // Check bounds
- if (index < 0 || index > size) {
- throw new IndexOutOfBoundsException();
- }
-
- return new Iter(back, getEntry(index, size, head, tail),
- index, size, modCount);
- }
-
- public void clear() {
- b.checkMod(this.modCount);
- head.next = tail;
- tail.previous = head;
- size = 0;
- b.decSize(size);
- modCount++;
- b.upMod();
- }
-
- // No removeRange because this class cannot be publically subclassed.
-
- public List subList(int fromIndex, int toIndex) {
- b.checkMod(this.modCount);
-
- // Check bounds
- if (fromIndex > toIndex || fromIndex < 0 || toIndex > size) {
- throw new IndexOutOfBoundsException();
- }
-
- return new SubLinkedList(back, getEntry(fromIndex - 1, size, head, tail),
- getEntry(toIndex, size, head, tail),
- toIndex - fromIndex);
- }
- }
-
- /**
- * Create a shallow copy of this LinkedList.
- * @return an object of the same class as this object, containing the
- * same elements in the same order.
- */
- public Object clone()
- {
- LinkedList copy;
- try
- {
- copy = (LinkedList) super.clone();
- }
- catch (CloneNotSupportedException ex)
- {
- throw new InternalError(ex.getMessage());
- }
- copy.size = 0;
- copy.ends = new Entry();
- copy.addAll(this);
- return copy;
- }
-
- /**
- * Serialize an object to a stream.
- * @serialdata the size of the list (int), followed by all the elements
- * (Object) in proper order.
- */
- private void writeObject(ObjectOutputStream s)
- throws IOException
- {
- s.writeInt(size);
- for (Iterator i = iterator(); i.hasNext(); )
- s.writeObject(i.next());
- }
-
- /**
- * Deserialize an object from a stream.
- * @serialdata the size of the list (int), followed by all the elements
- * (Object) in proper order.
- */
- private void readObject(ObjectInputStream s)
- throws IOException, ClassNotFoundException
- {
- int serialSize = s.readInt();
- ends = new Entry();
- for (int i=0; i< serialSize; i++)
- addLast(s.readObject());
- }
-}
diff --git a/jode/jode/util/List.java b/jode/jode/util/List.java
deleted file mode 100644
index 7e0c9ed..0000000
--- a/jode/jode/util/List.java
+++ /dev/null
@@ -1,331 +0,0 @@
-// This interface is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// List.java -- An ordered collection which allows indexed access
-//
-// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-
-// TO DO:
-// ~ Doc comment for the interface itself needs to be put into english.
-// ~ Some more @see clauses might be nice.
-
-package jode.util;
-
-/**
- * [This is what this doc comment will mention:
- * ~ Additional restrictions on some methods. Others included for completeness.
- * ~ ListIterator and what it can do
- * ~ Positional and iterated access
- * ~ search (but linear time)
- * ~ be careful when containing self as an element, because equals and hashCode
- * loop.]
- */
-public interface List extends Collection {
-
- /**
- * Insert an element into the list at a given position.
- *
- * @param index the location to insert the item.
- * @param o the object to insert.
- * @exception UnsupportedOperationException if this list does not support the
- * add operation.
- * @exception IndexOutOfBoundsException if index < 0 || index > size()
- * @exception ClassCastException if o cannot be added to this list due to its
- * type.
- * @exception IllegalArgumentException if o cannot be added to this list for
- * some other reason.
- */
- void add(int index, Object o);
-
- /**
- * Add an element to the end of the list.
- *
- * @param o the object to add.
- * @returns true, as Collection defines this method as returning true if the
- * list was modified as a result of this action, and it always is for a
- * list.
- * @exception UnsupportedOperationException if this list does not support the
- * add operation.
- * @exception ClassCastException if o cannot be added to this list due to its
- * type.
- * @exception IllegalArgumentException if o cannot be added to this list for
- * some other reason.
- */
- boolean add(Object o);
-
- /**
- * Insert the contents of a collection into the list at a given position.
- *
- * @param index the location to insert the collection.
- * @param c the collection to insert.
- * @returns true if the list was modified by this action, that is, if c is
- * non-empty.
- * @exception UnsupportedOperationException if this list does not support the
- * addAll operation.
- * @exception IndexOutOfBoundsException if index < 0 || index > size()
- * @exception ClassCastException if some element of c cannot be added to this
- * list due to its type.
- * @exception IllegalArgumentException if some element of c cannot be added
- * to this list for some other reason.
- */
- boolean addAll(int index, Collection c);
-
- /**
- * Add the contents of a collection to the end of the list.
- *
- * @param c the collection to add.
- * @returns true if the list was modified by this action, that is, if c is
- * non-empty.
- * @exception UnsupportedOperationException if this list does not support the
- * addAll operation.
- * @exception ClassCastException if some element of c cannot be added to this
- * list due to its type.
- * @exception IllegalArgumentException if some element of c cannot be added
- * to this list for some other reason.
- */
- boolean addAll(Collection c);
-
- /**
- * Clear the list, such that a subsequent call to isEmpty() would return
- * true.
- *
- * @exception UnsupportedOperationException if this list does not support the
- * clear operation.
- */
- void clear();
-
- /**
- * Test whether this list contains a given object as one of its elements.
- *
- * @param o the element to look for.
- * @returns true if this list contains an element e such that o ==
- * null ? e == null : o.equals(e)
.
- */
- boolean contains(Object o);
-
- /**
- * Test whether this list contains every element in a given collection.
- *
- * @param c the collection to test for.
- * @returns true if for every element o in c, contains(o) would return true.
- */
- boolean containsAll(Collection c);
-
- /**
- * Test whether this list is equal to another object. A List is defined to be
- * equal to an object if and only if that object is also a List, and the two
- * lists are equal. Two lists l1 and l2 are defined to be equal if and only
- * if l1.size() == l2.size()
, and for every integer n between 0
- * and l1.size() - 1
inclusive, l1.get(n) == null ?
- * l2.get(n) == null : l1.get(n).equals(l2.get(n))
.
- *
- * @param o the object to test for equality with this list.
- * @returns true if o is equal to this list.
- */
- boolean equals(Object o);
-
- /**
- * Get the element at a given index in this list.
- *
- * @param index the index of the element to be returned.
- * @returns the element at index index in this list.
- * @exception IndexOutOfBoundsException if index < 0 || index >= size()
- */
- Object get(int index);
-
- /**
- * Obtain a hash code for this list. In order to obey the general contract of
- * the hashCode method of class Object, this value is calculated as follows:
- *
- * hashCode = 1;
- * Iterator i = list.iterator();
- * while (i.hasNext()) {
- * Object obj = i.next();
- * hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode());
- * }
- *
- * This ensures that the general contract of Object.hashCode() is adhered to.
- *
- * @returns the hash code of this list.
- */
- int hashCode();
-
- /**
- * Obtain the first index at which a given object is to be found in this
- * list.
- *
- * @returns the least integer n such that o == null ? get(n) == null :
- * o.equals(get(n))
, or -1 if there is no such index.
- */
- int indexOf(Object o);
-
- /**
- * Test whether this list is empty, that is, if size() == 0.
- *
- * @returns true if this list contains no elements.
- */
- boolean isEmpty();
-
- /**
- * Obtain an Iterator over this list.
- *
- * @returns an Iterator over the elements of this list, in order.
- */
- Iterator iterator();
-
- /**
- * Obtain the last index at which a given object is to be found in this
- * list.
- *
- * @returns the greatest integer n such that o == null ? get(n) == null
- * : o.equals(get(n))
.
- */
- int lastIndexOf(Object o);
-
- /**
- * Obtain a ListIterator over this list, starting at the beginning.
- *
- * @returns a ListIterator over the elements of this list, in order, starting
- * at the beginning.
- */
- ListIterator listIterator();
-
- /**
- * Obtain a ListIterator over this list, starting at a given position.
- *
- * @param index the position, between 0 and size() inclusive, to begin the
- * iteration from.
- * @returns a ListIterator over the elements of this list, in order, starting
- * at index.
- * @exception IndexOutOfBoundsException if index < 0 || index > size()
- */
- ListIterator listIterator(int index);
-
- /**
- * Remove the element at a given position in this list.
- *
- * @param index the position within the list of the object to remove.
- * @returns the object that was removed.
- * @exception UnsupportedOperationException if this list does not support the
- * remove operation.
- * @exception IndexOutOfBoundsException if index < 0 || index > size()
- */
- Object remove(int index);
-
- /**
- * Remove the first occurence of an object from this list. That is, remove
- * the first element e such that o == null ? e == null :
- * o.equals(e)
.
- *
- * @param o the object to remove.
- * @returns true if the list changed as a result of this call, that is, if
- * the list contained at least one occurrence of o.
- * @exception UnsupportedOperationException if this list does not support the
- * remove operation.
- */
- boolean remove(Object o);
-
- /**
- * Remove all elements of a given collection from this list. That is, remove
- * every element e such that c.contains(e).
- *
- * @returns true if this list was modified as a result of this call.
- * @exception UnsupportedOperationException if this list does not support the
- * removeAll operation.
- */
- boolean removeAll(Collection c);
-
- /**
- * Remove all elements of this list that are not contained in a given
- * collection. That is, remove every element e such that !c.contains(e).
- *
- * @returns true if this list was modified as a result of this call.
- * @exception UnsupportedOperationException if this list does not support the
- * retainAll operation.
- */
- boolean retainAll(Collection c);
-
- /**
- * Replace an element of this list with another object.
- *
- * @param index the position within this list of the element to be replaced.
- * @param o the object to replace it with.
- * @returns the object that was replaced.
- * @exception UnsupportedOperationException if this list does not support the
- * set operation.
- * @exception IndexOutOfBoundsException if index < 0 || index >= size()
- * @exception ClassCastException if o cannot be added to this list due to its
- * type.
- * @exception IllegalArgumentException if o cannot be added to this list for
- * some other reason.
- */
- Object set(int index, Object o);
-
- /**
- * Get the number of elements in this list.
- *
- * @returns the number of elements in the list.
- */
- int size();
-
- /**
- * Obtain a List view of a subsection of this list, from fromIndex
- * (inclusive) to toIndex (exclusive). The returned list should be modifiable
- * if and only if this list is modifiable. Changes to the returned list
- * should be reflected in this list. If this list is structurally modified in
- * any way other than through the returned list, the result of any subsequent
- * operations on the returned list is undefined.
- *
- * @param fromIndex the index that the returned list should start from
- * (inclusive).
- * @param toIndex the index that the returned list should go to (exclusive).
- * @returns a List backed by a subsection of this list.
- * @exception IndexOutOfBoundsException if fromIndex < 0 || toIndex > size()
- * || fromIndex > toIndex.
- */
- List subList(int fromIndex, int toIndex);
-
- /**
- * Copy the current contents of this list into an array.
- *
- * @returns an array of type Object[] and length equal to the length of this
- * list, containing the elements currently in this list, in order.
- */
- Object[] toArray();
-
- /**
- * Copy the current contents of this list into an array. If the array passed
- * as an argument has length less than that of this list, an array of the
- * same run-time type as a, and length equal to the length of this list, is
- * allocated using Reflection. Otherwise, a itself is used. The elements of
- * this list are copied into it, and if there is space in the array, the
- * following element is set to null. The resultant array is returned.
- * Note: The fact that the following element is set to null is only useful
- * if it is known that this list does not contain any null elements.
- *
- * @param a the array to copy this list into.
- * @returns an array containing the elements currently in this list, in
- * order.
- * @exception ArrayStoreException if the type of any element of the
- * collection is not a subtype of the element type of a.
- */
- Object[] toArray(Object[] a);
-}
diff --git a/jode/jode/util/ListIterator.java b/jode/jode/util/ListIterator.java
deleted file mode 100644
index ad72b53..0000000
--- a/jode/jode/util/ListIterator.java
+++ /dev/null
@@ -1,145 +0,0 @@
-// This interface is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// ListIterator.java -- Extended Iterator for iterating over ordered lists
-//
-// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-
-package jode.util;
-
-/**
- * An extended version of Iterator to support the extra features of Lists. The
- * elements may be accessed in forward or reverse order, elements may be
- * replaced as well as removed, and new elements may be inserted, during the
- * traversal of the list.
- */
-public interface ListIterator extends Iterator {
-
- /**
- * Tests whether there are elements remaining in the list in the forward
- * direction.
- *
- * @return true if there is at least one more element in the list in the
- * forward direction, that is, if the next call to next will not throw
- * NoSuchElementException.
- */
- boolean hasNext();
-
- /**
- * Tests whether there are elements remaining in the list in the reverse
- * direction.
- *
- * @return true if there is at least one more element in the list in the
- * reverse direction, that is, if the next call to previous will not throw
- * NoSuchElementException.
- */
- boolean hasPrevious();
-
- /**
- * Obtain the next element in the list in the forward direction. Repeated
- * calls to next may be used to iterate over the entire list, or calls to next
- * and previous may be used together to go forwards and backwards. Alternating
- * calls to next and previous will return the same element.
- *
- * @return the next element in the list in the forward direction
- * @exception NoSuchElementException if there are no more elements
- */
- Object next();
-
- /**
- * Obtain the next element in the list in the reverse direction. Repeated
- * calls to previous may be used to iterate backwards over the entire list, or
- * calls to next and previous may be used together to go forwards and
- * backwards. Alternating calls to next and previous will return the same
- * element.
- *
- * @return the next element in the list in the reverse direction
- * @exception NoSuchElementException if there are no more elements
- */
- Object previous();
-
- /**
- * Find the index of the element that would be returned by a call to next.
- *
- * @return the index of the element that would be returned by a call to next,
- * or list.size() if the iterator is at the end of the list.
- */
- int nextIndex();
-
- /**
- * Find the index of the element that would be returned by a call to previous.
- *
- * @return the index of the element that would be returned by a call to
- * previous, or -1 if the iterator is at the beginning of the list.
- */
- int previousIndex();
-
- /**
- * Insert an element into the list at the current position of the iterator.
- * The element is inserted in between the element that would be returned by
- * previous and the element that would be returned by next. After the
- * insertion, a subsequent call to next is unaffected, but a call to
- * previous returns the item that was added. This operation is optional, it
- * may throw an UnsupportedOperationException.
- *
- * @param o the object to insert into the list
- * @exception ClassCastException the object is of a type which cannot be added
- * to this list
- * @exception IllegalArgumentException some other aspect of the object stops
- * it being added to this list
- * @exception UnsupportedOperationException if this ListIterator does not
- * support the add operation
- */
- void add(Object o);
-
- /**
- * Remove from the list the element last returned by a call to next or
- * previous. This method may only be called if neither add nor remove have
- * been called since the last call to next or previous. This operation is
- * optional, it may throw an UnsupportedOperationException.
- *
- * @exception IllegalStateException if neither next or previous have been
- * called, or if add or remove has been called since the last call to next
- * or previous.
- * @exception UnsupportedOperationException if this ListIterator does not
- * support the remove operation.
- */
- void remove();
-
- /**
- * Replace the element last returned by a call to next or previous with a
- * given object. This method may only be called if neither add nor remove have
- * been called since the last call to next or previous. This operation is
- * optional, it may throw an UnsupportedOperationException.
- *
- * @param o the object to replace the element with
- * @exception ClassCastException the object is of a type which cannot be added
- * to this list
- * @exception IllegalArgumentException some other aspect of the object stops
- * it being added to this list
- * @exception IllegalStateException if neither next or previous have been
- * called, or if add or remove has been called since the last call to next
- * or previous.
- * @exception UnsupportedOperationException if this ListIterator does not
- * support the set operation.
- */
- void set(Object o);
-}
diff --git a/jode/jode/util/Makefile.am b/jode/jode/util/Makefile.am
index 8074039..9e7849f 100644
--- a/jode/jode/util/Makefile.am
+++ b/jode/jode/util/Makefile.am
@@ -11,34 +11,7 @@ BUILD_CLASSPATH = $(top_srcdir):$(top_builddir):$(CLASSPATH):$(CLASSLIB)
MY_JAVA_FILES = \
SimpleMap.java \
SimpleSet.java \
- ArrayEnum.java \
- AbstractCollection.java \
- AbstractList.java \
- AbstractMap.java \
- AbstractSequentialList.java \
- AbstractSet.java \
- ArrayList.java \
- Arrays.java \
- BasicMapEntry.java \
- Bucket.java \
- Collection.java \
- Collections.java \
- Comparable.java \
- Comparator.java \
- ConcurrentModificationException.java \
- HashMap.java \
- HashSet.java \
- Iterator.java \
- LinkedList.java \
- List.java \
- ListIterator.java \
- Map.java \
- Set.java \
- SortedMap.java \
- SortedSet.java \
- TreeMap.java \
- TreeSet.java \
- UnsupportedOperationException.java
+ ArrayEnum.java
noinst_DATA = $(MY_JAVA_FILES:.java=.class)
EXTRA_DIST = $(MY_JAVA_FILES)
diff --git a/jode/jode/util/Map.java b/jode/jode/util/Map.java
deleted file mode 100644
index 6058c07..0000000
--- a/jode/jode/util/Map.java
+++ /dev/null
@@ -1,55 +0,0 @@
-// This interface is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// Map.java -- An object that maps keys to values
-//
-// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-
-// TO DO:
-// ~ Doc comments for everything.
-
-package jode.util;
-
-public interface Map
-{
- public void clear();
- public boolean containsKey(Object key);
- public boolean containsValue(Object value);
- public Set entrySet();
- public boolean equals(Object o);
- public Object get(Object key);
- public Object put(Object key, Object value);
- public int hashCode();
- public boolean isEmpty();
- public Set keySet();
- public void putAll(Map m);
- public Object remove(Object o);
- public int size();
- public Collection values();
-
- public static interface Entry {
- public Object getKey();
- public Object getValue();
- public Object setValue(Object value);
- public int hashCode();
- public boolean equals(Object o);
- }
-}
diff --git a/jode/jode/util/Set.java b/jode/jode/util/Set.java
deleted file mode 100644
index 69896e7..0000000
--- a/jode/jode/util/Set.java
+++ /dev/null
@@ -1,46 +0,0 @@
-// This interface is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// Set.java -- A collection that prohibits duplicates
-//
-// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-
-// TO DO:
-// ~ Doc comments for everything.
-
-package jode.util;
-
-public interface Set extends Collection {
- boolean add(Object o);
- boolean addAll(Collection c);
- void clear();
- boolean contains(Object o);
- boolean containsAll(Collection c);
- boolean equals(Object o);
- int hashCode();
- boolean isEmpty();
- Iterator iterator();
- boolean remove(Object o);
- boolean removeAll(Collection c);
- boolean retainAll(Collection c);
- int size();
- Object[] toArray();
-}
diff --git a/jode/jode/util/SimpleMap.java b/jode/jode/util/SimpleMap.java.in
similarity index 69%
rename from jode/jode/util/SimpleMap.java
rename to jode/jode/util/SimpleMap.java.in
index 3291dcc..b0ef122 100644
--- a/jode/jode/util/SimpleMap.java
+++ b/jode/jode/util/SimpleMap.java.in
@@ -18,12 +18,10 @@
*/
package jode.util;
-///#ifdef JDK12
-///import java.util.AbstractMap;
-///import java.util.Map;
-///import java.util.Iterator;
-///import java.util.Set;
-///#endif
+import @COLLECTIONS@.AbstractMap;
+import @COLLECTIONS@.Map;
+import @COLLECTIONS@.Iterator;
+import @COLLECTIONS@.Set;
/**
* This is a very simple map, using a set as backing.
@@ -49,11 +47,41 @@ public class SimpleMap extends AbstractMap {
return backing;
}
- public static class SimpleEntry extends BasicMapEntry {
+ public static class SimpleEntry implements Map.Entry {
+ Object key;
+ Object value;
+
public SimpleEntry(Object key, Object value) {
- super(key, value);
- }
- }
+ this.key = key;
+ this.value = value;
+ }
+
+ public Object getKey() {
+ return key;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public Object setValue(Object newValue) {
+ Object old = value;
+ value = newValue;
+ return old;
+ }
+
+ public int hashCode() {
+ return key.hashCode() ^ value.hashCode();
+ }
+
+ public boolean equals(Object o) {
+ if (o instanceof Map.Entry) {
+ Map.Entry e = (Map.Entry) o;
+ return key.equals(e.getKey()) && value.equals(e.getValue());
+ }
+ return false;
+ }
+ }
public Object put(Object key, Object value) {
for (Iterator i = backing.iterator();
diff --git a/jode/jode/util/SimpleSet.java b/jode/jode/util/SimpleSet.java.in
similarity index 96%
rename from jode/jode/util/SimpleSet.java
rename to jode/jode/util/SimpleSet.java.in
index f168b04..f71cbb1 100644
--- a/jode/jode/util/SimpleSet.java
+++ b/jode/jode/util/SimpleSet.java.in
@@ -18,10 +18,8 @@
*/
package jode.util;
-///#ifdef JDK12
-///import java.util.AbstractSet;
-///import java.util.Iterator;
-///#endif
+import @COLLECTIONS@.AbstractSet;
+import @COLLECTIONS@.Iterator;
public class SimpleSet extends AbstractSet implements Cloneable
{
diff --git a/jode/jode/util/SortedMap.java b/jode/jode/util/SortedMap.java
deleted file mode 100644
index 66fb250..0000000
--- a/jode/jode/util/SortedMap.java
+++ /dev/null
@@ -1,38 +0,0 @@
-// This interface is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// SortedMap.java -- A map that makes guarantees about the order of its keys
-//
-// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-
-// TO DO:
-// ~ Doc comments for everything.
-
-package jode.util;
-
-public interface SortedMap extends Map {
- Comparator comparator();
- Object firstKey();
- SortedMap headMap(Object toKey);
- Object lastKey();
- SortedMap subMap(Object fromKey, Object toKey);
- SortedMap tailMap(Object fromKey);
-}
diff --git a/jode/jode/util/SortedSet.java b/jode/jode/util/SortedSet.java
deleted file mode 100644
index 46c54bd..0000000
--- a/jode/jode/util/SortedSet.java
+++ /dev/null
@@ -1,38 +0,0 @@
-// This interface is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// SortedSet.java -- A set that makes guarantees about the order of its elements
-//
-// Copyright (c) 1998 by Stuart Ballard (stuart.ballard@mcmail.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-
-// TO DO:
-// ~ Doc comments for everything.
-
-package jode.util;
-
-public interface SortedSet extends Set {
- Comparator comparator();
- Object first();
- SortedSet headSet(Object toElement);
- Object last();
- SortedSet subSet(Object fromElement, Object toElement);
- SortedSet tailSet(Object fromElement);
-}
diff --git a/jode/jode/util/TreeMap.java b/jode/jode/util/TreeMap.java
deleted file mode 100644
index c20b255..0000000
--- a/jode/jode/util/TreeMap.java
+++ /dev/null
@@ -1,1380 +0,0 @@
-// This class is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// TreeMap.java -- a class providing a basic Red-Black Tree data structure,
-// mapping Object --> Object; part of the JDK1.2 collections
-// API
-//
-// This is a JDK 1.2 compliant version of TreeMap.java
-//
-// Copyright (c) 1998 by Jon A. Zeppieri (jon@eease.com),
-// Free Software Foundation, Inc.
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-package jode.util;
-
-import java.util.NoSuchElementException;
-
-import java.io.Serializable;
-import java.io.ObjectOutputStream;
-import java.io.ObjectInputStream;
-import java.io.IOException;
-
-/**
- * This class provides a red-black tree implementation of the SortedMap
- * interface. Elements in the Map will be sorted by either a user-provided
- * Comparator object, or by the natural ordering of the keys.
- *
- * The algorithms are adopted from Corman, Leiserson,
- * and Rivest's Introduction to Algorithms. In other words,
- * I cribbed from the same pseudocode as Sun. Any similarity
- * between my code and Sun's (if there is any -- I have never looked
- * at Sun's) is a result of this fact.
- *
- * TreeMap guarantees O(log n) insertion and deletion of elements. That
- * being said, there is a large enough constant coefficient in front of
- * that "log n" (overhead involved in keeping the tree
- * balanced), that TreeMap may not be the best choice for small
- * collections.
- *
- * TreeMap is a part of the JDK1.2 Collections API. Null keys are allowed
- * only if a Comparator is used which can deal with them. Null values are
- * always allowed.
- *
- * @author Jon Zeppieri
- * @version $Revision$
- * @modified $Id$
- */
-public class TreeMap extends AbstractMap
- implements SortedMap, Cloneable, Serializable
-{
- private static final int ENTRIES = 0;
- private static final int KEYS = 1;
- private static final int VALUES = 2;
-
- private static final int RED = -1;
- private static final int BLACK = 1;
-
- private static final RBNode NIL = new RBNode(null, null);
-
- /** The root node of this TreeMap */
- transient RBNode _oRoot;
-
- /** The size of this TreeMap */
- transient int _iSize;
-
- /** Number of modifications */
- transient int _iModCount;
-
- /** This TreeMap's comparator */
- Comparator comparator;
-
- static final long serialVersionUID = 919286545866124006L;
-
- /**
- * Instantiate a new TreeMap with no elements, using the keys'
- * natural ordering to sort.
- *
- * @see java.lang.Comparable
- */
- public TreeMap()
- {
- this((Comparator) null);
- }
-
- /**
- * Instantiate a new TreeMap with no elements, using the provided
- * comparator to sort.
- *
- * @param oComparator a Comparator object, used to sort
- * the keys of this SortedMap
- */
- public TreeMap(Comparator oComparator)
- {
- _oRoot = NIL;
- _iSize = 0;
- _iModCount = 0;
- comparator = oComparator;
- }
-
- /**
- * Instantiate a new TreeMap, initializing it with all of the
- * elements in the provided Map. The elements will be sorted
- * using the natural ordering of the keys.
- *
- * @param oMap a Map, whose keys will be put into
- * this TreeMap
- *
- * @throws ClassCastException if the keys in the provided
- * Map do not implement
- * Comparable
- *
- * @see java.lang.Comparable
- */
- public TreeMap(Map oMap)
- {
- this((Comparator) null);
- putAll(oMap);
- }
-
- /**
- * Instantiate a new TreeMap, initializing it with all of the
- * elements in the provided SortedMap. The elements will be sorted
- * using the same method as in the provided SortedMap.
- */
- public TreeMap(SortedMap oSortedMap)
- {
- this(oSortedMap.comparator());
-
- Map.Entry[] arEntries = new Map.Entry[oSortedMap.size()];
- Iterator itElements = oSortedMap.entrySet().iterator();
- int i = 0;
-
- while (itElements.hasNext())
- arEntries[i++] = (Map.Entry) itElements.next();
-
- _iSize = i;
- putAllLinear(arEntries);
- }
-
- public void clear()
- {
- _oRoot = NIL;
- _iSize = 0;
- _iModCount++;
- }
-
- public Object clone()
- {
- TreeMap oClone;
-
- try
- {
- oClone = (TreeMap) super.clone();
- oClone._oRoot = _oRoot;
- oClone.comparator = comparator;
- oClone._iSize = _iSize;
- oClone._iModCount = 0;
- }
- catch(CloneNotSupportedException e)
- {
- oClone = null;
- }
-
- return oClone;
- }
-
- public Comparator comparator()
- {
- return comparator;
- }
-
- public boolean containsKey(Object oKey)
- {
- return (treeSearch(_oRoot, comparator, oKey) != NIL);
- }
-
- public boolean containsValue(Object oValue)
- {
- RBNode oNode = _oRoot;
- Object oCurrentValue;
-
- while (oNode != NIL)
- {
- oCurrentValue = oNode.getValue();
-
- if (((oValue == null) && (oCurrentValue == null))
- || oValue.equals(oCurrentValue))
- return true;
-
- oNode = treeSuccessor(oNode);
- }
- return false;
- }
-
- public Set entrySet()
- {
- return new TreeMapSet(this, ENTRIES);
- }
-
- public Object firstKey()
- {
- try
- {
- return treeMin(_oRoot).getKey();
- }
- catch(NullPointerException e)
- {
- throw new NoSuchElementException("TreeMap is empty");
- }
- }
-
- public Object get(Object oKey)
- {
- RBNode oNode = treeSearch(_oRoot, comparator, oKey);
- return (oNode != NIL) ? oNode.getValue() : null;
- }
-
- public SortedMap headMap(Object oToKey)
- {
- if (keyInClosedMaxRange(comparator, oToKey, null))
- return new SubTreeMap(null, oToKey);
- else
- throw new IllegalArgumentException(getArgumentError("create a headMap",
- null, null));
- }
-
- public Set keySet()
- {
- return new TreeMapSet(this, KEYS);
- }
-
- public Object lastKey()
- {
- try
- {
- return treeMax(_oRoot).getKey();
- }
- catch(NullPointerException e)
- {
- throw new NoSuchElementException("TreeMap is empty");
- }
- }
-
- public Object put(Object oKey, Object oValue)
- {
- Map.Entry oEntry = rbInsert(this, comparator, new RBNode(oKey, oValue));
- if (oEntry == NIL)
- _iSize++;
- _iModCount++;
- return ((oEntry == NIL) ? null : oEntry.getValue());
- }
-
- public void putAll(Map oMap)
- {
- Iterator itEntries = oMap.entrySet().iterator();
- Map.Entry oEntry;
-
- while (itEntries.hasNext())
- {
- oEntry = (Map.Entry) itEntries.next();
- put(oEntry.getKey(), oEntry.getValue());
- }
- }
-
- public Object remove(Object oKey)
- {
- RBNode oResult = treeSearch(_oRoot, comparator, oKey);
-
- if (oResult != NIL)
- {
- oResult = rbDelete(this, oResult);
- _iSize--;
- _iModCount++;
- return oResult.getValue();
- }
- else
- {
- return null;
- }
- }
-
- public int size()
- {
- return _iSize;
- }
-
- public SortedMap subMap(Object oFromKey, Object oToKey)
- {
- if (compare(comparator, oFromKey, oToKey) < 0)
- return new SubTreeMap(oFromKey, oToKey);
- else
- throw new IllegalArgumentException(getArgumentError("create a subMap",
- null, null));
- }
-
- public SortedMap tailMap(Object oFromKey)
- {
- if (keyInMinRange(comparator, oFromKey, null))
- return new SubTreeMap(oFromKey, null);
- else
- throw new IllegalArgumentException(getArgumentError("create a tailMap",
- null, null));
- }
-
- public Collection values()
- {
- return new TreeMapCollection(this);
- }
-
- void putAllLinear(Map.Entry[] arEntries)
- {
- int iHeight;
- double dHeight;
- boolean boComplete;
-
- dHeight = Math.pow((double) arEntries.length, (double) 0.5);
- iHeight = (int) dHeight;
- boComplete = (dHeight == ((double) iHeight));
-
- _oRoot = buildTree(arEntries, iHeight, boComplete, 0, 0, arEntries.length);
- }
-
- private void writeObject(ObjectOutputStream oOut) throws IOException
- {
- RBNode oNode = treeMin(_oRoot);
- oOut.defaultWriteObject();
-
- oOut.writeInt(_iSize);
-
- while (oNode != NIL)
- {
- oOut.writeObject(oNode.getKey());
- oOut.writeObject(oNode.getValue());
- oNode = treeSuccessor(oNode);
- }
- }
-
- private void readObject(ObjectInputStream oIn)
- throws IOException, ClassNotFoundException
- {
- int i;
- Map.Entry[] arEntries;
- oIn.defaultReadObject();
- _iSize = oIn.readInt();
- _iModCount = 0;
-
- arEntries = new Map.Entry[_iSize];
- for (i = 0; i < _iSize; i++)
- arEntries[i] = new RBNode(oIn.readObject(), oIn.readObject());
-
- putAllLinear(arEntries);
- }
-
-
- private static final RBNode buildTree(Map.Entry[] arEntries, int iHeight,
- boolean boComplete, int iCurrentTier,
- int iStart, int iStop)
- {
- RBNode oNewTree;
- int iRootIndex;
-
- if (iStart == iStop)
- {
- return NIL;
- }
- else
- {
- iRootIndex = (iStop + iStart) / 2;
-
- oNewTree = new RBNode(arEntries[iRootIndex].getKey(),
- arEntries[iRootIndex].getValue());
- oNewTree._oLeft = buildTree(arEntries, iHeight, boComplete,
- (iCurrentTier + 1), iStart, iRootIndex);
- oNewTree._oRight = buildTree(arEntries, iHeight, boComplete,
- (iCurrentTier + 1),
- (iRootIndex + 1), iStop);
-
- if ((!boComplete) &&
- ((iHeight % 2) == 1) &&
- (iCurrentTier >= (iHeight - 2)))
- oNewTree._iColor = (iCurrentTier == (iHeight - 1)) ? RED : BLACK;
- else
- oNewTree._iColor = ((iCurrentTier % 2) == 1) ? RED : BLACK;
-
- if (oNewTree._oLeft != NIL)
- oNewTree._oLeft._oParent = oNewTree;
- if (oNewTree._oRight != NIL)
- oNewTree._oRight._oParent = oNewTree;
- return oNewTree;
- }
- }
-
- static final int compare(Comparator oComparator, Object oOne, Object oTwo)
- {
- return ((oComparator == null)
- ? ((Comparable) oOne).compareTo(oTwo)
- : oComparator.compare(oOne, oTwo));
- }
-
- static final boolean keyInMinRange(Comparator oComparator,
- Object oKey,
- Object oMinKey)
- {
- return ((oMinKey == null) ||
- (compare(oComparator, oMinKey, oKey) <= 0));
- }
-
- static final boolean keyInMaxRange(Comparator oComparator,
- Object oKey,
- Object oMaxKey)
- {
- return ((oMaxKey == null) ||
- (compare(oComparator, oMaxKey, oKey) > 0));
- }
-
- static final boolean keyInClosedMaxRange(Comparator oComparator,
- Object oKey,
- Object oMaxKey)
- {
- return ((oMaxKey == null) ||
- (compare(oComparator, oMaxKey, oKey) >= 0));
- }
-
- static final boolean keyInRange(Comparator oComparator,
- Object oKey,
- Object oMinKey,
- Object oMaxKey)
- {
- return (keyInMinRange(oComparator, oKey, oMinKey) &&
- keyInMaxRange(oComparator, oKey, oMaxKey));
- }
-
- static final boolean keyInClosedRange(Comparator oComparator,
- Object oKey,
- Object oMinKey,
- Object oMaxKey)
- {
- return (keyInMinRange(oComparator, oKey, oMinKey) &&
- keyInClosedMaxRange(oComparator, oKey, oMaxKey));
- }
-
- static final RBNode treeSearch(RBNode oRoot,
- Comparator oComparator,
- Object oKey)
- {
- int iCompareResult;
-
- while (oRoot != NIL)
- {
- iCompareResult = compare(oComparator, oKey, oRoot.getKey());
- if (iCompareResult == 0)
- return oRoot;
- else if (iCompareResult < 0)
- oRoot = oRoot._oLeft;
- else
- oRoot = oRoot._oRight;
- }
- return oRoot;
- }
-
- static final RBNode treeMin(RBNode oRoot)
- {
- while (oRoot._oLeft != NIL)
- oRoot = oRoot._oLeft;
-
- return oRoot;
- }
-
- static final RBNode treeMinConstrained(RBNode oRoot,
- Comparator oComparator,
- Object oMinKey,
- Object oMaxKey)
- {
- int iCompare;
- RBNode oCurrent;
-
- do
- {
- oCurrent = oRoot;
- iCompare = compare(oComparator, oMinKey, oCurrent.getKey());
-
- if (iCompare == 0)
- return oRoot;
- else
- oRoot = (iCompare < 0) ? oCurrent._oLeft : oCurrent._oRight;
- }
- while (oRoot != NIL);
-
- if (iCompare > 0)
- oCurrent = treeSuccessor(oCurrent);
-
- return oCurrent;
- }
-
- static final RBNode treeMax(RBNode oRoot)
- {
- while (oRoot._oRight != NIL)
- oRoot = oRoot._oRight;
-
- return oRoot;
- }
-
- static final RBNode treeMaxConstrained(RBNode oRoot,
- Comparator oComparator,
- Object oMinKey,
- Object oMaxKey)
- {
- int iCompare;
- RBNode oCurrent;
-
- do
- {
- oCurrent = oRoot;
- iCompare = compare(oComparator, oMaxKey, oCurrent.getKey());
-
- if (iCompare == 0)
- return oRoot;
- else
- oRoot = (iCompare < 0) ? oCurrent._oLeft : oCurrent._oRight;
- }
- while (oRoot != NIL);
-
- if (iCompare < 0)
- oCurrent = treePredecessor(oCurrent);
-
- return oCurrent;
- }
-
- static RBNode lowerBound(RBNode oRoot, Comparator oComparator,
- Object oMinKey, Object oMaxKey)
- {
- return ((oMinKey != null)
- ? treeMinConstrained(oRoot, oComparator, oMinKey, oMaxKey)
- : treeMin(oRoot));
- }
-
- static RBNode upperBound(RBNode oRoot, Comparator oComparator,
- Object oMinKey, Object oMaxKey)
- {
- return ((oMaxKey != null)
- ? treeMaxConstrained(oRoot, oComparator, oMinKey, oMaxKey)
- : NIL);
- }
-
- static final RBNode treeSuccessor(RBNode oNode)
- {
- RBNode oParent;
-
- if (oNode._oRight != NIL)
- return treeMin(oNode._oRight);
-
- oParent = oNode._oParent;
- while ((oParent != NIL) && (oNode == oParent._oRight))
- {
- oNode = oParent;
- oParent = oParent._oParent;
- }
-
- return oParent;
- }
-
- static final RBNode treePredecessor(RBNode oNode)
- {
- RBNode oParent;
-
- if (oNode._oLeft != NIL)
- return treeMax(oNode._oLeft);
-
- oParent = oNode._oParent;
- while ((oParent != NIL) && (oNode == oParent._oLeft))
- {
- oNode = oParent;
- oParent = oParent._oParent;
- }
-
- return oParent;
- }
-
- static final String getArgumentError(String stType,
- Object oMinKey,
- Object oMaxKey)
- {
- return ("Attempt to " + stType + " outside of range [" +
- oMinKey.toString() + ", " + oMaxKey.toString() + ").");
- }
-
- private static final RBNode treeInsert(TreeMap oTree,
- Comparator oComparator,
- RBNode oNewNode)
- {
- int iCompareResult;
- Object oNewKey = oNewNode.getKey();
- RBNode oParent = NIL;
- RBNode oRoot = oTree._oRoot;
- RBNode oResult;
-
- while (oRoot != NIL)
- {
- oParent = oRoot;
-
- iCompareResult = compare(oComparator, oNewKey, oRoot.getKey());
-
- if (iCompareResult == 0)
- {
- oResult = new RBNode(oRoot.getKey(), oRoot.getValue());
- oRoot.key = oNewNode.key;
- oRoot.value = oNewNode.value;
- return oResult;
- }
- else
- {
- oRoot = (iCompareResult < 0) ? oRoot._oLeft : oRoot._oRight;
- }
- }
-
- oNewNode._oParent = oParent;
- if (oParent == NIL)
- oTree._oRoot = oNewNode;
- else if (compare(oComparator, oNewKey, oParent.getKey()) < 0)
- oParent._oLeft = oNewNode;
- else
- oParent._oRight = oNewNode;
-
- return oRoot;
- }
-
- private static final void leftRotate(TreeMap oTree, RBNode oNode)
- {
- RBNode oChild = oNode._oRight;
- oNode._oRight = oChild._oLeft;
-
- if (oChild._oLeft != NIL)
- oChild._oLeft._oParent = oNode;
-
- oChild._oParent = oNode._oParent;
-
- if (oNode._oParent == NIL)
- oTree._oRoot = oChild;
- else if (oNode == oNode._oParent._oLeft)
- oNode._oParent._oLeft = oChild;
- else
- oNode._oParent._oRight = oChild;
-
- oChild._oLeft = oNode;
- oNode._oParent = oChild;
- }
-
- private static final void rightRotate(TreeMap oTree, RBNode oNode)
- {
- RBNode oChild = oNode._oLeft;
- oNode._oLeft = oChild._oRight;
-
- if (oChild._oRight != NIL)
- oChild._oRight._oParent = oNode;
-
- oChild._oParent = oNode._oParent;
-
- if (oNode._oParent == NIL)
- oTree._oRoot = oChild;
- else if (oNode == oNode._oParent._oRight)
- oNode._oParent._oRight = oChild;
- else
- oNode._oParent._oLeft = oChild;
-
- oChild._oRight = oNode;
- oNode._oParent = oChild;
- }
-
- private static final RBNode rbInsert(TreeMap oTree,
- Comparator oComparator,
- RBNode oNode)
- {
- RBNode oUncle;
- RBNode oResult = treeInsert(oTree, oComparator, oNode);
-
- if (oResult == NIL)
- {
- oNode._iColor = RED;
- while ((oNode != oTree._oRoot) && (oNode._oParent._iColor == RED))
- {
- if (oNode._oParent == oNode._oParent._oParent._oRight)
- {
- oUncle = oNode._oParent._oParent._oRight;
- if (oUncle._iColor == RED)
- {
- oNode._oParent._iColor = BLACK;
- oUncle._iColor = BLACK;
- oNode._oParent._oParent._iColor = RED;
- oNode = oNode._oParent._oParent;
- }
- else
- {
- if (oNode == oNode._oParent._oRight)
- {
- oNode = oNode._oParent;
- leftRotate(oTree, oNode);
- }
- oNode._oParent._iColor = BLACK;
- oNode._oParent._oParent._iColor = RED;
- rightRotate(oTree, oNode._oParent._oParent);
- }
- }
- else
- {
- oUncle = oNode._oParent._oParent._oLeft;
- if (oUncle._iColor == RED)
- {
- oNode._oParent._iColor = BLACK;
- oUncle._iColor = BLACK;
- oNode._oParent._oParent._iColor = RED;
- oNode = oNode._oParent._oParent;
- }
- else
- {
- if (oNode == oNode._oParent._oLeft)
- {
- oNode = oNode._oParent;
- rightRotate(oTree, oNode);
- }
- oNode._oParent._iColor = BLACK;
- oNode._oParent._oParent._iColor = RED;
- leftRotate(oTree, oNode._oParent._oParent);
- }
- }
- }
- }
- oTree._oRoot._iColor = BLACK;
- return oResult;
- }
-
- private static final RBNode rbDelete(TreeMap oTree, RBNode oNode)
- {
- RBNode oSplice;
- RBNode oChild;
- RBNode oSentinelParent = NIL;
- RBNode oResult = oNode;
-
- oSplice = (((oNode._oLeft == NIL) || (oNode._oRight == NIL))
- ? oNode : treeSuccessor(oNode));
- oChild = (oSplice._oLeft != NIL) ? oSplice._oLeft : oSplice._oRight;
-
- oChild._oParent = oSplice._oParent;
-
- if (oSplice._oParent == NIL)
- oTree._oRoot = oChild;
- else if (oSplice == oSplice._oParent._oLeft)
- oSplice._oParent._oLeft = oChild;
- else
- oSplice._oParent._oRight = oChild;
-
- if (oSplice != oNode)
- {
- oResult = new RBNode(oNode.getKey(), oNode.getValue());
- oNode.key = oSplice.key;
- oNode.value = oSplice.value;
- }
-
- if (oSplice._iColor == BLACK)
- rbDeleteFixup(oTree, oChild);
-
- return oResult;
- }
-
- private static final void rbDeleteFixup(TreeMap oTree, RBNode oNode)
- {
- RBNode oSibling;
-
- while ((oNode != oTree._oRoot) && (oNode._iColor == BLACK))
- {
- if (oNode == oNode._oParent._oLeft)
- {
- oSibling = oNode._oParent._oRight;
- if (oSibling._iColor == RED)
- {
- oSibling._iColor = BLACK;
- oNode._oParent._iColor = RED;
- leftRotate(oTree, oNode._oParent);
- oSibling = oNode._oParent._oRight;
- }
- if ((oSibling._oLeft._iColor == BLACK) &&
- (oSibling._oRight._iColor == BLACK))
- {
- oSibling._iColor = RED;
- oNode = oNode._oParent;
- }
- else
- {
- if (oSibling._oRight._iColor == BLACK)
- {
- oSibling._oLeft._iColor = BLACK;
- oSibling._iColor = RED;
- rightRotate(oTree, oSibling);
- oSibling = oNode._oParent._oRight;
- }
- oSibling._iColor = oNode._oParent._iColor;
- oNode._oParent._iColor = BLACK;
- oSibling._oRight._iColor = BLACK;
- leftRotate(oTree, oNode._oParent);
- oNode = oTree._oRoot;
- }
- }
- else
- {
- oSibling = oNode._oParent._oLeft;
- if (oSibling._iColor == RED)
- {
- oSibling._iColor = BLACK;
- oNode._oParent._iColor = RED;
- rightRotate(oTree, oNode._oParent);
- oSibling = oNode._oParent._oLeft;
- }
- if ((oSibling._oRight._iColor == BLACK) &&
- (oSibling._oLeft._iColor == BLACK))
- {
- oSibling._iColor = RED;
- oNode = oNode._oParent;
- }
- else
- {
- if (oSibling._oLeft._iColor == BLACK)
- {
- oSibling._oRight._iColor = BLACK;
- oSibling._iColor = RED;
- leftRotate(oTree, oSibling);
- oSibling = oNode._oParent._oLeft;
- }
- oSibling._iColor = oNode._oParent._iColor;
- oNode._oParent._iColor = BLACK;
- oSibling._oLeft._iColor = BLACK;
- rightRotate(oTree, oNode._oParent);
- oNode = oTree._oRoot;
- }
- }
- }
-
- oNode._iColor = BLACK;
- }
-
- private static class RBNode extends BasicMapEntry implements Map.Entry
- {
- int _iColor;
- RBNode _oLeft;
- RBNode _oRight;
- RBNode _oParent;
-
- RBNode(Object oKey, Object oValue)
- {
- super(oKey, oValue);
- _oLeft = NIL;
- _oRight = NIL;
- _oParent = NIL;
- _iColor = BLACK;
- }
- }
-
- private class TreeMapSet extends AbstractSet implements Set
- {
- SortedMap _oMap;
- int _iType;
-
- TreeMapSet(SortedMap oMap, int iType)
- {
- _oMap = oMap;
- _iType = iType;
- }
-
- /**
- * adding an element is unsupported; this method simply
- * throws an exception
- *
- * @throws UnsupportedOperationException
- */
- public boolean add(Object oObject) throws UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * adding an element is unsupported; this method simply throws
- * an exception
- *
- * @throws UnsupportedOperationException
- */
- public boolean addAll(Collection oCollection)
- throws UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * clears the backing TreeMap; this is a prime example of an
- * overridden implementation which is far more efficient than
- * its superclass implementation (which uses an iterator
- * and is O(n) -- this is an O(1) call)
- */
- public void clear()
- {
- _oMap.clear();
- }
-
- /**
- * returns true if the supplied object is contained by this Set
- *
- * @param oObject an Object being testing to see if it is in this Set
- */
- public boolean contains(Object oObject)
- {
- Map.Entry oEntry;
- Object oKey;
- Object oInputValue;
- Object oMapValue;
-
- if (_iType == KEYS)
- {
- return _oMap.containsKey(oObject);
- }
- else if (oObject instanceof Map.Entry)
- {
- oEntry = (Map.Entry) oObject;
- oKey = oEntry.getKey();
-
- if (_oMap.containsKey(oKey))
- {
- oInputValue = oEntry.getValue();
- oMapValue = _oMap.get(oKey);
- return ((oInputValue == null)
- ? (oMapValue == null)
- : (oInputValue.equals(oMapValue)));
- }
- }
- return false;
- }
-
- /**
- * returns true if the backing Map is empty (which is the only
- * case either a KEYS Set or an ENTRIES Set would be empty)
- */
- public boolean isEmpty()
- {
- return _oMap.isEmpty();
- }
-
- /**
- * removes the supplied Object from the Set
- *
- * @param o the Object to be removed
- */
- public boolean remove(Object oObject)
- {
- if (_iType == KEYS)
- return (_oMap.remove(oObject) != null);
- else
- return (oObject instanceof Map.Entry)
- ? (_oMap.remove(((Map.Entry) oObject).getKey()) != null)
- : false;
- }
-
- /** returns the size of this Set (always equal to the size of
- * the backing Hashtable) */
- public int size()
- {
- return _oMap.size();
- }
-
- /** returns an Iterator over the elements in this set */
- public Iterator iterator()
- {
- return new TreeMapIterator(_oMap, _iType);
- }
- }
-
- private class TreeMapCollection extends AbstractCollection
- implements Collection
- {
- private SortedMap _oMap;
-
- TreeMapCollection(SortedMap oMap)
- {
- _oMap = oMap;
- }
-
- /**
- * adding elements is not supported by this Collection;
- * this method merely throws an exception
- *
- * @throws UnsupportedOperationException
- */
- public boolean add(Object oObject) throws UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-
- /**
- * adding elements is not supported by this Collection;
- * this method merely throws an exception
- *
- * @throws UnsupportedOperationException
- */
- public boolean addAll(Collection oCollection)
- throws UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-
- /** removes all elements from this Collection (and from the
- * backing TreeMap) */
- public void clear()
- {
- _oMap.clear();
- }
-
- /**
- * returns true if this Collection contains at least one Object
- * which equals() the supplied Object
- *
- * @param o the Object to compare against those in the Set
- */
- public boolean contains(Object oObject)
- {
- return _oMap.containsValue(oObject);
- }
-
- /** returns true IFF the Collection has no elements */
- public boolean isEmpty()
- {
- return _oMap.isEmpty();
- }
-
- /** returns the size of this Collection */
- public int size()
- {
- return _oMap.size();
- }
-
- /** returns an Iterator over the elements in this Collection */
- public Iterator iterator()
- {
- return new TreeMapIterator(_oMap, VALUES);
- }
- }
-
- private class TreeMapIterator implements Iterator
- {
- SortedMap _oMap;
- int _iType;
- int _iKnownMods;
- RBNode _oFirst;
- RBNode _oLast;
- RBNode _oPrev;
-
- TreeMapIterator(SortedMap oMap, int iType)
- {
- TreeMap oBackingMap = TreeMap.this;
-
- _oMap = oMap;
- _iType = iType;
- _iKnownMods = oBackingMap._iModCount;
- _oPrev = NIL;
-
- if (_oMap.isEmpty())
- {
- _oFirst = NIL;
- }
- else
- {
- _oFirst = TreeMap.treeSearch(oBackingMap._oRoot,
- oBackingMap.comparator,
- _oMap.firstKey());
- _oLast = TreeMap.treeSearch(oBackingMap._oRoot,
- oBackingMap.comparator,
- _oMap.lastKey());
- }
- }
-
-
- /**
- * Stuart Ballard's code: if the backing TreeMap has been altered
- * through anything but this Iterator's remove()
- * method, we will give up right here, rather than risking undefined
- * behavior
- *
- * @throws ConcurrentModificationException
- */
- private void checkMod()
- {
- if (_iKnownMods < TreeMap.this._iModCount)
- throw new ConcurrentModificationException();
- }
-
- public boolean hasNext()
- {
- checkMod();
- return (_oFirst != NIL);
- }
-
- public Object next()
- {
- checkMod();
-
- RBNode oResult = _oFirst;
-
- if (oResult == NIL)
- throw new NoSuchElementException();
- else if (oResult == _oLast)
- _oFirst = NIL;
- else
- _oFirst = TreeMap.treeSuccessor(_oFirst);
-
- _oPrev = oResult;
-
- return ((_iType == KEYS)
- ? oResult.getKey()
- : ((_iType == VALUES)
- ? oResult.getValue()
- : oResult));
- }
-
- public void remove()
- {
- checkMod();
-
- Object oKey;
-
- if (_oPrev == NIL)
- {
- throw new IllegalStateException("No previous call to next(), " +
- "or remove() has already been " +
- "called on this iteration.");
- }
- else
- {
- oKey = _oPrev.getKey();
- if (_oMap.containsKey(oKey))
- {
- _oMap.remove(oKey);
- _iKnownMods++;
- }
- _oPrev = NIL;
- }
- }
- }
-
-
- private class SubTreeMap extends AbstractMap implements SortedMap
- {
- Object _oMinKey;
- Object _oMaxKey;
-
- SubTreeMap(Object oMinKey, Object oMaxKey)
- {
- _oMinKey = oMinKey;
- _oMaxKey = oMaxKey;
- }
-
- public void clear()
- {
- Object oMaxKey;
- RBNode oMin = TreeMap.lowerBound(TreeMap.this._oRoot,
- TreeMap.this.comparator,
- _oMinKey, _oMaxKey);
- RBNode oMax = TreeMap.upperBound(TreeMap.this._oRoot,
- TreeMap.this.comparator,
- _oMinKey, _oMaxKey);
- oMaxKey = oMax.getKey();
- while ((oMin != NIL) &&
- ((oMax == NIL) ||
- (TreeMap.compare(TreeMap.this.comparator,
- oMin.getKey(), oMaxKey) < 0)))
- {
- TreeMap.this.remove(oMin.getKey());
- oMin = TreeMap.treeSuccessor(oMin);
- }
- }
-
- public boolean containsKey(Object oKey)
- {
- return
- (keyInRange(TreeMap.this.comparator, oKey, _oMinKey, _oMaxKey) &&
- TreeMap.this.containsKey(oKey));
- }
-
- public boolean containsValue(Object oValue)
- {
- Object oCurrentValue;
- Object oMaxKey;
- RBNode oMin = TreeMap.lowerBound(TreeMap.this._oRoot,
- TreeMap.this.comparator,
- _oMinKey, _oMaxKey);
- RBNode oMax = TreeMap.upperBound(TreeMap.this._oRoot,
- TreeMap.this.comparator,
- _oMinKey, _oMaxKey);
-
- oMaxKey = oMax.getKey();
- while ((oMin != NIL) &&
- ((oMax == NIL) ||
- (TreeMap.compare(TreeMap.this.comparator,
- oMin.getKey(), oMaxKey) < 0)))
- {
- oCurrentValue = oMin.getValue();
-
- if (((oValue == null) && (oCurrentValue == null))
- || oValue.equals(oCurrentValue))
- return true;
- oMin = treeSuccessor(oMin);
- }
- return false;
- }
-
- public Object get(Object oKey)
- {
- if (keyInRange(TreeMap.this.comparator, oKey, _oMinKey, _oMaxKey))
- return TreeMap.this.get(oKey);
- else
- return null;
- }
-
- public Object put(Object oKey, Object oValue)
- {
- if (keyInRange(TreeMap.this.comparator, oKey, _oMinKey, _oMaxKey))
- return TreeMap.this.put(oKey, oValue);
- else
- throw new IllegalArgumentException(getArgumentError("insert an entry",
- _oMinKey,
- _oMaxKey));
- }
-
- public void putAll(Map oMap)
- {
- Map.Entry oEntry;
- Iterator itElements = oMap.entrySet().iterator();
-
- while (itElements.hasNext())
- {
- oEntry = (Map.Entry) itElements.next();
- put(oEntry.getKey(), oEntry.getValue());
- }
- }
-
- public Object remove(Object oKey)
- {
- if (keyInRange(TreeMap.this.comparator, oKey, _oMinKey, _oMaxKey))
- return TreeMap.this.remove(oKey);
- else
- throw new IllegalArgumentException(getArgumentError("remove an entry",
- _oMinKey,
- _oMaxKey));
- }
-
- public int size()
- {
- int iCount = 0;
- Object oMaxKey;
- RBNode oMin = TreeMap.lowerBound(TreeMap.this._oRoot,
- TreeMap.this.comparator,
- _oMinKey, _oMaxKey);
- RBNode oMax = TreeMap.upperBound(TreeMap.this._oRoot,
- TreeMap.this.comparator,
- _oMinKey, _oMaxKey);
-
- oMaxKey = oMax.getKey();
- while ((oMin != NIL) &&
- ((oMax == NIL) ||
- (TreeMap.compare(TreeMap.this.comparator,
- oMin.getKey(), oMaxKey) < 0)))
- {
- iCount++;
- oMin = TreeMap.treeSuccessor(oMin);
- }
-
- return iCount;
- }
-
- public Set entrySet()
- {
- return new TreeMapSet(this, ENTRIES);
- }
-
- public Set keySet()
- {
- return new TreeMapSet(this, KEYS);
- }
-
- public Collection values()
- {
- return new TreeMapCollection(this);
- }
-
- public Comparator comparator()
- {
- return TreeMap.this.comparator;
- }
-
- public Object firstKey()
- {
- RBNode oFirst = TreeMap.lowerBound(TreeMap.this._oRoot,
- TreeMap.this.comparator,
- _oMinKey, _oMaxKey);
-
- return (oFirst != NIL) ? oFirst.getKey() : null;
- }
-
- public Object lastKey()
- {
- RBNode oLast;
-
- if (_oMaxKey == null)
- {
- oLast = TreeMap.treeMax(TreeMap.this._oRoot);
- return (oLast != NIL) ? oLast.getKey() : null;
- }
- else
- {
- oLast = TreeMap.treeMaxConstrained(TreeMap.this._oRoot,
- TreeMap.this.comparator,
- _oMinKey, _oMaxKey);
- return (oLast != NIL) ? TreeMap.treePredecessor(oLast).getKey() : null;
- }
- }
-
- public SortedMap subMap(Object oFromKey, Object oToKey)
- {
- if ((compare(comparator, oFromKey, oToKey) < 0) &&
- keyInMinRange(TreeMap.this.comparator,
- oFromKey, _oMinKey) &&
- keyInClosedMaxRange(TreeMap.this.comparator,
- oFromKey, _oMaxKey) &&
- keyInMinRange(TreeMap.this.comparator,
- oToKey, _oMinKey) &&
- keyInClosedMaxRange(TreeMap.this.comparator,
- oToKey, _oMaxKey))
- return new SubTreeMap(oFromKey, oToKey);
- else
- throw new IllegalArgumentException(getArgumentError("create a subMap",
- _oMinKey,
- _oMaxKey));
- }
-
- public SortedMap headMap(Object oToKey)
- {
- if (keyInMinRange(TreeMap.this.comparator,
- oToKey, _oMinKey) &&
- keyInClosedMaxRange(TreeMap.this.comparator,
- oToKey, _oMaxKey))
- return new SubTreeMap(_oMinKey, oToKey);
- else
- throw new IllegalArgumentException(getArgumentError("create a subMap",
- _oMinKey,
- _oMaxKey));
- }
-
- public SortedMap tailMap(Object oFromKey)
- {
- if (keyInMinRange(TreeMap.this.comparator,
- oFromKey, _oMinKey) &&
- keyInClosedMaxRange(TreeMap.this.comparator,
- oFromKey, _oMaxKey))
- return new SubTreeMap(oFromKey, _oMaxKey);
- else
- throw new IllegalArgumentException(getArgumentError("create a subMap",
- _oMinKey,
- _oMaxKey));
- }
- }
-}
diff --git a/jode/jode/util/TreeSet.java b/jode/jode/util/TreeSet.java
deleted file mode 100644
index 1ccf585..0000000
--- a/jode/jode/util/TreeSet.java
+++ /dev/null
@@ -1,331 +0,0 @@
-// This class is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/////////////////////////////////////////////////////////////////////////////
-// TreeSet.java -- a class providing a TreeMap-backet SortedSet
-//
-// Copyright (c) 1999 by Jon A. Zeppieri (jon@eease.com)
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Library General Public License as published
-// by the Free Software Foundation, version 2. (see COPYING.LIB)
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public License
-// along with this program; if not, write to the Free Software Foundation
-// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/////////////////////////////////////////////////////////////////////////////
-package jode.util;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-/**
- * This class provides a TreeMap-backed implementation of the
- * SortedSet interface.
- *
- * Each element in the Set is a key in the backing TreeMap; each key
- * maps to a static token, denoting that the key does, in fact, exist.
- *
- * Most operations are O(log n).
- *
- * TreeSet is a part of the JDK1.2 Collections API.
- *
- * @author Jon Zeppieri
- * @version $Revision$
- * @modified $Id$
- */
-
-public class TreeSet extends AbstractSet
- implements SortedSet, Cloneable, Serializable
-{
- // INSTANCE VARIABLES -------------------------------------------------
-
- /** The TreeMap which backs this Set */
- transient SortedMap _oMap;
- static final long serialVersionUID = -2479143000061671589L;
-
-
- // CONSTRUCTORS -------------------------------------------------------
-
- /**
- * Construct a new TreeSet whose backing TreeMap using the "natural" ordering
- * of keys.
- */
- public TreeSet()
- {
- this((Comparator) null);
- }
-
- /**
- * Construct a new TreeSet whose backing TreeMap uses the supplied
- * Comparator.
- *
- * @param oComparator the Comparator this Set will use
- */
- public TreeSet(Comparator oComparator)
- {
- _oMap = new TreeMap(oComparator);
- }
-
- /**
- * Construct a new TreeSet whose backing TreeMap uses the "natural"
- * orering of the keys and which contains all of the elements in the
- * supplied Collection.
- *
- * @param oCollection the new Set will be initialized with all
- * of the elements in this Collection
- */
- public TreeSet(Collection oCollection)
- {
- this((Comparator) null);
- addAll(oCollection);
- }
-
- /**
- * Construct a new TreeSet, using the same key ordering as the supplied
- * SortedSet and containing all of the elements in the supplied SortedSet.
- * This constructor runs in linear time.
- *
- * @param oSortedSet the new TreeSet will use this SortedSet's
- * comparator and will initialize itself
- * with all of the elements in this SortedSet
- */
- public TreeSet(SortedSet oSortedSet)
- {
- this(oSortedSet.comparator());
-
- TreeMap oMap = (TreeMap) _oMap;
- int i = 0;
- Map.Entry[] arEntries = new Map.Entry[oSortedSet.size()];
- Iterator itEntries = oSortedSet.iterator();
-
- while (itEntries.hasNext())
- arEntries[i++] = new BasicMapEntry(itEntries.next(), Boolean.TRUE);
-
- oMap._iSize = i;
- oMap.putAllLinear(arEntries);
- }
-
- TreeSet(SortedMap oMap)
- {
- _oMap = oMap;
- }
-
- // METHODS -----------------------------------------------------------
-
- /**
- * Adds the spplied Object to the Set if it is not already in the Set;
- * returns true if the element is added, false otherwise
- *
- * @param oObject the Object to be added to this Set
- */
- public boolean add(Object oObject)
- {
- if (_oMap.containsKey(oObject))
- {
- return false;
- }
- else
- {
- internalAdd(_oMap, oObject);
- return true;
- }
- }
-
- /**
- * Adds all of the elements in the supplied Collection to this TreeSet.
- *
- * @param oCollection All of the elements in this Collection
- * will be added to the Set.
- *
- * @return true if the Set is altered, false otherwise
- */
- public boolean addAll(Collection oCollection)
- {
- boolean boResult = false;
- Iterator itElements = oCollection.iterator();
-
- while (itElements.hasNext())
- boResult = (boResult || add(itElements.next()));
-
- return boResult;
- }
-
- /**
- * Removes all elements in this Set.
- */
- public void clear()
- {
- _oMap.clear();
- }
-
- /** Returns a shallow copy of this Set. */
- public Object clone()
- {
- TreeSet oClone;
-
- try
- {
- oClone = (TreeSet) super.clone();
- oClone._oMap = _oMap;
- }
- catch(CloneNotSupportedException e)
- {
- oClone = null;
- }
- return oClone;
- }
-
- /** Returns this Set's comparator */
- public Comparator comparator()
- {
- return _oMap.comparator();
- }
-
- /**
- * Returns true if this Set contains the supplied Object,
- * false otherwise
- *
- * @param oObject the Object whose existence in the Set is
- * being tested
- */
- public boolean contains(Object oObject)
- {
- return _oMap.containsKey(oObject);
- }
-
- /** Returns true if this Set has size 0, false otherwise */
- public boolean isEmpty()
- {
- return _oMap.isEmpty();
- }
-
- /** Returns the number of elements in this Set */
- public int size()
- {
- return _oMap.size();
- }
-
- /**
- * If the supplied Object is in this Set, it is removed, and true is
- * returned; otherwise, false is returned.
- *
- * @param oObject the Object we are attempting to remove
- * from this Set
- */
- public boolean remove(Object oObject)
- {
- return (_oMap.remove(oObject) != null);
- }
-
- /** Returns the first (by order) element in this Set */
- public Object first()
- {
- return _oMap.firstKey();
- }
-
- /** Returns the last (by order) element in this Set */
- public Object last()
- {
- return _oMap.lastKey();
- }
-
- /**
- * Returns a view of this Set including all elements in the interval
- * [oFromElement, oToElement).
- *
- * @param oFromElement the resultant view will contain all
- * elements greater than or equal to this
- * element
- * @param oToElement the resultant view will contain all
- * elements less than this element
- */
- public SortedSet subSet(Object oFromElement, Object oToElement)
- {
- return new TreeSet(_oMap.subMap(oFromElement, oToElement));
- }
-
- /**
- * Returns a view of this Set including all elements less than oToElement
- *
- * @param oToElement the resultant view will contain all
- * elements less than this element
- */
- public SortedSet headSet(Object oToElement)
- {
- return new TreeSet(_oMap.headMap(oToElement));
- }
-
- /**
- * Returns a view of this Set including all elements greater than or
- * equal to oFromElement.
- *
- * @param oFromElement the resultant view will contain all
- * elements greater than or equal to this
- * element
- */
- public SortedSet tailSet(Object oFromElement)
- {
- return new TreeSet(_oMap.tailMap(oFromElement));
- }
-
-
- /** Returns in Iterator over the elements in this TreeSet */
- public Iterator iterator()
- {
- return _oMap.keySet().iterator();
- }
-
- private void writeObject(ObjectOutputStream oOut) throws IOException
- {
- Iterator itElements = iterator();
-
- oOut.writeObject(comparator());
- oOut.writeInt(size());
-
- while (itElements.hasNext())
- oOut.writeObject(itElements.next());
- }
-
- private void readObject(ObjectInputStream oIn)
- throws IOException, ClassNotFoundException
- {
- int i;
- Map.Entry[] arEntries;
- TreeMap oMap;
- Comparator oComparator = (Comparator) oIn.readObject();
- int iSize = oIn.readInt();
-
- arEntries = new Map.Entry[iSize];
-
- for (i = 0; i < iSize; i++)
- arEntries[iSize] = new BasicMapEntry(oIn.readObject(), Boolean.TRUE);
-
- oMap = new TreeMap(oComparator);
- oMap._iSize = iSize;
- oMap.putAllLinear(arEntries);
- _oMap = oMap;
- }
-
- /**
- * adds the supplied element to this Set; this private method is used
- * internally instead of add(), because add() can be overridden
- * to do unexpected things
- *
- * @param o the Object to add to this Set
- */
- private static final void internalAdd(Map oMap, Object oObject)
- {
- oMap.put(oObject, Boolean.TRUE);
- }
-}
diff --git a/jode/jode/util/UnsupportedOperationException.java b/jode/jode/util/UnsupportedOperationException.java
deleted file mode 100644
index 2934959..0000000
--- a/jode/jode/util/UnsupportedOperationException.java
+++ /dev/null
@@ -1,54 +0,0 @@
-// This interface is taken from the Classpath project.
-// Please note the different copyright holder!
-// The changes I did is this comment, the package line, some
-// imports from java.util and some minor jdk12 -> jdk11 fixes.
-// -- Jochen Hoenicke
-
-/*************************************************************************
-/* UnsupportedOperationException.java -- Exception thrown when an
-/* unsupported operation is attempted on an object
-/*
-/* Copyright (c) 1998 by Free Software Foundation, Inc.
-/*
-/* This program is free software; you can redistribute it and/or modify
-/* it under the terms of the GNU Library General Public License as published
-/* by the Free Software Foundation, version 2. (see COPYING.LIB)
-/*
-/* This program is distributed in the hope that it will be useful, but
-/* WITHOUT ANY WARRANTY; without even the implied warranty of
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-/* GNU General Public License for more details.
-/*
-/* You should have received a copy of the GNU General Public License
-/* along with this program; if not, write to the Free Software Foundation
-/* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
-/*************************************************************************/
-
-package jode.util;
-
-/**
- * This exception is thrown by an object when an operation is
- * requested of it that it does not support.
- *
- * @since JDK 1.2
- */
-public class UnsupportedOperationException extends RuntimeException
-{
- static final long serialVersionUID = -1242599979055084673L;
-
- /**
- * Create an exception without a message.
- */
- public UnsupportedOperationException()
- {
- super();
- }
-
- /**
- * Create an exception with a message.
- */
- public UnsupportedOperationException( String s )
- {
- super(s);
- }
-}