SetIndices.java

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

package hlt.language.util;



This provides an enumeration through the indices of SetOf objects.

NB: once built with the constructor SetIndices(t), an index 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:07:33 2018 by hak



public class SetIndices implements IndexEnumeration
{
  private SetOf set;
  private int position = 0;
  private int[] indices;

  SetIndices (SetOf set)
    {
      setupIndexEnumeration(set);
    }

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

  public SetIndices reset (SetOf set)
    {
      setupIndexEnumeration(set);
      return this;
    }

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

  public final int nextIndex ()
    {
      return (indices == null)
	     ? -1
	     : indices[position++];
    }
}


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