org.semanticweb.elk.util.collections.entryset
Class KeyEntryHashSet<T>

java.lang.Object
  extended by java.util.AbstractCollection<T>
      extended by org.semanticweb.elk.util.collections.entryset.KeyEntryHashSet<T>
Type Parameters:
T - the type of elements in the set
All Implemented Interfaces:
Iterable<T>, Collection<T>

public class KeyEntryHashSet<T>
extends AbstractCollection<T>

A collection containing elements modulo equality. The comparison of elements is performed by wrapping them into KeyEntry objects where the key is a specified input element. For this purpose, these objects should redefine the Object.equals(Object) and Object.hashCode() methods accordingly. A factory for producing KeyEntry objects from the elements should be provided during construction of this collection. The main method provided is merging a entry into collection, which returns an equal element from the collection, if there is one (according to the specified way to compare elements), or, otherwise, inserts the input element into the collection returning itself. Other methods include finding an element in the collection that is equal to the given one, deleting such an element from the collection, if found, and iterating over the entries.

Author:
"Yevgeny Kazakov"

Field Summary
protected  EntryHashSet<KeyEntry<T,? extends T>> entryHashSet
          The underlying entry collection used to back this collection
protected  KeyEntryFactory<T> keyEntryFactory
          The factory used for wrapping keys into entries
 
Constructor Summary
KeyEntryHashSet(KeyEntryFactory<T> keyEntryFactory)
          Create an empty set associated with a given factory for creating KeyEntry wrapper objects.
KeyEntryHashSet(KeyEntryFactory<T> keyEntryFactory, int initialCapacity)
          Create an empty set associated with a given factory for creating KeyEntry wrapper objects and with the given initial capacity.
 
Method Summary
 boolean add(T key)
           
 void clear()
           
 T get(T key)
          Retrieves the element in the set that is equal to the given object, if it exists, or returns null otherwise.
 Iterator<T> iterator()
           
 T merge(T key)
          Get the element in set that is equal to the input entry if there is one, or otherwise insert the given entry into the set and return itself.
 boolean remove(Object o)
           
 T removeEntry(T key)
          Removes and returns the element in the set that is equal to the input element.
 int size()
           
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, removeAll, retainAll, 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.Collection
equals, hashCode
 

Field Detail

keyEntryFactory

protected final KeyEntryFactory<T> keyEntryFactory
The factory used for wrapping keys into entries


entryHashSet

protected final EntryHashSet<KeyEntry<T,? extends T>> entryHashSet
The underlying entry collection used to back this collection

Constructor Detail

KeyEntryHashSet

public KeyEntryHashSet(KeyEntryFactory<T> keyEntryFactory,
                       int initialCapacity)
Create an empty set associated with a given factory for creating KeyEntry wrapper objects and with the given initial capacity. The set will be resized as necessary to accommodate new elements.

Parameters:
keyEntryFactory - factory for creating KeyEntry wrapper objects
initialCapacity - the estimated

KeyEntryHashSet

public KeyEntryHashSet(KeyEntryFactory<T> keyEntryFactory)
Create an empty set associated with a given factory for creating KeyEntry wrapper objects.

Parameters:
keyEntryFactory -
Method Detail

merge

public T merge(T key)
Get the element in set that is equal to the input entry if there is one, or otherwise insert the given entry into the set and return itself. Equality of entries is decided by wrapping them into the respective KeyEntry objects using the factory.

Parameters:
key - the element to be merged into the set
Returns:
the element in the set that is equal to the input element if there is one, or the input element otherwise

add

public boolean add(T key)
Specified by:
add in interface Collection<T>
Overrides:
add in class AbstractCollection<T>

get

public T get(T key)
Retrieves the element in the set that is equal to the given object, if it exists, or returns null otherwise. Equality of entries is decided by wrapping them into the respective KeyEntry objects using the factory.

Parameters:
key - the object that is used for finding the entry
Returns:
the entry in the set that is equal to the given object, if there exists one, or null otherwise

removeEntry

public T removeEntry(T key)
Removes and returns the element in the set that is equal to the input element. Returns null if the set contains no such element. Equality of entries is decided by wrapping them into the respective KeyEntry objects using the factory.

Parameters:
key - the element that is used for finding the element to remove
Returns:
the removed element, or null if no element that is equal to the given one is found

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<T>
Overrides:
remove in class AbstractCollection<T>

clear

public void clear()
Specified by:
clear in interface Collection<T>
Overrides:
clear in class AbstractCollection<T>

size

public int size()
Specified by:
size in interface Collection<T>
Specified by:
size in class AbstractCollection<T>

iterator

public Iterator<T> iterator()
Specified by:
iterator in interface Iterable<T>
Specified by:
iterator in interface Collection<T>
Specified by:
iterator in class AbstractCollection<T>


Copyright © 2011-2013 Department of Computer Science, University of Oxford. All Rights Reserved.