LimeWire collection component api

org.limewire.collection
Class LIFOSet<E>

java.lang.Object
  extended by org.limewire.collection.LIFOSet<E>
All Implemented Interfaces:
java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>
Direct Known Subclasses:
FixedSizeLIFOSet

public class LIFOSet<E>
extends java.lang.Object
implements java.util.Set<E>

A hash-based Set ordered with the last added element is the first item in the list.

    LIFOSet<String> s = new LIFOSet<String>(1);
    s.add("Abby");
    s.add("Bob");
    s.add("Chris");
    s.add("Dan");
    s.add("Eric");  
    s.add("Fred");
    System.out.println(s);

    Output:
        [Fred, Eric, Dan, Chris, Bob, Abby]


Constructor Summary
LIFOSet()
           
LIFOSet(int initialCapacity)
           
LIFOSet(int initialCapacity, float loadFactor)
           
 
Method Summary
 boolean add(E o)
          Adds the given element to the head of the set.
 boolean addAll(java.util.Collection<? extends E> c)
           
 void clear()
           
 boolean contains(java.lang.Object o)
           
 boolean containsAll(java.util.Collection<?> c)
           
 boolean isEmpty()
           
 java.util.Iterator<E> iterator()
           
protected  boolean remove(int index)
          Removes the element at the given index from the ordered Set
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection<?> c)
           
protected  boolean removeEldest()
          Removes the first (eldest) element from the ordered set
protected  boolean removeNewest()
          Removes the last (newest) element from the ordered set
 boolean retainAll(java.util.Collection<?> c)
           
 int size()
           
 java.lang.Object[] toArray()
           
<T> T[]
toArray(T[] a)
           
 java.lang.String 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

LIFOSet

public LIFOSet()

LIFOSet

public LIFOSet(int initialCapacity)

LIFOSet

public LIFOSet(int initialCapacity,
               float loadFactor)
Method Detail

add

public boolean add(E o)
Adds the given element to the head of the set.

Specified by:
add in interface java.util.Collection<E>
Specified by:
add in interface java.util.Set<E>

addAll

public boolean addAll(java.util.Collection<? extends E> c)
Specified by:
addAll in interface java.util.Collection<E>
Specified by:
addAll in interface java.util.Set<E>

clear

public void clear()
Specified by:
clear in interface java.util.Collection<E>
Specified by:
clear in interface java.util.Set<E>

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection<E>
Specified by:
contains in interface java.util.Set<E>

containsAll

public boolean containsAll(java.util.Collection<?> c)
Specified by:
containsAll in interface java.util.Collection<E>
Specified by:
containsAll in interface java.util.Set<E>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection<E>
Specified by:
isEmpty in interface java.util.Set<E>

iterator

public java.util.Iterator<E> iterator()
Specified by:
iterator in interface java.lang.Iterable<E>
Specified by:
iterator in interface java.util.Collection<E>
Specified by:
iterator in interface java.util.Set<E>

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection<E>
Specified by:
remove in interface java.util.Set<E>

removeEldest

protected boolean removeEldest()
Removes the first (eldest) element from the ordered set

Returns:
true if the set was changed

removeNewest

protected boolean removeNewest()
Removes the last (newest) element from the ordered set

Returns:
true if the set was changed

remove

protected boolean remove(int index)
Removes the element at the given index from the ordered Set


removeAll

public boolean removeAll(java.util.Collection<?> c)
Specified by:
removeAll in interface java.util.Collection<E>
Specified by:
removeAll in interface java.util.Set<E>

retainAll

public boolean retainAll(java.util.Collection<?> c)
Specified by:
retainAll in interface java.util.Collection<E>
Specified by:
retainAll in interface java.util.Set<E>

size

public int size()
Specified by:
size in interface java.util.Collection<E>
Specified by:
size in interface java.util.Set<E>

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection<E>
Specified by:
toArray in interface java.util.Set<E>

toArray

public <T> T[] toArray(T[] a)
Specified by:
toArray in interface java.util.Collection<E>
Specified by:
toArray in interface java.util.Set<E>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

LimeWire collection component api

Copyright © 2009 Lime Wire LLC. All Rights Reserved.