Logo
Distributed Genetic Programming Framework
print print

File org.sfc.collections.ArrayIterator.java

Here you can find all the information about the file org.sfc.collections.ArrayIterator.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2006 Thomas Weise
 * 
 * E-Mail           : tweise@gmx.de
 * Creation Date    : 2006-06-14 11:41:02
 * Original Filename: org.sfc.collections.ArrayIterator.java
 * Version          : 1.0.0
 * Last modification: 2006-06-14
 *                by: Thomas Weise
 * 
 * License          : GNU LESSER GENERAL PUBLIC LICENSE
 *                    Version 2.1, February 1999
 *                    You should have received a copy of this license along
 *                    with this library; if not, write to the Free Software
 *                    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *                    MA 02111-1307, USA or download the license under
 *                    http://www.gnu.org/copyleft/lesser.html.
 *                    
 * Warranty         : This software is provided "as is" without any
 *                    warranty; without even the implied warranty of
 *                    merchantability or fitness for a particular purpose.
 *                    See the Gnu Lesser General Public License for more
 *                    details.
 */

 
package org.sfc.collections;

import java.util.NoSuchElementException;

/**
 * This class iterates over a passed in array.
 * @param <ItemType>  The sort of items to iterate over.
 * @author Thomas Weise
 */

public final class ArrayIterator<ItemType>  extends IteratorBase<ItemType>
  {
/**
 * The data.
 */

  private final ItemType[]  m_data  ;
/**
 * The current index.
 */

  private       int         m_index ;
/**
 * The counter.
 */

  private       int         m_cnt ;
  
  
/**
 * Create a new array iterator.
 * @param p_data  The array to iterate over. 
 */

  public  ArrayIterator (final ItemType[] p_data)
    {
    this(p_data, 0, p_data.length);
    }
  
/**
 * Create a new array iterator.
 * @param p_data    The data to iterate over.
 * @param p_index   The start index.
 * @param p_count   The count of items in the iteration.
 */

  public  ArrayIterator(final ItemType[]  p_data,
                        final int         p_index,
                        final int         p_count)
    {
    super();
    this.m_data  = p_data;
    this.m_index = p_index;
    this.m_cnt   = p_count;
    }
  
/**
 * Returns <tt>true</tt> if the iteration has more elements. (In other
 * words, returns <tt>true</tt> if <tt>next</tt> would return an element
 * rather than throwing an exception.)
 *
 * @return <tt>true</tt> if the iterator has more elements.
 */

  public  final boolean hasNext()
    {
    return (this.m_cnt > 0);
    }

/**
 * Returns the next element in the iteration.  Calling this method
 * repeatedly until the {@link #hasNext()} method returns false will
 * return each element in the underlying collection exactly once.
 *
 * @return the next element in the iteration.
 * @exception NoSuchElementException iteration has no more elements.
 */

  public  final ItemType next()
    {
    if( (this.m_cnt--) > 0 )
      {
      return this.m_data[this.m_index++];
      }
    throw new NoSuchElementException();
    }
  }

File Information:

file name:ArrayIterator.java
package:org.sfc.collections
qualified name:org.sfc.collections.ArrayIterator.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/sfc/collections/ArrayIterator.java
size:3.066 KB (3140 B)
uploaded: 2015-07-22 04:11:11 GMT+0000
last update: 2006-06-14 08:51:17 GMT+0000
last access: 2018-01-22 00:01:33 GMT+0000

statistics online since 2006-01-02.   RSS Feed
Contact us by sending an email to tweise@gmx.de to receive further information, to report errors, or to join our project.
All content on this site (http://dgpf.sourceforge.net/) is LGPL-licensed.
http://dgpf.sourceforge.net/scripts/source/source.php last modified at 2015-07-22 04:10:53 GMT+0000 served at 2018-01-22 00:01:33 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo