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
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 presentaddAll
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
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 staleisEmpty
isEmpty(): boolean#Returns whether the priority-bucket map is empty.
Returns: whether the priority-bucket map is empty
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 presentpeek
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 stalepeekWaiting
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 stalepeekWaiting(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 stalepoll
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 stalepollWaiting
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 stalepollWaiting(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 staleremove
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 absentremove(): 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 staleremoveAll
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
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[]