org.geotools.util
Class Singleton

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractSet
          extended byorg.geotools.util.Singleton
All Implemented Interfaces:
java.util.Collection, java.util.Set

public class Singleton
extends java.util.AbstractSet

A mutable set containing only one element. This set can't contains null element.

Since:
2.1
Version:
$Id: Singleton.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux

Constructor Summary
Singleton()
          Creates a initially empty singleton.
 
Method Summary
 boolean add(java.lang.Object object)
          Adds the specified element to this set if it is not already present.
 void clear()
          Removes the element from this singleton.
 boolean contains(java.lang.Object object)
          Returns if this singleton contains the specified element.
 java.lang.Object get()
          Returns the element in this singleton.
 boolean isEmpty()
          Returns if this singleton contains no elements.
 java.util.Iterator iterator()
          Returns an iterator over the element of this singleton.
 boolean remove(java.lang.Object object)
          Removes the specified element from this singleton, if it is present.
 int size()
          Returns 1 if this singleton contains an element, or 0 otherwise.
 
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
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, containsAll, retainAll, toArray, toArray
 

Constructor Detail

Singleton

public Singleton()
Creates a initially empty singleton.

Method Detail

size

public int size()
Returns 1 if this singleton contains an element, or 0 otherwise.


isEmpty

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


get

public java.lang.Object get()
                     throws java.util.NoSuchElementException
Returns the element in this singleton.

Returns:
The singleton element (never null).
Throws:
java.util.NoSuchElementException - if this singleton is empty.

contains

public boolean contains(java.lang.Object object)
Returns if this singleton contains the specified element.


add

public boolean add(java.lang.Object object)
Adds the specified element to this set if it is not already present. If this set already contains an other element, an exception is thrown.

Throws:
java.lang.NullPointerException - if the argument is null.
java.lang.IllegalArgumentException - if this set already contains an other element.

remove

public boolean remove(java.lang.Object object)
Removes the specified element from this singleton, if it is present.


clear

public void clear()
Removes the element from this singleton.


iterator

public java.util.Iterator iterator()
Returns an iterator over the element of this singleton.



Copyright © GeoTools. All Rights Reserved.