diff options
Diffstat (limited to 'src/main/java/utils/VSPriorityQueue.java')
| -rw-r--r-- | src/main/java/utils/VSPriorityQueue.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/main/java/utils/VSPriorityQueue.java b/src/main/java/utils/VSPriorityQueue.java new file mode 100644 index 0000000..d706352 --- /dev/null +++ b/src/main/java/utils/VSPriorityQueue.java @@ -0,0 +1,32 @@ +package utils; + +import java.util.PriorityQueue; + +/** + * The class VSPriorityQueue. This class is the same like the standard + * VSPriorityQueue of the Java API. It only overrides the get(int) method. + * + * @author Paul C. Buetow + */ +public final class VSPriorityQueue<T> extends PriorityQueue<T> { + /** The serial version uid */ + private static final long serialVersionUID = 1L; + + /** + * Gets the specific element. If the index is out of bounds, it will return + * null. + * + * @param index the index + * + * @return the element, or null, if out of bounds + */ + public T get(int index) { + int i = 0; + + for (T t : this) + if (i++ == index) + return t; + + return null; + } +} |
