The attached patches fix a couple of errors detected by the JSR 166 TCK.
* java/util/.AbstractMap.java:
SimpleImmutableEntry does not declare equals and hashcode. Since
this class is supposed to be an immutable version of SimpleEntry,
changed to extend SimpleEntry and override setValue.
This means that hashCode and equals behave as expected by the tck.
* java/util/PriorityQueue.java
Constructor PriorityQueue(int cap, Comparator comp) throws
IllegalArgumentException when cap < 1.
Iterator.remove() fixed so as not to skip the entry after the
removed entry.
This fixes EntryTest, PriorityQueueTest and PriorityBlockingQueueTest in
the tck.
On 29/04/10 07:32, Andrew John Hughes wrote:
As subject.
2010-04-28 Andrew John Hughes<ahug...@redhat.com>
* gnu/javax/print/ipp/IppPrintService.java:
(printerAttr): Add generic typing.
(printServiceAttributeListener): Likewise.
(flavors): Likewise.
(printerUris): Likewise.
(IppPrintService(URI uri, String username, String password)):
Use generic types in initialising listener set.
(getPrinterAttributes()): Add generic types. Remove cast.
(getPrinterAttributeSet(Class<T>)): Return a set containing
attributes of type T. Now creates a new set and checks that
all elements of the original set can be cast and added to this
new set.
(getPrinterDefaultAttribute(Class<? extends Attribute>)): Add
generic types.
(processResponse()): Add generic types.
(getAttribute(Class<T>)): Use generic types corresponding to
parent interface.
(getSupportedAttributeCategories()): Use generic types.
(getSupportedAttributeValues()): Likewise.
(handleSupportedAttributeValuesResponse(IppResponse,Class<? extends
Attribute>)):
Likewise.
(isAttributeCategorySupported(Class<? extends Attribute>)): Likewise.
* gnu/javax/print/ipp/IppResponse.java:
(parseResponse(InputStream)): Use generic types.
(parseAttributes(Map<Class<? extends Attribute>, Set<Attribute>,
DataInputStream)):
Likewise.
(addAttribute(Map<Class<? extends Attribute>, Set<Attribute>>,
Attribute): Likewise.
(IppResponse(URI, short)): Create lists with appropriate type
parameters.
(getJobAttributes()): Use generic return type.
(getOperationAttributes()): Likewise.
(getPrinterAttributes()): Likewise.
(getUnsupportedAttributes()): Likewise.
* gnu/javax/print/ipp/attribute/supported/CompressionSupported.java:
(getAssociatedAttributeArray(Set<Attribute>)): Use superclass Attribute
as set type parameter and cast when looping over it.
* gnu/javax/print/ipp/attribute/supported/FinishingsSupported.java,
(getAssociatedAttributeArray(Set<Attribute>)): Use superclass Attribute
as set type parameter and cast when looping over it.
* gnu/javax/print/ipp/attribute/supported/JobSheetsSupported.java,
(getAssociatedAttributeArray(Set<Attribute>)): Use superclass Attribute
as set type parameter and cast when looping over it.
* gnu/javax/print/ipp/attribute/supported/MediaSupported.java,
(getAssociatedAttributeArray(Set<Attribute>)): Use superclass Attribute
as set type parameter and cast when looping over it.
*
gnu/javax/print/ipp/attribute/supported/MultipleDocumentHandlingSupported.java,
(getAssociatedAttributeArray(Set<Attribute>)): Use superclass Attribute
as set type parameter and cast when looping over it.
*
gnu/javax/print/ipp/attribute/supported/OrientationRequestedSupported.java,
(getAssociatedAttributeArray(Set<Attribute>)): Use superclass Attribute
as set type parameter and cast when looping over it.
* gnu/javax/print/ipp/attribute/supported/PrintQualitySupported.java,
(getAssociatedAttributeArray(Set<Attribute>)): Use superclass Attribute
as set type parameter and cast when looping over it.
*
gnu/javax/print/ipp/attribute/supported/PrinterResolutionSupported.java,
(getAssociatedAttributeArray(Set<Attribute>)): Use superclass Attribute
as set type parameter and cast when looping over it.
--- components/classpath/97.2p9/classpath/java/util/AbstractMap.java 2010-04-27 16:31:20.000000000 +1000
+++ libraryInterface/GNUClasspath/EPL/src/java/util/AbstractMap.java 2010-05-02 23:01:48.000000000 +1000
@@ -71,16 +71,16 @@
*/
public abstract class AbstractMap<K, V> implements Map<K, V>
{
- /**
+ /**
* A class containing an immutable key and value. The
* implementation of {...@link Entry#setValue(V)} for this class
* simply throws an {...@link UnsupportedOperationException},
* thus preventing changes being made. This is useful when
* a static thread-safe view of a map is required.
*
- * @since 1.6
+ * @since 1.6
*/
- public static class SimpleImmutableEntry<K, V>
+ public static class SimpleImmutableEntry<K, V> extends SimpleEntry<K,V>
implements Entry<K, V>, Serializable
{
/**
@@ -88,34 +88,22 @@
*/
private static final long serialVersionUID = 7138329143949025153L;
- K key;
- V value;
-
public SimpleImmutableEntry(K key, V value)
{
- this.key = key;
- this.value = value;
+ super(key,value);
}
public SimpleImmutableEntry(Entry<? extends K, ? extends V> entry)
{
- this(entry.getKey(), entry.getValue());
- }
-
- public K getKey()
- {
- return key;
- }
-
- public V getValue()
- {
- return value;
+ super(entry);
}
+ @Override
public V setValue(V value)
{
throw new UnsupportedOperationException("setValue not supported on immutable entry");
}
+
}
/** An "enum" of iterator types. */
@@ -183,6 +171,7 @@
* @see Cloneable
* @see Object#clone()
*/
+ @Override
protected Object clone() throws CloneNotSupportedException
{
AbstractMap<K, V> copy = (AbstractMap<K, V>) super.clone();
@@ -248,6 +237,7 @@
* @return true if the object equals this map
* @see Set#equals(Object)
*/
+ @Override
public boolean equals(Object o)
{
return (o == this
@@ -289,6 +279,7 @@
* @see Map.Entry#hashCode()
* @see Set#hashCode()
*/
+ @Override
public int hashCode()
{
return entrySet().hashCode();
@@ -335,6 +326,7 @@
*
* @return The number of keys.
*/
+ @Override
public int size()
{
return AbstractMap.this.size();
@@ -347,6 +339,7 @@
* @param key The key to search for.
* @return True if the key was found, false otherwise.
*/
+ @Override
public boolean contains(Object key)
{
return containsKey(key);
@@ -359,6 +352,7 @@
*
* @return An iterator over the keys.
*/
+ @Override
public Iterator<K> iterator()
{
return new Iterator<K>()
@@ -386,7 +380,7 @@
* by the underlying <code>entrySet()</code> iterator.
*
* @return The next key.
- */
+ */
public K next()
{
return map_iterator.next().getKey();
@@ -454,7 +448,7 @@
// FIXME: bogus circumlocution.
Iterator entries2 = m.entrySet().iterator();
Iterator<Map.Entry<? extends K, ? extends V>> entries
- = (Iterator<Map.Entry<? extends K, ? extends V>>) entries2;
+ = entries2;
int pos = m.size();
while (--pos >= 0)
{
@@ -523,6 +517,7 @@
* @return a String representation
* @see Map.Entry#toString()
*/
+ @Override
public String toString()
{
Iterator<Map.Entry<K, V>> entries = entrySet().iterator();
@@ -571,7 +566,8 @@
*
* @return The number of values.
*/
- public int size()
+ @Override
+ public int size()
{
return AbstractMap.this.size();
}
@@ -583,6 +579,7 @@
* @param value The value to search for.
* @return True if the value was found, false otherwise.
*/
+ @Override
public boolean contains(Object value)
{
return containsValue(value);
@@ -595,6 +592,7 @@
*
* @return An iterator over the values.
*/
+ @Override
public Iterator<V> iterator()
{
return new Iterator<V>()
@@ -680,7 +678,7 @@
*
* @author Jon Zeppieri
* @author Eric Blake (e...@email.byu.edu)
- *
+ *
* @since 1.6
*/
public static class SimpleEntry<K, V> implements Entry<K, V>, Serializable
@@ -711,7 +709,7 @@
key = newKey;
value = newValue;
}
-
+
public SimpleEntry(Entry<? extends K, ? extends V> entry)
{
this(entry.getKey(), entry.getValue());
@@ -730,6 +728,7 @@
* @param o the object to compare
* @return <code>true</code> if it is equal
*/
+ @Override
public boolean equals(Object o)
{
if (! (o instanceof Map.Entry))
@@ -776,6 +775,7 @@
*
* @return the hash code
*/
+ @Override
public int hashCode()
{
return (AbstractMap.hashCode(key) ^ AbstractMap.hashCode(value));
@@ -809,11 +809,12 @@
*
* @return the string representation
*/
+ @Override
public String toString()
{
return key + "=" + value;
}
} // class SimpleEntry
-
-
+
+
}
--- components/classpath/97.2p9/classpath/java/util/PriorityQueue.java 2006-12-22 00:02:50.000000000 +1100
+++ libraryInterface/GNUClasspath/EPL/src/java/util/PriorityQueue.java 2010-05-02 22:36:24.000000000 +1000
@@ -108,6 +108,7 @@
public PriorityQueue(int cap, Comparator<? super E> comp)
{
+ if (cap <= 0) throw new IllegalArgumentException();
this.used = 0;
this.storage = (E[]) new Object[cap];
this.comparator = comp;
@@ -135,6 +136,7 @@
}
}
+ @Override
public void clear()
{
Arrays.fill(storage, null);
@@ -146,6 +148,7 @@
return comparator;
}
+ @Override
public Iterator<E> iterator()
{
return new Iterator<E>()
@@ -162,7 +165,7 @@
{
while (storage[++index] == null)
;
-
+
++count;
return storage[index];
}
@@ -170,6 +173,9 @@
public void remove()
{
PriorityQueue.this.remove(index);
+ // removal promotes another element to the slot just vacated,
+ // so we need to rewind to pick up the newly promoted element.
+ --index;
}
};
}
@@ -202,6 +208,7 @@
return result;
}
+ @Override
public boolean remove(Object o)
{
if (o != null)
@@ -218,6 +225,7 @@
return false;
}
+ @Override
public int size()
{
return used;
@@ -225,6 +233,7 @@
// It is more efficient to implement this locally -- less searching
// for free slots.
+ @Override
public boolean addAll(Collection<? extends E> c)
{
if (c == this)