mondrian.util
Class UnionIterator<T>

java.lang.Object
  extended by mondrian.util.UnionIterator<T>
All Implemented Interfaces:
java.util.Iterator<T>

public class UnionIterator<T>
extends java.lang.Object
implements java.util.Iterator<T>

Iterator over union of several Iterable collections.

Try, for instance, using the over(java.lang.Iterable...) helper method:

List<String> names;
List<String> addresses;
for (Sstring s : UnionIterator.over(names, addresses)) {   print(s);
}

Since:
Apr 28, 2008
Version:
$Id: //open/mondrian/src/main/mondrian/util/UnionIterator.java#6 $
Author:
jhyde

Constructor Summary
UnionIterator(java.util.Collection<? extends T>... iterables)
          Creates a UnionIterator over a list of collections.
UnionIterator(java.lang.Iterable<? extends T>... iterables)
          Creates a UnionIterator.
 
Method Summary
 boolean hasNext()
           
 T next()
           
static
<T> java.lang.Iterable<T>
over(java.util.Collection<? extends T>... collections)
          Returns the union of a list of collections.
static
<T> java.lang.Iterable<T>
over(java.lang.Iterable<? extends T>... iterables)
          Returns the union of a list of iterables.
 void remove()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UnionIterator

public UnionIterator(java.lang.Iterable<? extends T>... iterables)
Creates a UnionIterator.

Parameters:
iterables - Array of iterables

UnionIterator

public UnionIterator(java.util.Collection<? extends T>... iterables)
Creates a UnionIterator over a list of collections.

Parameters:
iterables - Array of collections
Method Detail

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator<T>

next

public T next()
Specified by:
next in interface java.util.Iterator<T>

remove

public void remove()
Specified by:
remove in interface java.util.Iterator<T>

over

public static <T> java.lang.Iterable<T> over(java.lang.Iterable<? extends T>... iterables)
Returns the union of a list of iterables.

You can use it like this:

 Iterable<String> iter1;
 Iterable<String> iter2;
 for (String s : union(iter1, iter2)) {
   print(s);
 }

Parameters:
iterables - Array of one or more iterables
Returns:
iterable over the union of the iterables

over

public static <T> java.lang.Iterable<T> over(java.util.Collection<? extends T>... collections)
Returns the union of a list of collections.

This method exists for code that will be retrowoven to run on JDK 1.4. Retroweaver has its own version of the Iterable interface, which is problematic since the Collection classes don't implement it. This method solves some of these problems by working in terms of collections; retroweaver deals with these correctly.

Parameters:
collections - Array of one or more collections
Returns:
iterable over the union of the collections
See Also:
over(Iterable[])

Get Mondrian at SourceForge.net. Fast, secure and free Open Source software downloads