next up previous contents
Next: xPoint Class Up: MyUtil Package Previous: Trash Class

UNNL Class

The UNNL class implements a unused natural number list. That is, a UNNL produces a sequence of natural numbers which have either not been used, or have been returned for reuse. The GraphPanel class uses two UNNL objects to number Vertex objects.

package MyUtil;

import java.util.Stack;

public class UNNL extends Stack {

   public UNNL () {
      super ();
      push (new Integer (1));
   }

   public int get() {
      Integer tmp = (Integer)pop();
      if (isEmpty()) 
         push(new Integer(tmp.intValue() + 1));
      return tmp.intValue();
   }

   public void reuse(int n){
      if (n>0) {
         Integer tmp = new Integer(n);
         if (!contains(tmp))
            push(tmp);
      }
   }

}



Kelly Waters
Mon Oct 27 18:18:15 EST 1997