< prev index next >

src/com/sun/javatest/util/ReadAheadIterator.java

Print this page
rev 145 : 7902237: Fixing raw use of parameterized class
Reviewed-by: jjg

@@ -24,18 +24,20 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 package com.sun.javatest.util;
 
+import com.sun.javatest.TestResult;
+
 import java.util.Iterator;
 
 /**
  * An iterator that can read ahead of the current position, either for
  * performance reasons or to help find out the number of items returned by an
  * iterator before accessing them.
  */
-public class ReadAheadIterator implements Iterator
+public class ReadAheadIterator implements Iterator<TestResult>
 {
     /**
      * A constant indicating that no read ahead is required.
      * @see #ReadAheadIterator
      */

@@ -59,11 +61,11 @@
      * @param mode A value indicating the type of read ahead required.
      * @see #NONE
      * @see #LIMITED
      * @see #FULL
      */
-    public ReadAheadIterator(Iterator source, int mode) {
+    public ReadAheadIterator(Iterator<TestResult> source, int mode) {
         this(source, mode, DEFAULT_LIMITED_READAHEAD);
     }
 
     /**
      * Create a ReadAheadIterator.

@@ -74,11 +76,11 @@
      * parameter will be ignored.
      * @see #NONE
      * @see #LIMITED
      * @see #FULL
      */
-    public ReadAheadIterator(Iterator source, int mode, int amount) {
+    public ReadAheadIterator(Iterator<TestResult> source, int mode, int amount) {
         this.source = source;
         setMode(mode, amount);
     }
 
     /**

@@ -171,13 +173,13 @@
     public synchronized boolean hasNext() {
         return (queue.size() > 0
                 || (worker == null ? source.hasNext() : sourceHasNext));
     }
 
-    public synchronized Object next() {
+    public synchronized TestResult next() {
         // see if there are items in the read ahead queue
-        Object result = queue.remove();
+        TestResult result = queue.remove();
 
         if (result == null) {
             // queue is empty: check whether to read source directly, or rely on the worker thread
             if (maxQueueSize == 0)
                 // no read ahead, so don't start worker; use source directly

@@ -254,11 +256,11 @@
         try {
             while (keepReading) {
                 // sourceHasNext is true, which means there is another item
                 // to be read, so read it, and also check whether there is
                 // another item after that
-                Object srcNext  = source.next();
+                TestResult srcNext  = source.next();
                 boolean srcHasNext = source.hasNext();
 
                 // get the lock to update the queue and sourceHasNext;
                 // check that the worker is still required; and
                 // wait (if necessary) for the queue to empty a bit

@@ -294,19 +296,19 @@
     // Instance variables: access to all of these (except source) must be synchronized.
 
     /**
      * The queue to hold the items that have been read from the underlying source iterator.
      */
-    private final Fifo queue = new Fifo();
+    private final Fifo<TestResult> queue = new Fifo<>();
 
     /**
      * The underlying source iterator.  If the worker thread is running, it alone
      * should access this iterator; otherwise, access to this should be synchronized,
      * along with everything else.
      * @see #worker
      */
-    private final Iterator source;
+    private final Iterator<TestResult> source;
 
     /**
      * A value indicating whether the underlying source iterator has more values to be read.
      * Use this instead of source.hasNext() when the worker thread is running.
      */
< prev index next >