Class PriorityList<E extends Prioritizable>
java.lang.Object
studio.mevera.imperat.util.priority.PriorityList<E>
- Type Parameters:
E- the type of elements in this list
- All Implemented Interfaces:
Iterable<E>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds an element with the specified priority.@NotNull PriorityList<E>Returns an immutable view of this PriorityList.voidclear()Removes all elements from this list.booleanChecks if this list contains the specified element.voidPerforms the given action for each element in priority order.booleanisEmpty()Checks if this list is empty.iterator()Returns an iterator over the elements in this list, ordered by priority.booleanRemoves an element from this list.intsize()Returns the number of elements in this list.stream()Returns a sequentialStreamof the elements in this list, ordered by priority.toList()Returns a list of all elements in priority order.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
spliterator
-
Constructor Details
-
PriorityList
public PriorityList()Creates a new empty PriorityList.
-
-
Method Details
-
add
Adds an element with the specified priority. If the element already exists, it will not be added again.- Parameters:
element- the element to add- Returns:
- true if the element was added, false if it already existed
-
remove
Removes an element from this list.- Parameters:
element- the element to remove- Returns:
- true if the element was removed, false if it wasn't present
-
contains
Checks if this list contains the specified element.- Parameters:
element- the element to check for- Returns:
- true if the element is present
-
size
public int size()Returns the number of elements in this list.- Returns:
- the size of this list
-
isEmpty
public boolean isEmpty()Checks if this list is empty.- Returns:
- true if this list contains no elements
-
clear
public void clear()Removes all elements from this list. -
iterator
Returns an iterator over the elements in this list, ordered by priority. Elements with higher priority are returned first. The TreeMap maintains sorted order, so no additional sorting is needed.- Specified by:
iteratorin interfaceIterable<E extends Prioritizable>- Returns:
- an iterator over the elements
-
forEach
Performs the given action for each element in priority order.- Specified by:
forEachin interfaceIterable<E extends Prioritizable>- Parameters:
action- the action to perform
-
toList
Returns a list of all elements in priority order.- Returns:
- a new list containing all elements
-
stream
Returns a sequentialStreamof the elements in this list, ordered by priority. Elements with higher priority are returned first.- Returns:
- a sequential stream of elements in priority order
-
asUnmodifiable
Returns an immutable view of this PriorityList. The returned list will reflect any changes made to the underlying list, but mutation operations will throwUnsupportedOperationException.- Returns:
- an immutable view of this PriorityList
-
toString
-