Skip to content

PrioryFiFoTaskQueue ​

com.jsmacrosce.PrioryFiFoTaskQueue

A queue that deduplicates entries by equality and groups them into integer-priority buckets,
preserving insertion order within each bucket. When adding to an empty membership set, the entry becomes the cached head. Removing the head through the queue's head-removal operation selects the next head from the lowest-priority bucket; removing entries by value or clearing the queue does not refresh the cached head. size() counts occupied priority buckets, not entries.

js
const Queue = Java.type("com.jsmacrosce.PrioryFiFoTaskQueue");  
const Integer = Java.type("java.lang.Integer");  
const queue = new Queue(JavaWrapper.methodToJava(function(value) {
 return Integer.valueOf(String(value));  
}));  
queue.add("2");  
queue.add("1");  
Chat.log(queue.poll());

Type Parameters ​

  • E: queued entry type

Constructors ​

new PrioryFiFoTaskQueue ​

new PrioryFiFoTaskQueue(Function<E, Integer> priorityFunction)#
Stores the function used to obtain each entry's stable integer priority; it is not evaluated here.

Parameters:

  • priorityFunction: non-null function providing a stable integer priority per entry

Methods ​

add ​

add(E e): boolean#
Adds an entry if no equal entry is already present. The priority function is evaluated for a new entry; adding a lower-priority entry does not replace the cached head while the membership set is nonempty.

Parameters:

  • e: non-null entry with a stable priority
Returns: true if added; false if already present

addAll ​

addAll(Collection<? extends E> collection): boolean#
Adds entries in collection iteration order; additions completed before a failure are not rolled back.

Parameters:

  • collection: entries to add
Returns: whether at least one entry was added

clear ​

clear(): void#
Clears the membership set and priority buckets without resetting the cached head or notifying waiters.

contains ​

contains(Object o): boolean#
Checks whether the membership set contains the candidate entry.

Parameters:

  • o: candidate entry
Returns: whether the entry is present

containsAll ​

containsAll(Collection<?> collection): boolean#
Checks whether every supplied entry is in the membership set.

Parameters:

  • collection: entries to check
Returns: whether all entries are present

element ​

element(): E#
Returns the cached head without checking membership or removing it.
Returns: the cached head, or null if the cache is empty; it may be stale

isEmpty ​

isEmpty(): boolean#
Returns whether the priority-bucket map is empty.
Returns: whether the priority-bucket map is empty

iterator ​

iterator(): Iterator<E>#
Returns a live iterator over the membership set; iteration order is unspecified and is not priority order. Removing through the iterator changes only the membership set, not the priority buckets or cached head.
Returns: live membership-set iterator

offer ​

offer(E e): boolean#
Adds an entry using the queue's deduplication and priority behavior.

Parameters:

  • e: non-null entry with a stable priority
Returns: true if newly added; false if an equal entry is already present

peek ​

peek(): E#
Returns the cached head without checking membership or removing it.
Returns: the cached head, or null if the cache is empty; it may be stale

peekWaiting ​

peekWaiting(): E#
Waits once if membership is empty, then returns the cached head without removing it or rechecking membership. Wait interruption propagates as InterruptedException.
Returns: the cached head, which may be null or stale
peekWaiting(long timeout): E#
Waits once if membership is empty, then returns the cached head without removing it or rechecking membership. Wait interruption propagates as InterruptedException.

Parameters:

  • timeout: wait duration in milliseconds; zero waits indefinitely, and a negative value is invalid if waiting occurs
Returns: the cached head, which may be null or stale

poll ​

poll(): E#
Removes and returns the cached head using the queue's head-removal behavior.
Returns: the previous cached head, or null if the cache was empty; the cached entry may be stale

pollWaiting ​

pollWaiting(): E#
Waits until the membership set is nonempty, then removes and returns the cached head. Wait interruption propagates as InterruptedException.
Returns: the cached-head removal result, which may be null or stale
pollWaiting(long timeout): E#
While membership is empty, tracks wall-clock elapsed wait time against the budget, then attempts to remove and return the cached head even if the budget has expired or membership remains empty; this does not guarantee an exact deadline. Nonpositive budgets skip waiting. Wait interruption propagates as InterruptedException.

Parameters:

  • timeout: wait budget in milliseconds; nonpositive values skip waiting
Returns: the cached-head removal result, which may be null or stale

remove ​

remove(Object o): boolean#
Removes an entry and its bucket membership using its current priority-function result. This does not refresh the cached head; entries therefore need stable priorities.

Parameters:

  • o: entry to remove
Returns: true if present and removed; false if absent
remove(): E#
Removes and returns the cached head, then refreshes it from the lowest-priority bucket when non-null.
Returns: the previous cached head, or null if the cache was empty; the cached entry may be stale

removeAll ​

removeAll(Collection<?> collection): boolean#
Removes entries in collection iteration order through value removal; completed removals are not rolled back on failure. The cached head is not refreshed.

Parameters:

  • collection: entries to remove
Returns: whether any entry was removed, if the operation completes

retainAll ​

retainAll(Collection<?> collection): boolean#
Removes entries absent from the collection while iterating the live membership set; structural removals during iteration can cause ConcurrentModificationException after partial removal, so complete retention is not guaranteed. The cached head is not refreshed.

Parameters:

  • collection: entries to keep
Returns: whether any entry was removed, if the operation completes

size ​

size(): int#
Returns the number of priority buckets containing entries, not the number of entries.
Returns: occupied priority bucket count

toArray ​

toArray(): Object[]#
Returns an array of membership-set entries in unspecified order.
Returns: membership entries
toArray(T[] ts): T[]#
Copies membership-set entries into an array, using the supplied array when it is large enough.

Parameters:

  • ts: destination array

Type Parameters:

  • T: destination array component type
Returns: membership entries in the supplied array when large enough, or a new array otherwise
toArray(IntFunction<T[]> arg0): T[]#

Returns: T[]