LimeWire collection component api

org.limewire.collection
Class FixedSizeSortedList<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by org.limewire.collection.TreeList<E>
              extended by org.limewire.collection.SortedList<E>
                  extended by org.limewire.collection.FixedSizeSortedList<E>
All Implemented Interfaces:
java.lang.Iterable<E>, java.util.Collection<E>, java.util.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]


Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
FixedSizeSortedList(java.util.Collection<? extends E> c, java.util.Comparator<? super E> comparator, int capacity)
           
FixedSizeSortedList(java.util.Collection<? extends E> c, int capacity)
           
FixedSizeSortedList(java.util.Comparator<? super E> comparator, int capacity)
           
FixedSizeSortedList(int capacity)
           
 
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.SortedList
comparator, first, last
 
Methods inherited from class org.limewire.collection.TreeList
add, clear, contains, get, indexOf, iterator, listIterator, listIterator, remove, remove, set, size, toArray
 
Methods inherited from class java.util.AbstractList
addAll, equals, hashCode, lastIndexOf, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, removeAll, retainAll, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, containsAll, isEmpty, removeAll, retainAll, toArray
 

Constructor Detail

FixedSizeSortedList

public FixedSizeSortedList(int capacity)

FixedSizeSortedList

public FixedSizeSortedList(java.util.Collection<? extends E> c,
                           java.util.Comparator<? super E> comparator,
                           int capacity)

FixedSizeSortedList

public FixedSizeSortedList(java.util.Collection<? extends E> c,
                           int capacity)

FixedSizeSortedList

public FixedSizeSortedList(java.util.Comparator<? super E> comparator,
                           int capacity)
Method Detail

add

public boolean add(E e)
Specified by:
add in interface java.util.Collection<E>
Specified by:
add in interface java.util.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.

Returns:
null, the new element, or an existing element that was removed

LimeWire collection component api

Copyright © 2009 Lime Wire LLC. All Rights Reserved.