harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r437046 - /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/ref/ReferenceQueue.java
Date Sat, 26 Aug 2006 00:42:43 GMT
Author: ndbeyer
Date: Fri Aug 25 17:42:42 2006
New Revision: 437046

URL: http://svn.apache.org/viewvc?rev=437046&view=rev
Log:
Cleanup code and remove compiler warnings

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/ref/ReferenceQueue.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/ref/ReferenceQueue.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/ref/ReferenceQueue.java?rev=437046&r1=437045&r2=437046&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/ref/ReferenceQueue.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/ref/ReferenceQueue.java
Fri Aug 25 17:42:42 2006
@@ -15,25 +15,42 @@
 
 package java.lang.ref;
 
-
 /**
  * The implementation of this class is provided. The non-public implementation
- * details are documented so the vm vendor can use the implementation.
+ * details are documented so the VM vendor can use the implementation.
  * 
  * ReferenceQueue is the container on which reference objects are enqueued when
  * their reachability type is detected for the referent.
  * 
  * @since JDK1.2
  */
-public class ReferenceQueue<T> extends Object {
-
-	private Reference<? extends T>[] references;
-
-	private int head, tail;
+public class ReferenceQueue<T> {
+    
+    private static final int DEFAULT_QUEUE_SIZE = 128;
+    
+    private Reference<? extends T>[] references;
+
+	private int head;
+    
+    private int tail;
 
 	private boolean empty;
-
-	static private final int DEFAULT_QUEUE_SIZE = 128;
+    
+    /**
+     * Constructs a new instance of this class.
+     */
+    public ReferenceQueue() {
+        super();
+        references = newArray(DEFAULT_QUEUE_SIZE);
+        head = 0;
+        tail = 0;
+        empty = true;
+    }
+    
+    @SuppressWarnings("unchecked")
+    private Reference<? extends T>[] newArray(int size) {
+        return new Reference[size];
+    }
 
 	/**
 	 * Returns the next available reference from the queue if one is enqueued,
@@ -62,7 +79,7 @@
 
 	/**
 	 * Return the next available enqueued reference on the queue, blocking
-	 * indefinately until one is available.
+	 * indefinitely until one is available.
 	 * 
 	 * @return Reference a Reference object if one is available, null otherwise.
 	 * @exception InterruptedException
@@ -121,40 +138,27 @@
 	 * @return boolean true if reference is enqueued. false if reference failed
 	 *         to enqueue.
 	 */
-	boolean enqueue(Reference<? extends T> reference) {
+    boolean enqueue(Reference<? extends T> reference) {
 		synchronized (this) {
-			if (!empty && head == tail) {
-				/* Queue is full - grow */
-				int newQueueSize = (int) (references.length * 1.10);
-				Reference<? extends T> newQueue[] =
-                    (Reference<? extends T>[])new Reference[newQueueSize];
-				System.arraycopy(references, head, newQueue, 0,
-						references.length - head);
-				if (tail > 0) {
-					System.arraycopy(references, 0, newQueue, references.length
-							- head, tail);
-				}
-				head = 0;
-				tail = references.length;
-				references = newQueue;
-			}
-			references[tail++] = reference;
-			if (tail == references.length) {
-				tail = 0;
-			}
-			empty = false;
-			notifyAll();
-		}
-		return true;
-	}
-
-	/**
-	 * Constructs a new instance of this class.
-	 */
-	public ReferenceQueue() {
-		references = (Reference<? extends T>[])new Reference[DEFAULT_QUEUE_SIZE];
-		head = 0;
-		tail = 0;
-		empty = true;
+            if (!empty && head == tail) {
+                /* Queue is full - grow */
+                int newQueueSize = (int) (references.length * 1.10);
+                Reference<? extends T> newQueue[] = newArray(newQueueSize);
+                System.arraycopy(references, head, newQueue, 0, references.length - head);
+                if (tail > 0) {
+                    System.arraycopy(references, 0, newQueue, references.length - head, tail);
+                }
+                head = 0;
+                tail = references.length;
+                references = newQueue;
+            }
+            references[tail++] = reference;
+            if (tail == references.length) {
+                tail = 0;
+            }
+            empty = false;
+            notifyAll();
+        }
+        return true;
 	}
 }



Mime
View raw message