<commit_before>package gov.nih.nci.cagrid.data.wsenum.service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;

import javax.xml.soap.SOAPElement;

import org.globus.ws.enumeration.EnumIterator;
import org.globus.ws.enumeration.IterationConstraints;
import org.globus.ws.enumeration.IterationResult;
import org.globus.ws.enumeration.TimeoutException;
import org.globus.wsrf.utils.AnyHelper;

/** 
 *  LazyQueryResultEnumIterator
 *  EnumIterator implementation to take advantage of LazyCQLQueryProcessor results
 * 
 * @author <A HREF="MAILTO:<EMAIL>"><NAME></A>
 * 
 * @created Aug 7, 2006 
 * @version $Id$ 
 */
public class LazyQueryResultEnumIterator implements EnumIterator {
	private boolean hasBeenReleased = false;
	private Iterator lazyResults = null;
	
	public LazyQueryResultEnumIterator(Iterator lazyResults) {
		this.lazyResults = lazyResults;
	}
	

	public IterationResult next(IterationConstraints constraints) throws TimeoutException, NoSuchElementException {
		if (hasBeenReleased) {
			throw new NoSuchElementException("The enumeration has been released!");
		}
		// list to hold soap elements
		List soapElements = new ArrayList();
		// timer variable
		long startTime = System.currentTimeMillis();
		// compute current state
		int currentSize = soapElements.size();
		int currentChars = computeCharCount(soapElements);
		long currentTime = System.currentTimeMillis() - startTime;
		// iterate the lazy collection
		while (lazyResults.hasNext() && shouldAddElement(constraints, currentSize, currentChars, currentTime)) {
			SOAPElement element = AnyHelper.toAny(lazyResults.next());
			// TODO: what to do if this new element overflows the maxChars?
			soapElements.add(element);
		}
		// Build SOAPElement array and return IterationResult
		SOAPElement[] elements = new SOAPElement[soapElements.size()];
		soapElements.toArray(elements);
		IterationResult result = new IterationResult(elements, lazyResults.hasNext());<commit_msg>*** empty log message ***<commit_after>package gov.nih.nci.cagrid.data.wsenum.service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;

import javax.xml.soap.SOAPElement;

import org.globus.ws.enumeration.EnumIterator;
import org.globus.ws.enumeration.IterationConstraints;
import org.globus.ws.enumeration.IterationResult;
import org.globus.ws.enumeration.TimeoutException;
import org.globus.wsrf.utils.AnyHelper;

/** 
 *  LazyQueryResultEnumIterator
 *  EnumIterator implementation to take advantage of LazyCQLQueryProcessor results
 * 
 * @author <A HREF="MAILTO:<EMAIL>"><NAME></A>
 * 
 * @created Aug 7, 2006 
 * @version $Id$ 
 */
public class LazyQueryResultEnumIterator implements EnumIterator {
	private boolean hasBeenReleased = false;
	private Iterator lazyResults = null;
	
	public LazyQueryResultEnumIterator(Iterator lazyResults) {
		this.lazyResults = lazyResults;
	}
	

	public IterationResult next(IterationConstraints constraints) throws TimeoutException, NoSuchElementException {
		if (hasBeenReleased) {
			throw new NoSuchElementException("The enumeration has been released!");
		}
		// list to hold soap elements
		List soapElements = new ArrayList();
		// timer variable
		long startTime = System.currentTimeMillis();
		// compute current state
		int currentSize = soapElements.size();
		int currentChars = computeCharCount(soapElements);
		long currentTime = System.currentTimeMillis() - startTime;
		// iterate the lazy collection
		while (lazyResults.hasNext() && shouldAddElement(constraints, currentSize, currentChars, currentTime)) {
			SOAPElement element = AnyHelper.toAny(lazyResults.next());
			// TODO: what to do if this new element overflows the maxChars?
			soapElements.add(element);
		}
		// Build SOAPElement array and return IterationResult
		SOAPElement[] elements = new SOAPElement[soapElements.size()];
		soapElements.toArray(elements);
		IterationResult result = new IterationResult(elements, !lazyResults.hasNext());
{'fraction_non_alphanumeric': 0.09686960808479171, 'fraction_numerical': 0.002464875523786049, 'mean_word_length': 5.330733229329173, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4160379', 'n_tokens_mistral': 1253, 'n_tokens_neox': 1148, 'n_words': 287}