harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r413330 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/LinkedList.java test/java/tests/api/java/util/LinkedListTest.java
Date Sat, 10 Jun 2006 16:54:47 GMT
Author: ndbeyer
Date: Sat Jun 10 09:54:47 2006
New Revision: 413330

URL: http://svn.apache.org/viewvc?rev=413330&view=rev
Log:
Apply modified patch for HARMONY-494.

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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/LinkedList.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/LinkedList.java?rev=413330&r1=413329&r2=413330&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/LinkedList.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/LinkedList.java
Sat Jun 10 09:54:47 2006
@@ -28,8 +28,8 @@
  * elements can be any objects.
  * @since 1.2
  */
-public class LinkedList<E> extends AbstractSequentialList<E> implements List<E>,
-		Cloneable, Serializable {
+public class LinkedList<E> extends AbstractSequentialList<E> implements
+        List<E>, Queue<E>, Cloneable, Serializable {
 	
 	private static final long serialVersionUID = 876323262645176354L;
 
@@ -283,6 +283,7 @@
         return true;
     }
 
+
 	/**
 	 * Adds the objects in the specified Collection to this LinkedList.
 	 * 
@@ -642,6 +643,28 @@
 	public int size() {
 		return size;
 	}
+    
+    public boolean offer(E o) {
+        add(o);
+        return true;
+    }
+
+    public E poll() {
+        return size == 0 ? null : removeFirst();
+    }
+
+    public E remove() {
+        return removeFirst();
+    }
+
+    public E peek() {
+        Link<E> first = voidLink.next;
+        return first == voidLink ? null : first.data;
+    }
+
+    public E element() {
+        return getFirst();
+    }
 
 	/**
 	 * Answers a new array containing all elements contained in this LinkedList.
@@ -693,7 +716,7 @@
 	private void writeObject(ObjectOutputStream stream) throws IOException {
 		stream.defaultWriteObject();
 		stream.writeInt(size);
-		Iterator it = iterator();
+		Iterator<E> it = iterator();
 		while (it.hasNext())
 			stream.writeObject(it.next());
 	}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LinkedListTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LinkedListTest.java?rev=413330&r1=413329&r2=413330&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LinkedListTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/LinkedListTest.java
Sat Jun 10 09:54:47 2006
@@ -22,6 +22,8 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.ListIterator;
+import java.util.NoSuchElementException;
+
 
 import tests.support.Support_ListTest;
 
@@ -467,6 +469,42 @@
 		while (li.hasNext())
 			assertTrue("Lists are not equal", li.next() == ri.next());
 	}
+
+    public void test_offer() {
+        int origSize = ll.size();
+        assertTrue("offer() should return true'", ll.offer(objArray[0]));
+        assertEquals("offer() should add an element as the last one", origSize, ll.lastIndexOf(objArray[0]));
+    }
+
+    public void test_poll() {
+        assertEquals("should return the head", objArray[0], ll.poll());
+        LinkedList list = new LinkedList();
+        assertNull("should return 'null' if list is empty", list.poll());
+    }
+
+    public void test_remove() {
+        for (int i = 0; i < objArray.length; i++) {
+            assertEquals("should remove the head", objArray[i], ll.remove());
+        }
+        assertEquals("should be empty", 0, ll.size());
+        try {
+            ll.remove();
+            fail("NoSuchElementException is expected when removing from the empty list");
+        } catch (NoSuchElementException e) {
+            //-- expected
+        }
+    }
+
+    public void test_element() {
+        assertEquals("should return the head", objArray[0], ll.element());
+        assertEquals("element() should remove nothing", objArray.length, ll.size());
+        try {
+            new LinkedList().remove();
+            fail("NoSuchElementException is expected when the list is empty");
+        } catch (NoSuchElementException e) {
+            //-- expected
+        }
+    }
 
 	/**
 	 * Sets up the fixture, for example, open a network connection. This method



Mime
View raw message