< 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,41 ****
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.javatest.util;
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
{
/**
* A constant indicating that no read ahead is required.
* @see #ReadAheadIterator
*/
--- 24,43 ----
* 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<TestResult>
{
/**
* A constant indicating that no read ahead is required.
* @see #ReadAheadIterator
*/
*** 59,69 ****
* @param mode A value indicating the type of read ahead required.
* @see #NONE
* @see #LIMITED
* @see #FULL
*/
! public ReadAheadIterator(Iterator source, int mode) {
this(source, mode, DEFAULT_LIMITED_READAHEAD);
}
/**
* Create a ReadAheadIterator.
--- 61,71 ----
* @param mode A value indicating the type of read ahead required.
* @see #NONE
* @see #LIMITED
* @see #FULL
*/
! public ReadAheadIterator(Iterator<TestResult> source, int mode) {
this(source, mode, DEFAULT_LIMITED_READAHEAD);
}
/**
* Create a ReadAheadIterator.
*** 74,84 ****
* parameter will be ignored.
* @see #NONE
* @see #LIMITED
* @see #FULL
*/
! public ReadAheadIterator(Iterator source, int mode, int amount) {
this.source = source;
setMode(mode, amount);
}
/**
--- 76,86 ----
* parameter will be ignored.
* @see #NONE
* @see #LIMITED
* @see #FULL
*/
! public ReadAheadIterator(Iterator<TestResult> source, int mode, int amount) {
this.source = source;
setMode(mode, amount);
}
/**
*** 171,183 ****
public synchronized boolean hasNext() {
return (queue.size() > 0
|| (worker == null ? source.hasNext() : sourceHasNext));
}
! public synchronized Object next() {
// see if there are items in the read ahead queue
! Object 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
--- 173,185 ----
public synchronized boolean hasNext() {
return (queue.size() > 0
|| (worker == null ? source.hasNext() : sourceHasNext));
}
! public synchronized TestResult next() {
// see if there are items in the read ahead queue
! 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,264 ****
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();
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
--- 256,266 ----
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
! 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,312 ****
// 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();
/**
* 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;
/**
* 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.
*/
--- 296,314 ----
// 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<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<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 >