/** * 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; }
/** * Returns the next object of the prioritized map. This method makes use of the previously * chosen object of a level. Thus, every time this method starts a level, it's started at a * different point. * * @return The next object of the prioritized table. */ public E next() { // Next object of the current level E obj = currentLevel.get(); nObjects--; // The level has been finished if (nObjects == 0) { // Next time this method will start this level at the next object currentLevel.get(); if (outIter.hasNext()) { currentLevel = outIter.next(); nObjects = currentLevel.size(); } } return obj; }
/** 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()); } }
/** Creates an iterator for the prioritized table. */ public BalancedIterator() { outIter = levels.values().iterator(); if (outIter.hasNext()) { currentLevel = outIter.next(); nObjects = currentLevel.size(); } }