LimeWire Collection Component API

org.limewire.collection
Class DualIterator<T>

java.lang.Object
  extended by org.limewire.collection.DualIterator<T>
All Implemented Interfaces:
Iterator<T>

public class DualIterator<T>
extends Object
implements Iterator<T>

Provides an iterator that iterates over two other iterators, in order.

    LinkedList<String> l1 = new LinkedList<String>();
    LinkedList<String> l2 = new LinkedList<String>();
    for(int i = 0; i < 5; i++){
        l1.add(String.valueOf(i));
        l2.add(String.valueOf(i + 10));
    }

    for(DualIterator<String> di = 
            new DualIterator<String>(l1.iterator(), l2.iterator()); di.hasNext();)    
        System.out.println(di.next());      

    Output:
        0
        1
        2
        3
        4
        10
        11
        12
        13
        14


Constructor Summary
DualIterator(Iterator<T> a, Iterator<T> b)
          Constructs a new DualIterator backed by two iterators.
 
Method Summary
 boolean hasNext()
          Determines if there are any elements left in either iterator.
 T next()
          Retrieves the next element from the current backing iterator.
 void remove()
          Removes the element from the current backing iterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DualIterator

public DualIterator(Iterator<T> a,
                    Iterator<T> b)
Constructs a new DualIterator backed by two iterators.

Method Detail

hasNext

public boolean hasNext()
Determines if there are any elements left in either iterator.

Specified by:
hasNext in interface Iterator<T>

next

public T next()
Retrieves the next element from the current backing iterator.

Specified by:
next in interface Iterator<T>

remove

public void remove()
Removes the element from the current backing iterator.

Specified by:
remove in interface Iterator<T>

LimeWire Collection Component API

Copyright © 2009 Lime Wire LLC. All Rights Reserved.