一、前言
关于jsoup(1.6.1)源码包中org.jsoup.helper.DescendableLinkedList自定义双向链表,继承java.util.LinkedList双向链表基础类,同时自定义DescendingIterator内部类进行元素遍历,详情参见源码说明。
二、源码说明
package org.jsoup.helper;@b@@b@import java.util.Iterator;@b@import java.util.LinkedList;@b@import java.util.ListIterator;@b@@b@public class DescendableLinkedList<E> extends LinkedList<E>@b@{@b@ public void push(E e)@b@ {@b@ addFirst(e);@b@ }@b@@b@ public E peekLast()@b@ {@b@ return ((size() == 0) ? null : getLast());@b@ }@b@@b@ public E pollLast()@b@ {@b@ return ((size() == 0) ? null : removeLast());@b@ }@b@@b@ public Iterator<E> descendingIterator()@b@ {@b@ return new DescendingIterator(this, size(), null);@b@ }@b@@b@ private class DescendingIterator<E> implements Iterator<E>@b@ {@b@ private final ListIterator<E> iter;@b@@b@ private DescendingIterator(, int paramInt) {@b@ this.iter = paramDescendableLinkedList.listIterator(index);@b@ }@b@@b@ public boolean hasNext()@b@ {@b@ return this.iter.hasPrevious();@b@ }@b@@b@ public E next()@b@ {@b@ return this.iter.previous();@b@ }@b@@b@ public void remove()@b@ {@b@ this.iter.remove();@b@ }@b@ }@b@}