List of utility methods to do Queue Usage
List | loadBalancingLeftHeavy(List load Balancing Left Heavy Queue<T> sucQueue = new LinkedList<T>(); sucQueue.addAll(tasks); int todo_size = sucQueue.size(); List<List<T>> pList = new ArrayList<List<T>>(size); for (int i = 0; i < size; i++) pList.add(new LinkedList<T>()); T t1; int b = 0; ... |
void | offerUntilSuccess(T entry, Queue Certain types of queues will fail to java.util.Queue#offer(Object) an item due to many factors depending on the type of queue. boolean success; do { success = queue.offer(entry); Thread.yield(); } while (!success); |
Queue | parsePathToStack(String path) parse Path To Stack Queue<String> queue = new LinkedList<>(); String[] pathParts = path.split("/"); if (pathParts != null && pathParts.length > 0) { for (String part : pathParts) { if (part.length() > 0) { queue.add(part); return queue; |
T | pollWhileNotEmpty(Queue Certain types of queues will return null when calling java.util.Queue#poll() due to many factors depending on the type of queue. T item = queue.poll(); while (!queue.isEmpty() && item == null) { Thread.yield(); item = queue.poll(); return item; |
void | queue(final Queue Cast the object and feel the queue. if (o != null && Queue.class.isAssignableFrom(o.getClass())) { Queue<?> mObj = (Queue<?>) o; for (Object obj : mObj) { setQueueValue(queue, obj, clazz, removeNull); |
char[] | randomizeIndex(char[] array) randomize Index char[] randomArray = new char[array.length]; List<Integer> set = new ArrayList<>(); while (set.size() < array.length) { int index = (int) (Math.random() * array.length); if (!set.contains(index)) { set.add(index); Queue<Integer> queue = new LinkedList<>(set); int i = 0; while (!queue.isEmpty()) { randomArray[i++] = array[queue.poll()]; return randomArray; |
String | scramble(Object object) Will alter the order of the letters in the String representation of an Object. String string = object.toString(); char[] array = string.toCharArray(); char[] randomArray = randomizeIndex(array); return new String(randomArray); |
void | setQueueValue(final Queue Set the queue value. if (obj != null && clazz.isAssignableFrom(obj.getClass())) { queue.add(clazz.cast(obj)); } else if (obj == null && !removeNull) { queue.add(null); |
void | toArrayTest(Queue to Array Test if (q.toArray().length != 0) { throw new RuntimeException(); Object testObject = new Object(); q.add(testObject); Object[] result = q.toArray(); verify(result.length == 1); verify(result[0] == testObject); ... |
void | transferAllElementsFromListToQueue(final List transfer All Elements From List To Queue for (final Type element : elements) { queue.add(element); |