org.limewire.collection
Class FixedSizeLIFOSet<E>
java.lang.Object
org.limewire.collection.LIFOSet<E>
org.limewire.collection.FixedSizeLIFOSet<E>
- All Implemented Interfaces:
- Iterable<E>, Collection<E>, Set<E>
public class FixedSizeLIFOSet<E>
- extends LIFOSet<E>
A fixed size Set where the last added element is the first
item in the list. Upon reaching the capacity of elements,
FixedSizeLIFOSet removes either the last item inserted, first
out (LIFO, default) or removes the first item inserted, first out (FIFO).
This class is a hash-based Set and therefore, objects must correctly
contain a Object.hashCode() and Object.equals(Object).
System.out.println("EjectionPolicy: LIFO");
FixedSizeLIFOSet<String> lifo = new FixedSizeLIFOSet<String>(3, FixedSizeLIFOSet.EjectionPolicy.LIFO);
lifo.add("Abby");
lifo.add("Bob");
lifo.add("Chris");
System.out.println(lifo);
System.out.println("Last in: Chris, First in Abby");
lifo.add("Dan");
System.out.println(lifo);
System.out.println("\nEjectionPolicy: FIFO");
FixedSizeLIFOSet<String> fifo = new FixedSizeLIFOSet<String>(3, FixedSizeLIFOSet.EjectionPolicy.FIFO);
fifo.add("Abby");
fifo.add("Bob");
fifo.add("Chris");
System.out.println(fifo);
System.out.println("Last in: Chris, First in Abby");
fifo.add("Dan");
System.out.println(fifo);
Output:
EjectionPolicy: LIFO
[Chris, Bob, Abby]
Last in: Chris, First in Abby
[Dan, Bob, Abby]
EjectionPolicy: FIFO
[Chris, Bob, Abby]
Last in: Chris, First in Abby
[Dan, Chris, Bob]
|
Nested Class Summary |
static class |
FixedSizeLIFOSet.EjectionPolicy
The EjectionPolicy controls which element should
be removed from the Set if has reached its maximum
capacity. |
|
Method Summary |
boolean |
add(E o)
Adds the given element to the head of the set. |
| Methods inherited from class org.limewire.collection.LIFOSet |
addAll, clear, contains, containsAll, isEmpty, iterator, remove, remove, removeAll, removeEldest, removeNewest, retainAll, size, toArray, toArray, toString |
FixedSizeLIFOSet
public FixedSizeLIFOSet(int maxSize)
FixedSizeLIFOSet
public FixedSizeLIFOSet(int maxSize,
FixedSizeLIFOSet.EjectionPolicy policy)
FixedSizeLIFOSet
public FixedSizeLIFOSet(int maxSize,
int initialCapacity,
float loadFactor)
FixedSizeLIFOSet
public FixedSizeLIFOSet(int maxSize,
int initialCapacity,
float loadFactor,
FixedSizeLIFOSet.EjectionPolicy policy)
add
public boolean add(E o)
- Description copied from class:
LIFOSet
- Adds the given element to the head of the set.
- Specified by:
add in interface Collection<E>- Specified by:
add in interface Set<E>- Overrides:
add in class LIFOSet<E>
- Returns:
- true
Copyright © 2009 Lime Wire LLC. All Rights Reserved.