harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r432361 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/AbstractQueue.java test/java/tests/api/java/util/AbstractQueueTest.java
Date Thu, 17 Aug 2006 19:41:31 GMT
Author: tellison
Date: Thu Aug 17 12:41:30 2006
New Revision: 432361

URL: http://svn.apache.org/viewvc?rev=432361&view=rev
Log:
Fix for HARMONY-1178 (AbstractQueue.addAll return true even if collection was not changed
as a result of a call)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractQueue.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractQueueTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractQueue.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractQueue.java?rev=432361&r1=432360&r2=432361&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractQueue.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractQueue.java
Thu Aug 17 12:41:30 2006
@@ -1,132 +1,126 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package java.util;
-
-/**
- * 
- * An abstract class which gives out skeletal implementations for some methods
- * in Queue which include add, remove, and element that are based on offer,
- * poll, and peek except that they throw exception to indicate the occurrence of
- * some error instead of the return value of false or null.
- * 
- * @param <E>
- *            the type of the element in the collection.
- */
-public abstract class AbstractQueue<E> extends AbstractCollection<E> implements
-        Queue<E> {
-
-    /**
-     * Constructor for the sub classes.
-     * 
-     */
-    protected AbstractQueue() {
-        super();
-    }
-
-    /**
-     * Adds an element to the queue.
-     * 
-     * @param o the element added to the queue.
-     * @return true if the operation succeeds.
-     * @throws NullPointerException if the element is null.
-     * @throws IllegalStateException if the element is not allowed to be added
-     *         to the queue.
-     */
-    @Override
-    public boolean add(E o) {
-        if (null == o) {
-            throw new NullPointerException();
-        }
-        if (offer(o)) {
-            return true;
-        } else {
-            throw new IllegalStateException();
-        }
-    }
-
-    /**
-     * Adds all the elements of a collection to the queue. If the collection is
-     * the queue itself, then an IllegalArgumentException will be thrown out. If
-     * during the process, some runtime exception is thrown out, then part of
-     * the elements in the collection that have successfully added will remain
-     * in the queue.
-     * 
-     * The result of the method is undefined if the collection is modified
-     * during the process of the method.
-     * 
-     * @param c the collection to be added to the queue.
-     * @return true if the operation succeeds.
-     * @throws NullPointerException if the collection or any element of it is
-     *         null.
-     * @throws IllegalArgumentException If the collection to be added to the
-     *         queue is the queue itself.
-     */
-    @Override
-    public boolean addAll(Collection<? extends E> c) {
-        if (null == c) {
-            throw new NullPointerException();
-        }
-        if (this == c) {
-            throw new IllegalArgumentException();
-        }
-        Iterator<? extends E> iter = c.iterator();
-        while (iter.hasNext()) {
-            E o = iter.next();
-            add(o);
-        }
-        return true;
-
-    }
-
-    /**
-     * Gets and removes the element in the head of the queue.
-     * 
-     * @return the element in the head of the queue.
-     * @throws NoSuchElementException if the queue is empty.
-     */
-    public E remove() {
-        E o = poll();
-        if (null == o) {
-            throw new NoSuchElementException();
-        }
-        return o;
-    }
-
-    /**
-     * Gets but not removes the element in the head of the queue.
-     * 
-     * @return the element in the head of the queue.
-     * @throws NoSuchElementException if the queue is empty.
-     */
-    public E element() {
-        E o = peek();
-        if (null == o) {
-            throw new NoSuchElementException();
-        }
-        return o;
-    }
-
-    /**
-     * Removes all elements of the queue.
-     */
-    @Override
-    public void clear() {
-        E o;
-        do {
-            o = poll();
-        } while (null != o);
-    }
-}
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.util;
+
+/**
+ * 
+ * An abstract class which gives out skeletal implementations for some methods
+ * in Queue which include add, remove, and element that are based on offer,
+ * poll, and peek except that they throw exception to indicate the occurrence of
+ * some error instead of the return value of false or null.
+ * 
+ * @param <E>
+ *            the type of the element in the collection.
+ */
+public abstract class AbstractQueue<E> extends AbstractCollection<E> implements
+        Queue<E> {
+
+    /**
+     * Constructor for the sub classes.
+     * 
+     */
+    protected AbstractQueue() {
+        super();
+    }
+
+    /**
+     * Adds an element to the queue.
+     * 
+     * @param o the element added to the queue.
+     * @return true if the operation succeeds.
+     * @throws NullPointerException if the element is null.
+     * @throws IllegalStateException if the element is not allowed to be added
+     *         to the queue.
+     */
+    @Override
+    public boolean add(E o) {
+        if (null == o) {
+            throw new NullPointerException();
+        }
+        if (offer(o)) {
+            return true;
+        } else {
+            throw new IllegalStateException();
+        }
+    }
+
+    /**
+     * Adds all the elements of a collection to the queue. If the collection is
+     * the queue itself, then an IllegalArgumentException will be thrown out. If
+     * during the process, some runtime exception is thrown out, then part of
+     * the elements in the collection that have successfully added will remain
+     * in the queue.
+     * 
+     * The result of the method is undefined if the collection is modified
+     * during the process of the method.
+     * 
+     * @param c the collection to be added to the queue.
+     * @return true if the operation succeeds.
+     * @throws NullPointerException if the collection or any element of it is
+     *         null.
+     * @throws IllegalArgumentException If the collection to be added to the
+     *         queue is the queue itself.
+     */
+    @Override
+    public boolean addAll(Collection<? extends E> c) {
+        if (null == c) {
+            throw new NullPointerException();
+        }
+        if (this == c) {
+            throw new IllegalArgumentException();
+        }
+        return super.addAll(c);
+    }
+
+    /**
+     * Gets and removes the element in the head of the queue.
+     * 
+     * @return the element in the head of the queue.
+     * @throws NoSuchElementException if the queue is empty.
+     */
+    public E remove() {
+        E o = poll();
+        if (null == o) {
+            throw new NoSuchElementException();
+        }
+        return o;
+    }
+
+    /**
+     * Gets but not removes the element in the head of the queue.
+     * 
+     * @return the element in the head of the queue.
+     * @throws NoSuchElementException if the queue is empty.
+     */
+    public E element() {
+        E o = peek();
+        if (null == o) {
+            throw new NoSuchElementException();
+        }
+        return o;
+    }
+
+    /**
+     * Removes all elements of the queue.
+     */
+    @Override
+    public void clear() {
+        E o;
+        do {
+            o = poll();
+        } while (null != o);
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractQueueTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractQueueTest.java?rev=432361&r1=432360&r2=432361&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractQueueTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/AbstractQueueTest.java
Thu Aug 17 12:41:30 2006
@@ -15,6 +15,7 @@
 package tests.api.java.util;
 
 import java.util.AbstractQueue;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
@@ -186,6 +187,15 @@
         } catch (IllegalStateException e) {
             // expected
         }
+    }
+
+    /**
+     * @tests java.util.AbstractQueue#addAll(E)
+     */
+    public void test_addAllLE_empty() {
+        // Regression test for HARMONY-1178
+        List list = new ArrayList<Object>(0);
+        assertFalse("Non modification to queue should return false", queue.addAll(list));
     }
 
     /**



Mime
View raw message