git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/branches/collections_jdk5_branch@471214 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2006-11-04 15:21:01 +00:00
parent d855890756
commit 9b78600daa
14 changed files with 112 additions and 122 deletions

View File

@ -38,13 +38,14 @@ import java.util.Set;
* In an ideal world, the interface would be changed to fix the problems, however
* it has been decided to maintain backwards compatibility instead.
*
* @param <E> the type held in the bag
* @since Commons Collections 2.0
* @version $Revision$ $Date$
*
* @author Chuck Burdick
* @author Stephen Colebourne
*/
public interface Bag extends Collection {
public interface Bag<E> extends Collection<E> {
/**
* Returns the number of occurrences (cardinality) of the given
@ -54,7 +55,7 @@ public interface Bag extends Collection {
* @param object the object to search for
* @return the number of occurrences of the object, zero if not found
*/
int getCount(Object object);
int getCount(E object);
/**
* <i>(Violation)</i>
@ -72,7 +73,7 @@ public interface Bag extends Collection {
* @param object the object to add
* @return <code>true</code> if the object was not already in the <code>uniqueSet</code>
*/
boolean add(Object object);
boolean add(E object);
/**
* Adds <code>nCopies</code> copies of the specified object to the Bag.
@ -85,7 +86,7 @@ public interface Bag extends Collection {
* @param nCopies the number of copies to add
* @return <code>true</code> if the object was not already in the <code>uniqueSet</code>
*/
boolean add(Object object, int nCopies);
boolean add(E object, int nCopies);
/**
* <i>(Violation)</i>
@ -111,7 +112,7 @@ public interface Bag extends Collection {
* @param nCopies the number of copies to remove
* @return <code>true</code> if this call changed the collection
*/
boolean remove(Object object, int nCopies);
boolean remove(E object, int nCopies);
/**
* Returns a {@link Set} of unique elements in the Bag.
@ -120,7 +121,7 @@ public interface Bag extends Collection {
*
* @return the Set of unique Bag elements
*/
Set uniqueSet();
Set<E> uniqueSet();
/**
* Returns the total number of items in the bag across all types.
@ -145,7 +146,7 @@ public interface Bag extends Collection {
* @param coll the collection to check against
* @return <code>true</code> if the Bag contains all the collection
*/
boolean containsAll(Collection coll);
boolean containsAll(Collection<?> coll);
/**
* <i>(Violation)</i>
@ -163,7 +164,7 @@ public interface Bag extends Collection {
* @param coll the collection to remove
* @return <code>true</code> if this call changed the collection
*/
boolean removeAll(Collection coll);
boolean removeAll(Collection<?> coll);
/**
* <i>(Violation)</i>
@ -184,7 +185,7 @@ public interface Bag extends Collection {
* @param coll the collection to retain
* @return <code>true</code> if this call changed the collection
*/
boolean retainAll(Collection coll);
boolean retainAll(Collection<?> coll);
/**
* Returns an {@link Iterator} over the entire set of members,
@ -193,7 +194,7 @@ public interface Bag extends Collection {
*
* @return iterator over all elements in the Bag
*/
Iterator iterator();
Iterator<E> iterator();
// The following is not part of the formal Bag interface, however where possible
// Bag implementations should follow these comments.
@ -218,5 +219,5 @@ public interface Bag extends Collection {
// * @return the hash code of the Bag
// */
// int hashCode();
}

View File

@ -33,33 +33,15 @@ package org.apache.commons.collections;
* This is required so that "inverting" the map results in a map without
* duplicate keys. See the {@link #put} method description for more information.
*
* @param <K> the type of the keys in the map
* @param <V> the type of the values in the map
* @since Commons Collections 3.0
* @version $Revision$ $Date$
*
* @author Stephen Colebourne
*/
public interface BidiMap extends IterableMap {
public interface BidiMap<K, V> extends IterableMap<K, V> {
/**
* Obtains a <code>MapIterator</code> over the map.
* <p>
* A map iterator is an efficient way of iterating over maps.
* It does not require that the map is stored using Map Entry objects
* which can increase performance.
* <pre>
* BidiMap map = new DualHashBidiMap();
* MapIterator it = map.mapIterator();
* while (it.hasNext()) {
* Object key = it.next();
* Object value = it.getValue();
* it.setValue("newValue");
* }
* </pre>
*
* @return a map iterator
*/
MapIterator mapIterator();
/**
* Puts the key-value pair into the map, replacing any previous pair.
* <p>
@ -88,8 +70,8 @@ public interface BidiMap extends IterableMap {
* @throws NullPointerException (optional) if the map limits the values to
* non-null and null was specified
*/
Object put(Object key, Object value);
V put(K key, V value);
/**
* Gets the key that is currently mapped to the specified value.
* <p>
@ -106,8 +88,8 @@ public interface BidiMap extends IterableMap {
* @throws NullPointerException (optional) if the map limits the values to
* non-null and null was specified
*/
Object getKey(Object value);
K getKey(V value);
/**
* Removes the key-value pair that is currently mapped to the specified
* value (optional operation).
@ -127,8 +109,8 @@ public interface BidiMap extends IterableMap {
* @throws UnsupportedOperationException if this method is not supported
* by the implementation
*/
Object removeValue(Object value);
K removeValue(V value);
/**
* Gets a view of this map where the keys and values are reversed.
* <p>
@ -141,6 +123,6 @@ public interface BidiMap extends IterableMap {
*
* @return an inverted bidirectional map
*/
BidiMap inverseBidiMap();
BidiMap<V, K> inverseBidiMap();
}

View File

@ -35,6 +35,7 @@ import java.util.Collection;
* also implement {@link java.util.List}, {@link java.util.Set} or
* {@link Bag}.
*
* @param <E> the type of the elements in the buffer
* @since Commons Collections 2.1
* @version $Revision$ $Date$
*
@ -43,7 +44,7 @@ import java.util.Collection;
* @author Paul Jack
* @author Stephen Colebourne
*/
public interface Buffer extends Collection {
public interface Buffer<E> extends Collection<E> {
/**
* Gets and removes the next object from the buffer.
@ -51,7 +52,7 @@ public interface Buffer extends Collection {
* @return the next object in the buffer, which is also removed
* @throws BufferUnderflowException if the buffer is already empty
*/
Object remove();
E remove();
/**
* Gets the next object from the buffer without removing it.
@ -59,6 +60,6 @@ public interface Buffer extends Collection {
* @return the next object in the buffer, which is not removed
* @throws BufferUnderflowException if the buffer is empty
*/
Object get();
E get();
}

View File

@ -22,41 +22,43 @@ import java.util.Map;
* Defines a map that can be iterated directly without needing to create an entry set.
* <p>
* A map iterator is an efficient way of iterating over maps.
* There is no need to access the entry set or cast to Map Entry objects.
* There is no need to access the entry set or use Map Entry objects.
* <pre>
* IterableMap map = new HashedMap();
* MapIterator it = map.mapIterator();
* IterableMap<String,Integer> map = new HashedMap<String,Integer>();
* MapIterator<String,Integer> it = map.mapIterator();
* while (it.hasNext()) {
* Object key = it.next();
* Object value = it.getValue();
* it.setValue("newValue");
* String key = it.next();
* Integer value = it.getValue();
* it.setValue(value + 1);
* }
* </pre>
*
* @param <K> the type of the keys in the map
* @param <V> the type of the values in the map
* @since Commons Collections 3.0
* @version $Revision$ $Date$
*
* @author Stephen Colebourne
*/
public interface IterableMap extends Map {
public interface IterableMap<K, V> extends Map<K, V> {
/**
* Obtains a <code>MapIterator</code> over the map.
* <p>
* A map iterator is an efficient way of iterating over maps.
* There is no need to access the entry set or cast to Map Entry objects.
* There is no need to access the entry set or use Map Entry objects.
* <pre>
* IterableMap map = new HashedMap();
* MapIterator it = map.mapIterator();
* IterableMap<String,Integer> map = new HashedMap<String,Integer>();
* MapIterator<String,Integer> it = map.mapIterator();
* while (it.hasNext()) {
* Object key = it.next();
* Object value = it.getValue();
* it.setValue("newValue");
* String key = it.next();
* Integer value = it.getValue();
* it.setValue(value + 1);
* }
* </pre>
*
* @return a map iterator
*/
MapIterator mapIterator();
MapIterator<K, V> mapIterator();
}

View File

@ -23,25 +23,27 @@ package org.apache.commons.collections;
* key-value pair. This interface defines the minimum key value, with just the
* two get methods.
*
* @param <K> the type of the key
* @param <V> the type of the value
* @since Commons Collections 3.0
* @version $Revision$ $Date$
*
* @author Stephen Colebourne
*/
public interface KeyValue {
public interface KeyValue<K, V> {
/**
* Gets the key from the pair.
*
* @return the key
*/
Object getKey();
K getKey();
/**
* Gets the value from the pair.
*
* @return the value
*/
Object getValue();
V getValue();
}

View File

@ -17,6 +17,7 @@
package org.apache.commons.collections;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* Defines an iterator that operates over a <code>Map</code>.
@ -32,14 +33,16 @@ import java.util.Iterator;
* to <code>next()</code>, the <code>getValue()</code> method provides direct
* access to the value. The value can also be set using <code>setValue()</code>.
* <pre>
* MapIterator it = map.mapIterator();
* MapIterator<String,Integer> it = map.mapIterator();
* while (it.hasNext()) {
* Object key = it.next();
* Object value = it.getValue();
* it.setValue(newValue);
* String key = it.next();
* Integer value = it.getValue();
* it.setValue(value + 1);
* }
* </pre>
*
*
* @param <K> the type of the keys in the map
* @param <V> the type of the values in the map
* @since Commons Collections 3.0
* @version $Revision$ $Date$
*
@ -58,7 +61,7 @@ public interface MapIterator<K, V> extends Iterator<K> {
* Gets the next <em>key</em> from the <code>Map</code>.
*
* @return the next key in the iteration
* @throws java.util.NoSuchElementException if the iteration is finished
* @throws NoSuchElementException if the iteration is finished
*/
K next();

View File

@ -23,12 +23,14 @@ package org.apache.commons.collections;
* Implementations should allow a value to be looked up from a key and
* a key to be looked up from a value with equal performance.
*
* @param <K> the type of the keys in the map
* @param <V> the type of the values in the map
* @since Commons Collections 3.0
* @version $Revision$ $Date$
*
* @author Stephen Colebourne
*/
public interface OrderedBidiMap extends BidiMap, OrderedMap {
public interface OrderedBidiMap<K, V> extends BidiMap<K, V>, OrderedMap<K, V> {
/**
* Gets a view of this map where the keys and values are reversed.
@ -45,8 +47,8 @@ public interface OrderedBidiMap extends BidiMap, OrderedMap {
*
* @return an inverted bidirectional map
*/
public BidiMap inverseBidiMap();
public BidiMap<V, K> inverseBidiMap();
/**
* Gets a view of this map where the keys and values are reversed.
* <p>
@ -59,6 +61,6 @@ public interface OrderedBidiMap extends BidiMap, OrderedMap {
*
* @return an inverted bidirectional map
*/
public OrderedBidiMap inverseOrderedBidiMap();
public OrderedBidiMap<V, K> inverseOrderedBidiMap();
}

View File

@ -17,18 +17,20 @@
package org.apache.commons.collections;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* Defines an iterator that operates over an ordered collection.
* Defines an iterator that operates over an ordered container.
* <p>
* This iterator allows both forward and reverse iteration through the collection.
*
* This iterator allows both forward and reverse iteration through the container.
*
* @param <E> the type to iterate over
* @since Commons Collections 3.0
* @version $Revision$ $Date$
*
* @author Stephen Colebourne
*/
public interface OrderedIterator extends Iterator {
public interface OrderedIterator<E> extends Iterator<E> {
/**
* Checks to see if there is a previous element that can be iterated to.
@ -38,11 +40,11 @@ public interface OrderedIterator extends Iterator {
boolean hasPrevious();
/**
* Gets the previous element from the collection.
* Gets the previous element from the container.
*
* @return the previous element in the iteration
* @throws java.util.NoSuchElementException if the iteration is finished
* @throws NoSuchElementException if the iteration is finished
*/
Object previous();
E previous();
}

View File

@ -20,40 +20,32 @@ package org.apache.commons.collections;
* Defines a map that maintains order and allows both forward and backward
* iteration through that order.
*
* @param <K> the type of the keys in the map
* @param <V> the type of the values in the map
* @since Commons Collections 3.0
* @version $Revision$ $Date$
*
* @author Stephen Colebourne
*/
public interface OrderedMap extends IterableMap {
public interface OrderedMap<K, V> extends IterableMap<K, V> {
/**
* Obtains an <code>OrderedMapIterator</code> over the map.
* <p>
* A ordered map iterator is an efficient way of iterating over maps
* in both directions.
* <pre>
* BidiMap map = new TreeBidiMap();
* MapIterator it = map.mapIterator();
* while (it.hasNext()) {
* Object key = it.next();
* Object value = it.getValue();
* it.setValue("newValue");
* Object previousKey = it.previous();
* }
* </pre>
*
* @return a map iterator
*/
OrderedMapIterator orderedMapIterator();
OrderedMapIterator<K, V> orderedMapIterator();
/**
* Gets the first key currently in this map.
*
* @return the first key currently in this map
* @throws java.util.NoSuchElementException if this map is empty
*/
public Object firstKey();
public K firstKey();
/**
* Gets the last key currently in this map.
@ -61,15 +53,15 @@ public interface OrderedMap extends IterableMap {
* @return the last key currently in this map
* @throws java.util.NoSuchElementException if this map is empty
*/
public Object lastKey();
public K lastKey();
/**
* Gets the next key after the one specified.
*
* @param key the key to search for next from
* @return the next key, null if no match or at end
*/
public Object nextKey(Object key);
public K nextKey(K key);
/**
* Gets the previous key before the one specified.
@ -77,6 +69,6 @@ public interface OrderedMap extends IterableMap {
* @param key the key to search for previous from
* @return the previous key, null if no match or at start
*/
public Object previousKey(Object key);
public K previousKey(K key);
}

View File

@ -16,18 +16,22 @@
*/
package org.apache.commons.collections;
import java.util.NoSuchElementException;
/**
* Defines an iterator that operates over an ordered <code>Map</code>.
* <p>
* This iterator allows both forward and reverse iteration through the map.
*
*
* @param <K> the type of the keys in the map
* @param <V> the type of the values in the map
* @since Commons Collections 3.0
* @version $Revision$ $Date$
*
* @author Stephen Colebourne
*/
public interface OrderedMapIterator extends MapIterator, OrderedIterator {
public interface OrderedMapIterator<K, V> extends MapIterator<K, V>, OrderedIterator<K> {
/**
* Checks to see if there is a previous entry that can be iterated to.
*
@ -39,8 +43,8 @@ public interface OrderedMapIterator extends MapIterator, OrderedIterator {
* Gets the previous <em>key</em> from the <code>Map</code>.
*
* @return the previous key in the iteration
* @throws java.util.NoSuchElementException if the iteration is finished
* @throws NoSuchElementException if the iteration is finished
*/
Object previous();
K previous();
}

View File

@ -23,12 +23,13 @@ import java.util.Iterator;
* <p>
* This interface allows an iterator to be repeatedly reused.
*
* @param <E> the type to iterate over
* @since Commons Collections 3.0
* @version $Revision$ $Date$
*
* @author Stephen Colebourne
*/
public interface ResettableIterator extends Iterator {
public interface ResettableIterator<E> extends Iterator<E> {
/**
* Resets the iterator back to the position at which the iterator

View File

@ -23,17 +23,12 @@ import java.util.ListIterator;
* <p>
* This interface allows an iterator to be repeatedly reused.
*
* @param <E> the type to iterate over
* @since Commons Collections 3.0
* @version $Revision$ $Date$
*
* @author Stephen Colebourne
*/
public interface ResettableListIterator extends ListIterator, ResettableIterator {
/**
* Resets the iterator back to the position at which the iterator
* was created.
*/
public void reset();
public interface ResettableListIterator<E> extends ListIterator<E>, ResettableIterator<E> {
}

View File

@ -22,12 +22,13 @@ import java.util.Comparator;
* Defines a type of <code>Bag</code> that maintains a sorted order among
* its unique representative members.
*
* @param <E> the type to iterate over
* @since Commons Collections 2.0
* @version $Revision$ $Date$
*
* @author Chuck Burdick
*/
public interface SortedBag extends Bag {
public interface SortedBag<E> extends Bag<E> {
/**
* Returns the comparator associated with this sorted set, or null
@ -35,20 +36,20 @@ public interface SortedBag extends Bag {
*
* @return the comparator in use, or null if natural ordering
*/
public Comparator comparator();
public Comparator<? super E> comparator();
/**
* Returns the first (lowest) member.
*
* @return the first element in the sorted bag
*/
public Object first();
public E first();
/**
* Returns the last (highest) member.
*
* @return the last element in the sorted bag
*/
public Object last();
public E last();
}

View File

@ -25,12 +25,14 @@ import java.util.SortedMap;
* Implementations should allow a value to be looked up from a key and
* a key to be looked up from a value with equal performance.
*
* @param <K> the type of the keys in the map
* @param <V> the type of the values in the map
* @since Commons Collections 3.0
* @version $Revision$ $Date$
*
* @author Stephen Colebourne
*/
public interface SortedBidiMap extends OrderedBidiMap, SortedMap {
public interface SortedBidiMap<K, V> extends OrderedBidiMap<K, V>, SortedMap<K, V> {
/**
* Gets a view of this map where the keys and values are reversed.
@ -47,8 +49,8 @@ public interface SortedBidiMap extends OrderedBidiMap, SortedMap {
*
* @return an inverted bidirectional map
*/
public BidiMap inverseBidiMap();
public BidiMap<V, K> inverseBidiMap();
/**
* Gets a view of this map where the keys and values are reversed.
* <p>
@ -64,6 +66,6 @@ public interface SortedBidiMap extends OrderedBidiMap, SortedMap {
*
* @return an inverted bidirectional map
*/
public SortedBidiMap inverseSortedBidiMap();
public SortedBidiMap<V, K> inverseSortedBidiMap();
}