DESY ACOP Beans Home

com.cosylab.util
Class Iterators

java.lang.Object
  extended by com.cosylab.util.Iterators

public class Iterators
extends java.lang.Object

Utilities for working with iterators.

Author:
Klemen Zagar, Cosylab

Constructor Summary
Iterators()
           
 
Method Summary
static boolean areEqual(java.util.Iterator<? extends java.lang.Object> iterA, java.util.Iterator<? extends java.lang.Object> iterB)
          Determine whether two iterators iterate through the same set of elements.
static boolean areEqualOrder(java.util.Iterator<? extends java.lang.Object> iterA, java.util.Iterator<? extends java.lang.Object> iterB)
          Do two iterators iterate through the same elements in the same order?
static
<T> java.util.Iterator<T>
distinct(java.util.Iterator<T> iter)
          Create an iterator that iterates only through distinct values.
static
<T> java.util.Iterator<T>
intersect(java.util.Iterator<T> iterA, java.util.Iterator<T> iterB)
          Intersection of two iterators.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Iterators

public Iterators()
Method Detail

areEqual

public static boolean areEqual(java.util.Iterator<? extends java.lang.Object> iterA,
                               java.util.Iterator<? extends java.lang.Object> iterB)
Determine whether two iterators iterate through the same set of elements. If the same element appears more than once in the set, it is treated as if it appeared exactly once.

Note: This implementation is not efficient for iterators over large sets, as it first puts elements of both iterators in two sets, and then compares the sets.

Parameters:
iterA - First iterator.
iterB - Second iterator.
Returns:
true if elements are the same.

areEqualOrder

public static boolean areEqualOrder(java.util.Iterator<? extends java.lang.Object> iterA,
                                    java.util.Iterator<? extends java.lang.Object> iterB)
Do two iterators iterate through the same elements in the same order?

Parameters:
iterA - First iterator.
iterB - Second iterator.
Returns:
true if the iteration order is the same.

intersect

public static <T> java.util.Iterator<T> intersect(java.util.Iterator<T> iterA,
                                                  java.util.Iterator<T> iterB)
Intersection of two iterators.

Note: the implementation is such that the first iterator (iterA) is first traversed in its entirety. Whenever possible, iterA should be the shorter of the two iterators.

Type Parameters:
T - Type across which the iterator iterates.
Parameters:
iterA - First iterator.
iterB - Second iterator.
Returns:
Iterator through items traversed both by iterA and iterB.

distinct

public static <T> java.util.Iterator<T> distinct(java.util.Iterator<T> iter)
Create an iterator that iterates only through distinct values.

Type Parameters:
T - Type across which the iterator is iterating.
Parameters:
iter - The underlying iterator.
Returns:
The iterator that iterates only through distinct values.


Copyright © 2010. All Rights Reserved.