2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
26 package org.forester.phylogeny.iterators;
28 import java.util.NoSuchElementException;
30 import org.forester.phylogeny.PhylogenyNode;
33 * An iterator to forward iterate over child nodes of a PhylogenyNode. Created:
34 * 10/23/2005 by Christian M. Zmasek. Last modified: 12/28/2006 by Christian M.
37 * @author Christian M. Zmasek
41 public class ChildNodeIteratorForward implements PhylogenyNodeIterator {
46 final private PhylogenyNode _node;
51 * Creates a new ChildNodeIteratorForward.
54 * the parent of the PhylogenyNodes to iterate over.
55 * @throws IllegalArgumentException
56 * if node has no child nodes
58 public ChildNodeIteratorForward( final PhylogenyNode node ) throws IllegalArgumentException {
59 if ( node.getNumberOfDescendants() < 1 ) {
60 throw new IllegalArgumentException( "Attempt to use ChildNodeIteratorForward on node with no child nodes." );
69 * Returns the counter.
76 * Returns the parent of the nodes to iterate over.
78 * @return the parent of the nodes to iterate over.
80 private PhylogenyNode getNode() {
87 * Returns true is this iterator has at least one more element, false
90 * @return true is this iterator has at least one more element, false
94 public boolean hasNext() {
95 return ( getI() < getNode().getNumberOfDescendants() );
99 * Increases the counter by one.
101 private void increaseI() {
106 * Returns the next PhylogenyNode.
108 * @return the next PhylogenyNode
109 * @throws NoSuchElementException
110 * if iteration is complete
113 public PhylogenyNode next() throws NoSuchElementException {
115 throw new NoSuchElementException( "Attempt to call \"next()\" on iterator which has no more next elements." );
117 final PhylogenyNode n = getNode().getChildNode( getI() );
127 public void remove() {
128 throw new UnsupportedOperationException();
132 * Resets the iterator.
135 public void reset() {
142 private void setI( final int i ) {
145 } // end of class ChildNodeIteratorForward.