org.semanticweb.owlapi.reasoner.impl
Class SynonymSetImpl<E>

java.lang.Object
  extended by org.semanticweb.owlapi.reasoner.impl.SynonymSetImpl<E>

public class SynonymSetImpl<E>
extends java.lang.Object

Author: Matthew Horridge
The University of Manchester
Information Management Group
Date: 01-Aug-2009


Constructor Summary
SynonymSetImpl()
          Constructs a new, empty set; the backing HashMap instance has default initial capacity (16) and load factor (0.75).
SynonymSetImpl(java.util.Collection<? extends E> c)
          Constructs a new set containing the elements in the specified collection.
SynonymSetImpl(E e)
          Creates a singleton synonym set
 
Method Summary
 boolean add(E o)
          Adds the specified element to this set if it is not already present.
 boolean addAll(java.util.Collection<? extends E> c)
          Adds all of the elements in the specified collection to this collection (optional operation).
 void clear()
          Removes all of the elements from this set.
 boolean contains(java.lang.Object o)
          Returns true if this set contains the specified element.
 boolean containsAll(java.util.Collection<?> c)
          Returns true if this set contains all of the elements of the specified collection.
 E getSingletonElement()
          Gets the one and only element if this set of synonyms is a singleton set
 boolean isEmpty()
          Returns true if this set contains no elements.
 boolean isSingleton()
          Determines if this set of synonyms is a singleton set.
 java.util.Iterator<E> iterator()
          Returns an iterator over the elements in this set.
 boolean remove(java.lang.Object o)
          Removes the specified element from this set if it is present.
 boolean removeAll(java.util.Collection<?> c)
          Removes from this set all of its elements that are contained in the specified collection (optional operation).
 boolean retainAll(java.util.Collection<?> c)
          Retains only the elements in this collection that are contained in the specified collection (optional operation).
 int size()
          Returns the number of elements in this set (its cardinality).
 java.lang.Object[] toArray()
          Returns an array containing all of the elements in this set.
<T> T[]
toArray(T[] a)
          Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SynonymSetImpl

public SynonymSetImpl()
Constructs a new, empty set; the backing HashMap instance has default initial capacity (16) and load factor (0.75).


SynonymSetImpl

public SynonymSetImpl(E e)
Creates a singleton synonym set

Parameters:
e - The one and only element

SynonymSetImpl

public SynonymSetImpl(java.util.Collection<? extends E> c)
Constructs a new set containing the elements in the specified collection. The HashMap is created with default load factor (0.75) and an initial capacity sufficient to contain the elements in the specified collection.

Parameters:
c - the collection whose elements are to be placed into this set.
Throws:
java.lang.NullPointerException - if the specified collection is null.
Method Detail

isSingleton

public boolean isSingleton()
Determines if this set of synonyms is a singleton set.

Returns:
true if this synonym set is a singleton set, otherwise false

getSingletonElement

public E getSingletonElement()
Gets the one and only element if this set of synonyms is a singleton set

Returns:
the one and only element if this set is a singleton set. If this set is not a singleton set then a runtime exception will be thrown
See Also:
isSingleton()

iterator

public java.util.Iterator<E> iterator()
Returns an iterator over the elements in this set. The elements are returned in no particular order.

Returns:
an Iterator over the elements in this set.
See Also:
ConcurrentModificationException

add

public boolean add(E o)
Adds the specified element to this set if it is not already present.

Parameters:
o - element to be added to this set.
Returns:
true if the set did not already contain the specified element.

remove

public boolean remove(java.lang.Object o)
Removes the specified element from this set if it is present.

Parameters:
o - object to be removed from this set, if present.
Returns:
true if the set contained the specified element.

clear

public void clear()
Removes all of the elements from this set.


removeAll

public boolean removeAll(java.util.Collection<?> c)
Removes from this set all of its elements that are contained in the specified collection (optional operation).

This implementation determines which is the smaller of this set and the specified collection, by invoking the size method on each. If this set has fewer elements, then the implementation iterates over this set, checking each element returned by the iterator in turn to see if it is contained in the specified collection. If it is so contained, it is removed from this set with the iterator's remove method. If the specified collection has fewer elements, then the implementation iterates over the specified collection, removing from this set each element returned by the iterator, using this set's remove method.

Note that this implementation will throw an UnsupportedOperationException if the iterator returned by the iterator method does not implement the remove method.

Parameters:
c - elements to be removed from this set.
Returns:
true if this set changed as a result of the call.
Throws:
java.lang.UnsupportedOperationException - removeAll is not supported by this set.
java.lang.NullPointerException - if the specified collection is null.
See Also:
remove(Object), contains(Object)

addAll

public boolean addAll(java.util.Collection<? extends E> c)
Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.)

This implementation iterates over the specified collection, and adds each object returned by the iterator to this collection, in turn.

Note that this implementation will throw an UnsupportedOperationException unless add is overridden (assuming the specified collection is non-empty).

Parameters:
c - collection whose elements are to be added to this collection.
Returns:
true if this collection changed as a result of the call.
Throws:
java.lang.UnsupportedOperationException - if this collection does not support the addAll method.
java.lang.NullPointerException - if the specified collection is null.
See Also:
add(Object)

retainAll

public boolean retainAll(java.util.Collection<?> c)
Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.

This implementation iterates over this collection, checking each element returned by the iterator in turn to see if it's contained in the specified collection. If it's not so contained, it's removed from this collection with the iterator's remove method.

Note that this implementation will throw an UnsupportedOperationException if the iterator returned by the iterator method does not implement the remove method and this collection contains one or more elements not present in the specified collection.

Parameters:
c - elements to be retained in this collection.
Returns:
true if this collection changed as a result of the call.
Throws:
java.lang.UnsupportedOperationException - if the retainAll method is not supported by this Collection.
java.lang.NullPointerException - if the specified collection is null.
See Also:
remove(Object), contains(Object)

size

public int size()
Returns the number of elements in this set (its cardinality). If this set contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:
the number of elements in this set (its cardinality).

isEmpty

public boolean isEmpty()
Returns true if this set contains no elements.

Returns:
true if this set contains no elements.

contains

public boolean contains(java.lang.Object o)
Returns true if this set contains the specified element. More formally, returns true if and only if this set contains an element e such that (o==null ? e==null : o.equals(e)).

Parameters:
o - element whose presence in this set is to be tested.
Returns:
true if this set contains the specified element.
Throws:
java.lang.ClassCastException - if the type of the specified element is incompatible with this set (optional).
java.lang.NullPointerException - if the specified element is null and this set does not support null elements (optional).

toArray

public java.lang.Object[] toArray()
Returns an array containing all of the elements in this set. Obeys the general contract of the Collection.toArray method.

Returns:
an array containing all of the elements in this set.

toArray

public <T> T[] toArray(T[] a)
Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array. Obeys the general contract of the Collection.toArray(Object[]) method.

Parameters:
a - the array into which the elements of this set are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
Returns:
an array containing the elements of this set.
Throws:
java.lang.ArrayStoreException - the runtime type of a is not a supertype of the runtime type of every element in this set.
java.lang.NullPointerException - if the specified array is null.

containsAll

public boolean containsAll(java.util.Collection<?> c)
Returns true if this set contains all of the elements of the specified collection. If the specified collection is also a set, this method returns true if it is a subset of this set.

Parameters:
c - collection to be checked for containment in this set.
Returns:
true if this set contains all of the elements of the specified collection.
Throws:
java.lang.ClassCastException - if the types of one or more elements in the specified collection are incompatible with this set (optional).
java.lang.NullPointerException - if the specified collection contains one or more null elements and this set does not support null elements (optional).
java.lang.NullPointerException - if the specified collection is null.
See Also:
contains(Object)