Initial revision

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@938 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 25 years ago
parent e46cf92d68
commit 39ec800e12
  1. 337
      jode/jode/util/AbstractCollection.java
  2. 551
      jode/jode/util/AbstractList.java
  3. 280
      jode/jode/util/AbstractMap.java
  4. 111
      jode/jode/util/AbstractSequentialList.java
  5. 78
      jode/jode/util/AbstractSet.java
  6. 1685
      jode/jode/util/Arrays.java
  7. 234
      jode/jode/util/Collection.java
  8. 1413
      jode/jode/util/Collections.java
  9. 51
      jode/jode/util/Comparable.java
  10. 62
      jode/jode/util/Comparator.java
  11. 53
      jode/jode/util/ConcurrentModificationException.java
  12. 66
      jode/jode/util/Iterator.java
  13. 331
      jode/jode/util/List.java
  14. 145
      jode/jode/util/ListIterator.java
  15. 55
      jode/jode/util/Map.java
  16. 46
      jode/jode/util/Set.java
  17. 100
      jode/jode/util/SimpleMap.java
  18. 38
      jode/jode/util/SortedMap.java
  19. 38
      jode/jode/util/SortedSet.java
  20. 54
      jode/jode/util/UnsupportedOperationException.java

@ -0,0 +1,337 @@
// 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 <jochen@gnu.org>
/////////////////////////////////////////////////////////////////////////////
// AbstractCollection.java -- Abstract implementation of most of Collection
//
// 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.lang.reflect.Array;
/**
* A basic implementation of most of the methods in the Collection interface to
* make it easier to create a collection. To create an unmodifiable Collection,
* just subclass AbstractCollection and provide implementations of the
* iterator() and size() methods. The Iterator returned by iterator() need only
* provide implementations of hasNext() and next() (that is, it may throw an
* UnsupportedOperationException if remove() is called). To create a modifiable
* Collection, you must in addition provide an implementation of the
* add(Object) method and the Iterator returned by iterator() must provide an
* implementation of remove(). Other methods should be overridden if the
* backing data structure allows for a more efficient implementation. The
* precise implementation used by AbstractCollection is documented, so that
* subclasses can tell which methods could be implemented more efficiently.
*/
public abstract class AbstractCollection implements Collection {
/**
* Return an Iterator over this collection. The iterator must provide the
* hasNext and next methods and should in addition provide remove if the
* collection is modifiable.
*/
public abstract Iterator iterator();
/**
* Return the number of elements in this collection.
*/
public abstract int size();
/**
* Add an object to the collection. This implementation always throws an
* UnsupportedOperationException - it should be overridden if the collection
* is to be modifiable.
*
* @param o the object to add
* @return true if the add operation caused the Collection to change
* @exception UnsupportedOperationException if the add operation is not
* supported on this collection
*/
public boolean add(Object o) {
throw new UnsupportedOperationException();
}
/**
* Add all the elements of a given collection to this collection. This
* implementation obtains an Iterator over the given collection and iterates
* over it, adding each element with the add(Object) method (thus this method
* will fail with an UnsupportedOperationException if the add method does).
*
* @param c the collection to add the elements of to this collection
* @return true if the add operation caused the Collection to change
* @exception UnsupportedOperationException if the add operation is not
* supported on this collection
*/
public boolean addAll(Collection c) {
Iterator i = c.iterator();
boolean modified = false;
while (i.hasNext()) {
modified |= add(i.next());
}
return modified;
}
/**
* Remove all elements from the collection. This implementation obtains an
* iterator over the collection and calls next and remove on it repeatedly
* (thus this method will fail with an UnsupportedOperationException if the
* Iterator's remove method does) until there are no more elements to remove.
* Many implementations will have a faster way of doing this.
*
* @exception UnsupportedOperationException if the Iterator returned by
* iterator does not provide an implementation of remove
*/
public void clear() {
Iterator i = iterator();
while (i.hasNext()) {
i.next();
i.remove();
}
}
/**
* Test whether this collection contains a given object. That is, if the
* collection has an element e such that (o == null ? e == null :
* o.equals(e)). This implementation obtains an iterator over the collection
* and iterates over it, testing each element for equality with the given
* object. If it is equal, true is returned. Otherwise false is returned when
* the end of the collection is reached.
*
* @param o the object to remove from this collection
* @return true if this collection contains an object equal to o
*/
public boolean contains(Object o) {
Iterator i = iterator();
// This looks crazily inefficient, but it takes the test o==null outside
// the loop, saving time, and also saves needing to store the result of
// i.next() each time.
if (o == null) {
while (i.hasNext()) {
if (i.next() == null) {
return true;
}
}
} else {
while (i.hasNext()) {
if (o.equals(i.next())) {
return true;
}
}
}
return false;
}
/**
* Tests whether this collection contains all the elements in a given
* collection. This implementation iterates over the given collection,
* testing whether each element is contained in this collection. If any one
* is not, false is returned. Otherwise true is returned.
*
* @param c the collection to test against
* @return true if this collection contains all the elements in the given
* collection
*/
public boolean containsAll(Collection c) {
Iterator i = c.iterator();
while (i.hasNext()) {
if (!contains(i.next())) {
return false;
}
}
return true;
}
/**
* Test whether this collection is empty. This implementation returns
* size() == 0.
*
* @return true if this collection is empty.
*/
public boolean isEmpty() {
return size() == 0;
}
/**
* Remove a single instance of an object from this collection. That is,
* remove one element e such that (o == null ? e == null : o.equals(e)), if
* such an element exists. This implementation obtains an iterator over the
* collection and iterates over it, testing each element for equality with
* the given object. If it is equal, it is removed by the iterator's remove
* method (thus this method will fail with an UnsupportedOperationException
* if the Iterator's remove method does). After the first element has been
* removed, true is returned; if the end of the collection is reached, false
* is returned.
*
* @param o the object to remove from this collection
* @return true if the remove operation caused the Collection to change, or
* equivalently if the collection did contain o.
* @exception UnsupportedOperationException if this collection's Iterator
* does not support the remove method
*/
public boolean remove(Object o) {
Iterator i = iterator();
// This looks crazily inefficient, but it takes the test o==null outside
// the loop, saving time, and also saves needing to store the result of
// i.next() each time.
if (o == null) {
while (i.hasNext()) {
if (i.next() == null) {
i.remove();
return true;
}
}
} else {
while (i.hasNext()) {
if (o.equals(i.next())) {
i.remove();
return true;
}
}
}
return false;
}
/**
* Remove from this collection all its elements that are contained in a given
* collection. This implementation iterates over this collection, and for
* each element tests if it is contained in the given collection. If so, it
* is removed by the Iterator's remove method (thus this method will fail
* with an UnsupportedOperationException if the Iterator's remove method
* does).
*
* @param c the collection to remove the elements of
* @return true if the remove operation caused the Collection to change
* @exception UnsupportedOperationException if this collection's Iterator
* does not support the remove method
*/
public boolean removeAll(Collection c) {
Iterator i = iterator();
boolean changed = false;
while (i.hasNext()) {
if (c.contains(i.next())) {
i.remove();
changed = true;
}
}
return changed;
}
/**
* Remove from this collection all its elements that are not contained in a
* given collection. This implementation iterates over this collection, and
* for each element tests if it is contained in the given collection. If not,
* it is removed by the Iterator's remove method (thus this method will fail
* with an UnsupportedOperationException if the Iterator's remove method
* does).
*
* @param c the collection to retain the elements of
* @return true if the remove operation caused the Collection to change
* @exception UnsupportedOperationException if this collection's Iterator
* does not support the remove method
*/
public boolean retainAll(Collection c) {
Iterator i = iterator();
boolean changed = false;
while (i.hasNext()) {
if (!c.contains(i.next())) {
i.remove();
changed = true;
}
}
return changed;
}
/**
* Return an array containing the elements of this collection. This
* implementation creates an Object array of size size() and then iterates
* over the collection, setting each element of the array from the value
* returned by the iterator.
*
* @return an array containing the elements of this collection
*/
public Object[] toArray() {
Object[] a = new Object[size()];
Iterator i = iterator();
for (int pos = 0; pos < a.length; pos++) {
a[pos] = i.next();
}
return a;
}
/**
* Copy the collection into a given array if it will fit, or into a
* dynamically created array of the same run-time type as the given array if
* not. If there is space remaining in the array, the first element after the
* end of the collection is set to null (this is only useful if the
* collection is known to contain no null elements, however). This
* implementation first tests whether the given array is large enough to hold
* all the elements of the collection. If not, the reflection API is used to
* allocate a new array of the same run-time type. Next an iterator is
* obtained over the collection and the elements are placed in the array as
* they are returned by the iterator. Finally the first spare element, if
* any, of the array is set to null, and the created array is returned.
*
* @param a the array to copy into, or of the correct run-time type
* @return the array that was produced
* @exception ClassCastException if the type of the array precludes holding
* one of the elements of the Collection
*/
public Object[] toArray(Object[] a) {
final int n = size();
if (a.length < n) {
a = (Object[])Array.newInstance(a.getClass().getComponentType(), n);
}
Iterator i = iterator();
for (int pos = 0; pos < n; pos++) {
a[pos] = i.next();
}
if (a.length > n) {
a[n] = null;
}
return a;
}
/**
* Creates a String representation of the Collection. The string returned is
* of the form "[a, b, ...]" where a and b etc are the results of calling
* toString on the elements of the collection. This implementation obtains an
* Iterator over the Collection and adds each element to a StringBuffer as it
* is returned by the iterator.
*
* @return a String representation of the Collection
*/
public String toString() {
StringBuffer s = new StringBuffer();
s.append('[');
Iterator i = iterator();
boolean more = i.hasNext();
while(more) {
s.append(i.next());
if (more = i.hasNext()) {
s.append(", ");
}
}
s.append(']');
return s.toString();
}
}

@ -0,0 +1,551 @@
// 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 <jochen@gnu.org>
/////////////////////////////////////////////////////////////////////////////
// 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.
* <p>
* 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();
}
public List subList(final int fromIndex, final int toIndex) {
// Note that within this class two fields called modCount are inherited -
// one from the superclass, and one from the outer class. These are
// explicitly disambiguated in the code by referring to "this.modCount"
// and "AbstractList.this.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 != AbstractList.this.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.
return new AbstractList() {
private final int offset = fromIndex;
private int size = toIndex - fromIndex;
{ // This is an instance initializer, called whenever this anonymous
// class is instantiated.
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 (this.modCount != AbstractList.this.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() {
this.modCount = AbstractList.this.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 = AbstractList.this.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 = AbstractList.this.set(index + offset, o);
upMod();
return o;
}
public Object get(int index) {
checkMod();
checkBoundsExclusive(index);
return AbstractList.this.get(index + offset);
}
public void add(int index, Object o) {
checkMod();
checkBoundsInclusive(index);
AbstractList.this.add(index + offset, o);
upMod();
size++;
}
public Object remove(int index) {
checkMod();
checkBoundsExclusive(index);
Object o = AbstractList.this.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
AbstractList.this.removeRange(offset + fromIndex2, offset + toIndex2);
upMod();
size -= toIndex2 - fromIndex2;
}
public boolean addAll(int index, Collection c) {
checkMod();
checkBoundsInclusive(index);
int s = AbstractList.this.size();
boolean result = AbstractList.this.addAll(offset + index, c);
upMod();
size += AbstractList.this.size() - s;
return result;
}
};
}
}

@ -0,0 +1,280 @@
// 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 <jochen@gnu.org>
/////////////////////////////////////////////////////////////////////////////
// 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;
}

@ -0,0 +1,111 @@
// 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 <jochen@gnu.org>
/////////////////////////////////////////////////////////////////////////////
// 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;
}
}

@ -0,0 +1,78 @@
// 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 <jochen@gnu.org>
/////////////////////////////////////////////////////////////////////////////
// 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 <em>is</em> 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;
}
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,234 @@
// 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 <jochen@gnu.org>
/////////////////////////////////////////////////////////////////////////////
// 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.
* <p>
* All methods of this interface that are defined to modify the collection are
* defined as <dfn>optional</dfn>. 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.
* <p>
* 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.
* <p>
* 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
* <code>o == null ? e == null : o.equals(e)</code>.
*/
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.
* <p>
* 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.
* <p>
* 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 <code>o == null ? e == null
* : o.equals(e)</code>.
*
* @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);
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,51 @@
// 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 <jochen@gnu.org>
/*************************************************************************
/* 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 <EM>total</EM>, such that two objects
** only compare equal if they are equal by the equals method, or
** <EM>partial</EM> 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
** <code>o<code>, zero if this object is equal to <code>o</code>, or
** a positive integer if this object is greater than <code>o</code>
**/
public int compareTo( Object o );
}

@ -0,0 +1,62 @@
// 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 <jochen@gnu.org>
/////////////////////////////////////////////////////////////////////////////
// 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 <EM>total</EM>, such that two objects only compare equal if they are
* equal by the equals method, or <EM>partial</EM> 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.
* <P>
* 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:
* <UL>
* <LI>if compare(a, b) &lt; 0 then compare(b, a) &gt; 0</LI>
* <LI>if compare(a, b) throws an exception, so does compare(b, a)</LI>
* <LI>if compare(a, b) &lt; 0 and compare(b, c) &lt; 0 then compare(a, c)
* &lt; 0</LI>
* <LI>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 <EM>total</EM> ordering.</LI>
* </UL>
*
* @throws ClassCastException if the elements are not of types that can be
* compared by this ordering.
*/
int compare(Object o1, Object o2);
}

@ -0,0 +1,53 @@
// 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 <jochen@gnu.org>
/////////////////////////////////////////////////////////////////////////////
// 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);
}
}

@ -0,0 +1,66 @@
// 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 <jochen@gnu.org>
/////////////////////////////////////////////////////////////////////////////
// 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();
}

@ -0,0 +1,331 @@
// 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 <jochen@gnu.org>
/////////////////////////////////////////////////////////////////////////////
// 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 <code>o ==
* null ? e == null : o.equals(e)</code>.
*/
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 <code>l1.size() == l2.size()</code>, and for every integer n between 0
* and <code>l1.size() - 1</code> inclusive, <code>l1.get(n) == null ?
* l2.get(n) == null : l1.get(n).equals(l2.get(n))</code>.
*
* @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:
* <pre>
* hashCode = 1;
* Iterator i = list.iterator();
* while (i.hasNext()) {
* Object obj = i.next();
* hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode());
* }
* </pre>
* 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 <code>o == null ? get(n) == null :
* o.equals(get(n))</code>, 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 <code>o == null ? get(n) == null
* : o.equals(get(n))</code>.
*/
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 <code>o == null ? e == null :
* o.equals(e)</code>.
*
* @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);
}

@ -0,0 +1,145 @@
// 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 <jochen@gnu.org>
/////////////////////////////////////////////////////////////////////////////
// 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);
}

@ -0,0 +1,55 @@
// 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 <jochen@gnu.org>
/////////////////////////////////////////////////////////////////////////////
// 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);
}
}

@ -0,0 +1,46 @@
// 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 <jochen@gnu.org>
/////////////////////////////////////////////////////////////////////////////
// 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();
}

@ -0,0 +1,100 @@
/* SimpleMap Copyright (C) 1999 Jochen Hoenicke.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* 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; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id$
*/
package jode.util;
///#ifdef JDK12
///import java.util.AbstractMap;
///import java.util.Map;
///import java.util.Iterator;
///import java.util.Set;
///#endif
/**
* This is a very simple map, using a set as backing.
* The default backing set is a simple set, but you can specify any other
* set of Map.Entry in the constructor.
*/
public class SimpleMap extends AbstractMap {
private Set backing;
public SimpleMap() {
backing = new SimpleSet();
}
public SimpleMap(int initialCapacity) {
backing = new SimpleSet(initialCapacity);
}
public SimpleMap(Set fromSet) {
backing = fromSet;
}
public Set entrySet() {
return backing;
}
public static class SimpleEntry implements Map.Entry {
Object key;
Object value;
public SimpleEntry(Object key, Object 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();
i.hasNext(); ) {
Map.Entry entry = (Map.Entry) i.next();
if (key.equals(entry.getKey()))
return entry.setValue(value);
}
backing.add(new SimpleEntry(key, value));
return null;
}
}

@ -0,0 +1,38 @@
// 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 <jochen@gnu.org>
/////////////////////////////////////////////////////////////////////////////
// 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);
}

@ -0,0 +1,38 @@
// 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 <jochen@gnu.org>
/////////////////////////////////////////////////////////////////////////////
// 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);
}

@ -0,0 +1,54 @@
// 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 <jochen@gnu.org>
/*************************************************************************
/* 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);
}
}
Loading…
Cancel
Save