SetEnumeration.java

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

package hlt.language.util;

import java.util.Enumeration;
import java.util.NoSuchElementException;



This provides an enumeration for SetOf objects.

NB: once built with the constructor SetEnumeration(s), an enumeration will not be altered if a set s is modified. In other words, it will keep enumerating all and only 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:05:52 2018 by hak



public class SetEnumeration implements Enumeration
{
  private SetOf set;
  private int position = 0;
  private int[] indices;

  SetEnumeration (SetOf set)
    {
      setupEnumeration(set);
    }

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

  public SetEnumeration reset (SetOf set)
    {
      setupEnumeration(set);
      return this;
    }

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

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



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