Example #1
0
 /** Creates a random iterator for the prioritized table. */
 public RandomIterator() {
   outIter = levels.values().iterator();
   if (outIter.hasNext()) {
     currentLevel = outIter.next();
     order = RandomPermutation.nextPermutation(currentLevel.size());
   }
 }
Example #2
0
 /**
  * Returns the next object of the prioritized map. This method may be called repeatedly to
  * iterate through the prioritized map.
  *
  * @return The next object of the prioritized map.
  */
 public E next() {
   // Next object of the current level
   E obj = currentLevel.get(order[current++]);
   // The level has been finished
   if (current == order.length) {
     if (outIter.hasNext()) {
       currentLevel = outIter.next();
       order = RandomPermutation.nextPermutation(currentLevel.size());
       current = 0;
     } else currentLevel = null;
   }
   return obj;
 }