LimeWire Collection Component API

org.limewire.collection
Class FixedSizeLIFOSet<E>

java.lang.Object
  extended by org.limewire.collection.LIFOSet<E>
      extended by 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.
 
Constructor Summary
FixedSizeLIFOSet(int maxSize)
           
FixedSizeLIFOSet(int maxSize, FixedSizeLIFOSet.EjectionPolicy policy)
           
FixedSizeLIFOSet(int maxSize, int initialCapacity, float loadFactor)
           
FixedSizeLIFOSet(int maxSize, int initialCapacity, float loadFactor, FixedSizeLIFOSet.EjectionPolicy policy)
           
 
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
equals, hashCode
 

Constructor Detail

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)
Method Detail

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

LimeWire Collection Component API

Copyright © 2009 Lime Wire LLC. All Rights Reserved.