java.lang.Object
cs1302.oracle.OracleCustomLinkedUrgencyQueue<Type>
- Type Parameters:
Type- the item type
- All Implemented Interfaces:
Queue<Type,,UrgencyQueue<Type>> UrgencyQueue<Type>
An "oracle" implementation of
UrgencyQueue
that uses a linked list of Node objects to maintain
its "line" of items and requires a
Comparator Constructor Parameter
so that it can compare items. Although Type does not have any
explicit upper-bound requirements, this class is still able to
determine the relative level of urgency between two items using
the ordering imposed by the comparator supplied to the constructor
(i.e., it uses comparator's
compare(Type, Type) method).-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all items from this urgency queue.dequeue()Retrieves and removes the most urgent item in this urgency queue.voidRemoves the most urgent item in this urgency queue and performs the given action on the removed item.dequeueMany(int num) Builds and returns a new urgency queue that contains the most urgentnumitems dequeued from thisUrgencyQueue.voiddequeueMany(int num, Consumer<Type> action) Removes the most urgentnum-many items in this urgency queue and performs the given action (usingaction.accept) on each item, in the urgency queue.booleanInserts the specified item into this urgency queue.<SubType extends Type>
booleanenqueueAll(Iterable<SubType> values) Enqueues the items contained in the specifiedIterableinto this urgency queue.Builds and returns a new urgency queue consisting of the items of this urgency queue that pass the test specified by the given predicate.peek()Retrieves, but does not remove, the most urgent item in this urgency queue.intsize()Returns the number of items in this urgency queue.Type[]toArray(IntFunction<Type[]> generator) Returns an array containing all of the objects in thisUrgencyQueuein proper sequence (from first to last element, by urgency).toString()Returns a string representation of this urgency queue.
-
Constructor Details
-
OracleCustomLinkedUrgencyQueue
-
-
Method Details
-
enqueue
Description copied from interface:UrgencyQueueInserts the specified item into this urgency queue. The inserted item is placed such that it appears after any existing items with the same or greater level of urgency and before any existing items with a lesser level of urgency.- Parameters:
value- the item to insert- Returns:
- true if this urgency queue was modified as a result of this call
-
dequeueMany
Description copied from interface:UrgencyQueueBuilds and returns a new urgency queue that contains the most urgentnumitems dequeued from thisUrgencyQueue.- Parameters:
num- the number of items to remove and return.- Returns:
- a new urgency queue object containing the most urgent
numitems dequeued from this queue
-
filter
Description copied from interface:UrgencyQueueBuilds and returns a new urgency queue consisting of the items of this urgency queue that pass the test specified by the given predicate. The term predicate usually refers to some function that returns eithertrueorfalse. Here, it refers to the parametercond, which should refer to an object of a class that implements thePredicate<Type>interface. More formally, this method returns a new urgency queue containing all itemsein this queue such thatcond.test(e)returnstrue.- Parameters:
cond- the predicate used to test items of this queue.- Returns:
- a reference to the filtered queue.
- See Also:
-
size
public int size()Description copied from interface:UrgencyQueueReturns the number of items in this urgency queue.- Specified by:
sizein interfaceQueue<Type,UrgencyQueue<Type>> - Specified by:
sizein interfaceUrgencyQueue<Type>- Returns:
- the number of items in this urgency queue.
-
peek
Description copied from interface:UrgencyQueueRetrieves, but does not remove, the most urgent item in this urgency queue.- Specified by:
peekin interfaceQueue<Type,UrgencyQueue<Type>> - Specified by:
peekin interfaceUrgencyQueue<Type>- Returns:
- the most urgent item in the queue.
-
toString
Description copied from interface:UrgencyQueueReturns a string representation of this urgency queue. The string representation consists of each item in the queue, from most urgent to least urgent, in the descending urgency order, separated by the characters", "(comma and space) with opening and closing square ([,]) at the beginning and end, respectively. Each item of the queue is represented by the string value returned by itstoString()method. Here is an example, assumingqueuerefers to an emptyUrgencyQueue<Person>object:
The output would be:queue.enqueue(new Person(22, "Sally")); queue.enqueue(new Person(20, "Billy")); queue.enqueue(new Person(23, "Kuma")); System.out.println(queue);[Person[age=23, name=Kuma], Person[age=22, name=Sally], Person[age=20, name=Billy]]- Specified by:
toStringin interfaceQueue<Type,UrgencyQueue<Type>> - Specified by:
toStringin interfaceUrgencyQueue<Type>- Overrides:
toStringin classObject- Returns:
- the string representation of this urgency queue
-
dequeue
Description copied from interface:UrgencyQueueRetrieves and removes the most urgent item in this urgency queue.- Specified by:
dequeuein interfaceQueue<Type,UrgencyQueue<Type>> - Specified by:
dequeuein interfaceUrgencyQueue<Type>- Returns:
- the most urgent item in the queue.
-
dequeue
Description copied from interface:UrgencyQueueRemoves the most urgent item in this urgency queue and performs the given action on the removed item.- Specified by:
dequeuein interfaceQueue<Type,UrgencyQueue<Type>> - Specified by:
dequeuein interfaceUrgencyQueue<Type>- Parameters:
action- the action to be performed on the removed item.- See Also:
-
dequeueMany
Description copied from interface:UrgencyQueueRemoves the most urgentnum-many items in this urgency queue and performs the given action (usingaction.accept) on each item, in the urgency queue.- Specified by:
dequeueManyin interfaceQueue<Type,UrgencyQueue<Type>> - Specified by:
dequeueManyin interfaceUrgencyQueue<Type>- Parameters:
num- the number of items to remove.action- the action to be performed on the removed items.- See Also:
-
clear
public void clear()Description copied from interface:UrgencyQueueRemoves all items from this urgency queue.- Specified by:
clearin interfaceQueue<Type,UrgencyQueue<Type>> - Specified by:
clearin interfaceUrgencyQueue<Type>
-
enqueueAll
Description copied from interface:UrgencyQueueEnqueues the items contained in the specifiedIterableinto this urgency queue. This method should returnfalseif the specifiedIterableis empty. Otherwise, this method either returnstrueor throws an exception upon failure.- Specified by:
enqueueAllin interfaceQueue<Type,UrgencyQueue<Type>> - Specified by:
enqueueAllin interfaceUrgencyQueue<Type>- Type Parameters:
SubType- the type of the items to be added.- Parameters:
values- the items to add to this queue.- Returns:
trueif this queue is changed as a result of the call;falseotherwise.
-
toArray
Description copied from interface:UrgencyQueueReturns an array containing all of the objects in thisUrgencyQueuein proper sequence (from first to last element, by urgency). Thegeneratorparameter accepts a reference to any method that takes an integer, which is the size of the desired array, and produces an array of the desired size.Here is an example, assuming
queuerefers to a nonemptyUrgencyQueue<Person>object:
The output would be:// print an existing, nonempty urgency queue System.out.print("urgency queue: " + queue); // setup an object that can generate a Person array IntFunction<Person[]> newPersonArray = (int value) -> { return new Person[value]; }; // get the urgency queue's items as an array Person[] persons = queue.toArray(newPersonArray); System.out.println("array length: " + persons.length); System.out.println("first array element: " + persons[0]);urgency queue: [Person[age=23, name=Kuma], Person[age=22, name=Sally]] array length: 2 first array element: Person[age=23, name=Kuma]- Specified by:
toArrayin interfaceQueue<Type,UrgencyQueue<Type>> - Specified by:
toArrayin interfaceUrgencyQueue<Type>- Parameters:
generator- a function which produces a new array of the desired type and the provided size.- Returns:
- an array containing all of the items in this queue in proper sequence.
-