SetIterator.java

//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// PLEASE DO NOT EDIT WITHOUT THE EXPLICIT CONSENT OF THE AUTHOR! \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\

package hlt.language.util;

import java.util.Iterator;



This provides an iterator for SetOf objects. NB: this is an exact replica of the implementation of SetEnumeration with the additional (non-supported) remove() method as mandated by the java.util.Iterator interface.

NB: once built wih the constructor SetIterator(s), a set iterator will not be altered if a set s is modified. In other words, it will keep iterating through the elements of the original set. This is why the method reset(SetOf) is provided.

See also:  SetOf
Copyright:  © Hassan Aït-Kaci
Author:  Hassan Aït-Kaci
Version:  Last modified on Sun Mar 25 09:06:30 2018 by hak



public class SetIterator implements Iterator
{
  private SetOf set;
  private int position = 0;
  private int[] indices;

  SetIterator (SetOf set)
    {
      setupIterator(set);
    }

  private void setupIterator (SetOf set)
    {
      if (set.indices == null) set.buildIndices();
      this.indices = set.indices;
      this.set = set;
    }

  public SetIterator reset (SetOf set)
    {
      setupIterator(set);
      return this;
    }

  public final boolean hasNext ()
    {
      return (indices != null) && (position < indices.length);
    }

  public final Object next ()
    {
      return (indices == null)
             ? null
             : set.base.get(indices[position++]);
    }

  

This method is not implemented - it just throws an UnsupportedOperationException.


  public final void remove ()
    {
      throw new UnsupportedOperationException();
    }
}







This file was generated on Sat May 11 08:40:08 CEST 2019 from file SetIterator.java
by the hlt.language.tools.Hilite Java tool written by Hassan Aït-Kaci