Class RedBlackTree<T extends Number & Comparable<T>>
java.lang.Object
nl.tudelft.simulation.dsol.eventlists.RedBlackTree<T>
- Type Parameters:
T
- The time type, e.g., Double, Long, Duration
- All Implemented Interfaces:
Serializable
,Iterable<SimEventInterface<T>>
,EventListInterface<T>
- Direct Known Subclasses:
TableModelEventList
public class RedBlackTree<T extends Number & Comparable<T>>
extends Object
implements EventListInterface<T>
A RedBlackTree implementation of the eventlistInterface. This implementation is based on Java's TreeSet. This implementation
embeds the data structure in the event list instead of extending it (extension has the chance that future implementations can
break the EventList, and that the user can use functions that do not belong to an EventList).
Copyright (c) 2002-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can be found at https://https://simulation.tudelft.nl/dsol/docs/latest/license.html.
- Since:
- 1.5
- Author:
- Alexander Verbraec
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(SimEventInterface<T> event) Add an event to the event list.void
clear()
Clear the event list.boolean
contains
(SimEventInterface<T> event) Return whether this event list contains the given event.first()
Returns the first event (lowest time / priority) of the event list.boolean
isEmpty()
Return whether the event list is empty.iterator()
Provide an iterator to loop over the event list.boolean
remove
(SimEventInterface<T> event) Remove the given event from the event list.Returns and removes the first event (lowest time / priority) of the event list.int
size()
Return the number of events on the event list.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
RedBlackTree
public RedBlackTree()Constructs a newRedBlackTree
.
-
-
Method Details
-
removeFirst
Returns and removes the first event (lowest time / priority) of the event list. The method returns null when the event list is empty.- Specified by:
removeFirst
in interfaceEventListInterface<T extends Number & Comparable<T>>
- Returns:
- SimEventInterface<T>; the first element in this event list before removal, or null when the list is empty
-
first
Returns the first event (lowest time / priority) of the event list. The method returns null when the event list is empty.- Specified by:
first
in interfaceEventListInterface<T extends Number & Comparable<T>>
- Returns:
- SimEventInterface<T>; the first element currently in this event list, or null when the list is empty
-
add
Add an event to the event list.- Specified by:
add
in interfaceEventListInterface<T extends Number & Comparable<T>>
- Parameters:
event
- SimEventInterface<T>; the event to add
-
contains
Return whether this event list contains the given event.- Specified by:
contains
in interfaceEventListInterface<T extends Number & Comparable<T>>
- Parameters:
event
- SimEventInterface<T>; the event to search for- Returns:
- boolean; whether the event list contains the given event
-
clear
public void clear()Clear the event list.- Specified by:
clear
in interfaceEventListInterface<T extends Number & Comparable<T>>
-
isEmpty
public boolean isEmpty()Return whether the event list is empty.- Specified by:
isEmpty
in interfaceEventListInterface<T extends Number & Comparable<T>>
- Returns:
- boolean; whether the event list is empty
-
iterator
Provide an iterator to loop over the event list.- Specified by:
iterator
in interfaceEventListInterface<T extends Number & Comparable<T>>
- Specified by:
iterator
in interfaceIterable<T extends Number & Comparable<T>>
- Returns:
- Iterator<SimEventInterface<T>>; an iterator to loop over the event list
-
remove
Remove the given event from the event list.- Specified by:
remove
in interfaceEventListInterface<T extends Number & Comparable<T>>
- Parameters:
event
- SimEventInterface<T>; the event to remove- Returns:
- boolean to indicate success of the removal operation
-
size
public int size()Return the number of events on the event list.- Specified by:
size
in interfaceEventListInterface<T extends Number & Comparable<T>>
- Returns:
- int; the number of events on the event list
-