All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.day.util.CompoundIterator Maven / Gradle / Ivy

/*
 * $Id: CompoundIterator.java 12345 2004-08-22 04:56:09Z fielding $
 *
 * Copyright 1997-2004 Day Management AG
 * Barfuesserplatz 6, 4001 Basel, Switzerland
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * Day Management AG, ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Day.
 */

package com.day.util;

import java.util.Iterator;

/**
 * Implements the Iterator interface and combines two
 * Iterator objects into one single Iterator.
 * 

* The constructor takes two Iterator arguments: parent * and child. Calling {@link #next} on this Iterator * will first try to return an element from the parent Iterator * and once the parent Iterator does not have any more elements * it will return elements from the child Iterator. * * @version $Revision: 1.2 $, $Date: 2004-08-22 06:56:09 +0200 (Sun, 22 Aug 2004) $ * @author mreutegg * @since fennec * @audience wad */ public class CompoundIterator implements Iterator { /** * The parent Iterator. Elements from this * Iterator are returned first. */ private final Iterator parent; /** * The child Iterator. Elements from this * Iterator are returned, after the parent * Iterator does not have elements any more. */ private final Iterator child; /** * Creates a CompoundIterator based on parent * and child. This CompountIterator will first * return elements from parent and then elements from * child. * @param parent the Iterator from where to return the elements * first. * @param child the Iterator from where to return the elements * after parent does not have elements any more. */ public CompoundIterator(Iterator parent, Iterator child) { this.parent = parent; this.child = child; } /** * Returns true if either parent or child iterator * has a next element; false otherwise. * @return true if either parent or child iterator * has a next element; false otherwise. */ public boolean hasNext() { return parent.hasNext() || child.hasNext(); } /** * Returns the next element from the parent or the child * iterator object. * @return the next element from the parent or the child * iterator object. */ public Object next() { return (parent.hasNext()) ? parent.next() : child.next(); } /** * Always throws UnsupportedOperationException * @throws UnsupportedOperationException always! */ public void remove() throws UnsupportedOperationException { throw new UnsupportedOperationException("remove() is not supported in CompoundInterator"); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy