LimeWire Collection Component API

org.limewire.collection
Class FixedSizeArrayHashSet<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by java.util.HashSet<E>
              extended by org.limewire.collection.FixedSizeArrayHashSet<E>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, RandomAccess, Set<E>, RandomAccessCollection<E>
Direct Known Subclasses:
RandomOrderHashSet

public class FixedSizeArrayHashSet<E>
extends HashSet<E>
implements RandomAccessCollection<E>

Provides a fixed size HashSet with index access. The replacement policy is FIFO (First in, First out) and the iteration order is from newest to oldest.

Adding an existing element resets the FIFO order; the newly added element is now the "last in" element.

FixedSizeArrayHashSet does not support the null element.

 
    FixedSizeArrayHashSet<String> fsah = new FixedSizeArrayHashSet<String>(4);

    fsah.add("Abby");
    fsah.add("Bob");
    fsah.add("Chris");
    fsah.add("Dan");
    fsah.add("Eric");
    fsah.add("Fred");
    System.out.println(fsah);

    if(!fsah.add("Chris"))
        System.out.println("Tried to add Chris again, but it already exists in the collection (though Chris was put to the first item).");
    System.out.println(fsah);

    System.out.println("Index access: " + fsah.get(0));

    fsah.remove("Chris");
    System.out.println(fsah);
    Output:
        [Fred, Eric, Dan, Chris]
        Tried to add Chris again, but it already exists in the collection (though Chris was put to the first item).
        [Chris, Fred, Eric, Dan]
        Index access: Chris
        [Fred, Eric, Dan]

   

See Also:
Serialized Form

Constructor Summary
FixedSizeArrayHashSet(Collection<? extends E> c)
          Creates a FixedSizeArrayHashSet with maximum capacity the size of the provided collection and adds all the elements of that collection.
FixedSizeArrayHashSet(int maxCapacity)
          creates a FixedSizeArrayHashSet with the specified maximum capacity.
FixedSizeArrayHashSet(int maxCapacity, Collection<? extends E> c)
          Creates a FixedSizeArrayHashSet with the provided maximum capacity and adds elements from the provided collection.
FixedSizeArrayHashSet(int maxCapacity, int initialCapacity)
           
FixedSizeArrayHashSet(int maxCapacity, int initialCapacity, float loadFactor)
           
 
Method Summary
 boolean add(E o)
           
 void clear()
           
 Object clone()
           
 boolean contains(Object o)
           
 E get(int i)
          Retrieves the element at index i.
 boolean isEmpty()
           
 Iterator<E> iterator()
           
 boolean remove(Object o)
           
 int size()
           
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
addAll, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
 
Methods inherited from interface java.util.Set
addAll, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
 

Constructor Detail

FixedSizeArrayHashSet

public FixedSizeArrayHashSet(int maxCapacity)
creates a FixedSizeArrayHashSet with the specified maximum capacity.


FixedSizeArrayHashSet

public FixedSizeArrayHashSet(Collection<? extends E> c)
Creates a FixedSizeArrayHashSet with maximum capacity the size of the provided collection and adds all the elements of that collection.


FixedSizeArrayHashSet

public FixedSizeArrayHashSet(int maxCapacity,
                             Collection<? extends E> c)
Creates a FixedSizeArrayHashSet with the provided maximum capacity and adds elements from the provided collection. If the capacity is less than the size of the collection, elements will get ejected with FIFO policy.


FixedSizeArrayHashSet

public FixedSizeArrayHashSet(int maxCapacity,
                             int initialCapacity,
                             float loadFactor)

FixedSizeArrayHashSet

public FixedSizeArrayHashSet(int maxCapacity,
                             int initialCapacity)
Method Detail

iterator

public Iterator<E> iterator()
Specified by:
iterator in interface Iterable<E>
Specified by:
iterator in interface Collection<E>
Specified by:
iterator in interface Set<E>
Overrides:
iterator in class HashSet<E>

size

public int size()
Specified by:
size in interface Collection<E>
Specified by:
size in interface Set<E>
Overrides:
size in class HashSet<E>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<E>
Specified by:
isEmpty in interface Set<E>
Overrides:
isEmpty in class HashSet<E>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<E>
Specified by:
contains in interface Set<E>
Overrides:
contains in class HashSet<E>

add

public boolean add(E o)
Specified by:
add in interface Collection<E>
Specified by:
add in interface Set<E>
Overrides:
add in class HashSet<E>

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<E>
Specified by:
remove in interface Set<E>
Overrides:
remove in class HashSet<E>

clear

public void clear()
Specified by:
clear in interface Collection<E>
Specified by:
clear in interface Set<E>
Overrides:
clear in class HashSet<E>

clone

public Object clone()
Overrides:
clone in class HashSet<E>

get

public E get(int i)
Description copied from interface: RandomAccessCollection
Retrieves the element at index i.

Specified by:
get in interface RandomAccessCollection<E>

LimeWire Collection Component API

Copyright © 2008 Lime Wire LLC. All Rights Reserved.