Package mondrian.util

Class UnionIterator<T>

  • All Implemented Interfaces:
    Iterator<T>

    public class UnionIterator<T>
    extends Object
    implements Iterator<T>
    Iterator over union of several Iterable collections.

    Try, for instance, using the over(java.lang.Iterable<? extends T>...) helper method:

    List<String> names;
    List<String> addresses;
    for (Sstring s : UnionIterator.over(names, addresses)) {   print(s);
    }
    Since:
    Apr 28, 2008
    Author:
    jhyde
    • Constructor Detail

      • UnionIterator

        public UnionIterator​(Iterable<? extends T>... iterables)
        Creates a UnionIterator.
        Parameters:
        iterables - Array of iterables
      • UnionIterator

        public UnionIterator​(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 Iterator<T>
      • next

        public T next()
        Specified by:
        next in interface Iterator<T>
      • remove

        public void remove()
        Specified by:
        remove in interface Iterator<T>
      • over

        public static <T> Iterable<T> over​(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> Iterable<T> over​(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[])