aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/org/jsoup/helper/DescendableLinkedList.java
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-08-13 18:34:33 +0300
committerArtur Signell <artur@vaadin.com>2012-08-13 19:18:33 +0300
commite85d933b25cc3c5cc85eb7eb4b13b950fd8e1569 (patch)
tree9ab6f13f7188cab44bbd979b1cf620f15328a03f /server/src/org/jsoup/helper/DescendableLinkedList.java
parent14dd4d0b28c76eb994b181a4570f3adec53342e6 (diff)
downloadvaadin-framework-e85d933b25cc3c5cc85eb7eb4b13b950fd8e1569.tar.gz
vaadin-framework-e85d933b25cc3c5cc85eb7eb4b13b950fd8e1569.zip
Moved server files to a server src folder (#9299)
Diffstat (limited to 'server/src/org/jsoup/helper/DescendableLinkedList.java')
-rw-r--r--server/src/org/jsoup/helper/DescendableLinkedList.java82
1 files changed, 82 insertions, 0 deletions
diff --git a/server/src/org/jsoup/helper/DescendableLinkedList.java b/server/src/org/jsoup/helper/DescendableLinkedList.java
new file mode 100644
index 0000000000..28ca1971eb
--- /dev/null
+++ b/server/src/org/jsoup/helper/DescendableLinkedList.java
@@ -0,0 +1,82 @@
+package org.jsoup.helper;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.ListIterator;
+
+/**
+ * Provides a descending iterator and other 1.6 methods to allow support on the 1.5 JRE.
+ */
+public class DescendableLinkedList<E> extends LinkedList<E> {
+
+ /**
+ * Create a new DescendableLinkedList.
+ */
+ public DescendableLinkedList() {
+ super();
+ }
+
+ /**
+ * Add a new element to the start of the list.
+ * @param e element to add
+ */
+ public void push(E e) {
+ addFirst(e);
+ }
+
+ /**
+ * Look at the last element, if there is one.
+ * @return the last element, or null
+ */
+ public E peekLast() {
+ return size() == 0 ? null : getLast();
+ }
+
+ /**
+ * Remove and return the last element, if there is one
+ * @return the last element, or null
+ */
+ public E pollLast() {
+ return size() == 0 ? null : removeLast();
+ }
+
+ /**
+ * Get an iterator that starts and the end of the list and works towards the start.
+ * @return an iterator that starts and the end of the list and works towards the start.
+ */
+ public Iterator<E> descendingIterator() {
+ return new DescendingIterator<E>(size());
+ }
+
+ private class DescendingIterator<E> implements Iterator<E> {
+ private final ListIterator<E> iter;
+
+ @SuppressWarnings("unchecked")
+ private DescendingIterator(int index) {
+ iter = (ListIterator<E>) listIterator(index);
+ }
+
+ /**
+ * Check if there is another element on the list.
+ * @return if another element
+ */
+ public boolean hasNext() {
+ return iter.hasPrevious();
+ }
+
+ /**
+ * Get the next element.
+ * @return the next element.
+ */
+ public E next() {
+ return iter.previous();
+ }
+
+ /**
+ * Remove the current element.
+ */
+ public void remove() {
+ iter.remove();
+ }
+ }
+}