org.limewire.collection
Class FixedSizeSortedList<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
org.limewire.collection.TreeList<E>
org.limewire.collection.SortedList<E>
org.limewire.collection.FixedSizeSortedList<E>
- All Implemented Interfaces:
- Iterable<E>, Collection<E>, List<E>
public class FixedSizeSortedList<E>
- extends SortedList<E>
Gives a sorted list of elements with a maximum size. Elements are sorted
upon insertion to the list, but only a fixed number of items are allowed.
Therefore, if the list has reached the capacity, the last ordered element
is removed and then the new element is inserted in the proper location.
FixedSizeSortedList<String> fssl = new FixedSizeSortedList<String>(5);
fssl.add("Abby");
fssl.add("Abby");
fssl.add("Bob");
fssl.add("Chris");
fssl.add("Dan");
System.out.println(fssl);
fssl.add("Eric");
System.out.println(fssl);
fssl.add("Abby");
System.out.println(fssl);
Output:
[Abby, Abby, Bob, Chris, Dan]
[Abby, Abby, Bob, Chris, Eric]
[Abby, Abby, Abby, Bob, Chris]
|
Method Summary |
boolean |
add(E e)
|
E |
insert(E e)
Tries to insert an element into the list. |
| Methods inherited from class org.limewire.collection.TreeList |
add, clear, contains, get, indexOf, iterator, listIterator, listIterator, remove, remove, set, size, toArray |
FixedSizeSortedList
public FixedSizeSortedList(int capacity)
FixedSizeSortedList
public FixedSizeSortedList(Collection<? extends E> c,
Comparator<? super E> comparator,
int capacity)
FixedSizeSortedList
public FixedSizeSortedList(Collection<? extends E> c,
int capacity)
FixedSizeSortedList
public FixedSizeSortedList(Comparator<? super E> comparator,
int capacity)
add
public boolean add(E e)
- Specified by:
add in interface Collection<E>- Specified by:
add in interface List<E>- Overrides:
add in class SortedList<E>
insert
public E insert(E e)
- Tries to insert an element into the list. This may fail if the list is
full and the new element is ordered below all existing elements, in
which case the new element is returned. If the list is full and the new
element is ordered above any existing element, the new element is
inserted and the lowest-ordered element is removed and returned. If the
list is not full, the new element is inserted and null is returned.
Got that? Gooood.
- Returns:
- null, the new element, or an existing element that was removed
Copyright © 2009 Lime Wire LLC. All Rights Reserved.