org.jutil.java.collections
Class Singleton

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractSet
              |
              +--org.jutil.java.collections.Singleton
All Implemented Interfaces:
java.util.Collection, java.util.Set

public final class Singleton
extends java.util.AbstractSet

Version:
$Revision: 1.5 $
Author:
Jan Dockx

Inner Class Summary
 class Singleton.SingletonIterator
           
 
Field Summary
static java.lang.String CVS_REVISION
           
 
Constructor Summary
Singleton(java.lang.Object onlyElement)
          public behavior

post getOnlyElement() == onlyElement;
Initialize a new Singleton containing the given element.
 
Method Summary
 boolean add(java.lang.Object o)
          also public behavior

post false;
exception UnsupportedOperationException true;
See superclass
 boolean addAll(java.util.Collection c)
          also public behavior

post false;
exception UnsupportedOperationException true;
See superclass
 void clear()
          also public behavior

post false;
exception UnsupportedOperationException true;
See superclass
 boolean contains(java.lang.Object o)
          also public behavior

post \result ==
((getOnlyElement() == null) && (o == null)) ||
getOnlyElement().equals(o);
See superclass
 java.lang.Object getOnlyElement()
          Return the only element in this Singleton.
 boolean isEmpty()
          also public behavior

post \result == false;
See superclass
 java.util.Iterator iterator()
          also public behavior

post \result instanceof SingletonIterator;
post \result != null;
See superclass
 boolean remove(java.lang.Object o)
          also public behavior

post false;
exception UnsupportedOperationException true;
See superclass
 boolean removeAll(java.util.Collection c)
          also public behavior

post false;
exception UnsupportedOperationException true;
See superclass
 boolean retainAll(java.util.Collection c)
          also public behavior

post false;
exception UnsupportedOperationException true;
See superclass
 int size()
          also public behavior

post \result == 1;
See superclass
 java.lang.Object[] toArray()
          also public behavior

post \result.length = 1;
post \result[0] == getOnlyElement();
See superclass
 java.lang.Object[] toArray(java.lang.Object[] a)
          also public behavior

post \result.getClass().getComponentType() == a.getClass().getComponentType();
post \result[0] == getOnlyElement();
post (a.length >= 1) ==> (\result == a);
post (a.length < 1) ==> (\result.length == 1);
exception NullPointerException
a == null;
exception ArrayStoreException
(getOnlyElement() != null) &&
(! a.getClass().isInstance(getOnlyElement()));
See superclass
 
Methods inherited from class java.util.AbstractSet
equals, hashCode
 
Methods inherited from class java.util.AbstractCollection
containsAll, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
containsAll
 

Field Detail

CVS_REVISION

public static final java.lang.String CVS_REVISION
Constructor Detail

Singleton

public Singleton(java.lang.Object onlyElement)
public behavior

post getOnlyElement() == onlyElement;
Initialize a new Singleton containing the given element.
Parameters:
onlyElement - The only element of this Singleton.
Method Detail

getOnlyElement

public java.lang.Object getOnlyElement()
Return the only element in this Singleton.

size

public int size()
also public behavior

post \result == 1;
See superclass
Overrides:
size in class java.util.AbstractCollection

isEmpty

public boolean isEmpty()
also public behavior

post \result == false;
See superclass
Overrides:
isEmpty in class java.util.AbstractCollection

contains

public boolean contains(java.lang.Object o)
also public behavior

post \result ==
((getOnlyElement() == null) && (o == null)) ||
getOnlyElement().equals(o);
See superclass
Overrides:
contains in class java.util.AbstractCollection

iterator

public java.util.Iterator iterator()
also public behavior

post \result instanceof SingletonIterator;
post \result != null;
See superclass
Overrides:
iterator in class java.util.AbstractCollection

toArray

public java.lang.Object[] toArray()
also public behavior

post \result.length = 1;
post \result[0] == getOnlyElement();
See superclass
Overrides:
toArray in class java.util.AbstractCollection

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
also public behavior

post \result.getClass().getComponentType() == a.getClass().getComponentType();
post \result[0] == getOnlyElement();
post (a.length >= 1) ==> (\result == a);
post (a.length < 1) ==> (\result.length == 1);
exception NullPointerException
a == null;
exception ArrayStoreException
(getOnlyElement() != null) &&
(! a.getClass().isInstance(getOnlyElement()));
See superclass
Overrides:
toArray in class java.util.AbstractCollection

add

public boolean add(java.lang.Object o)
            throws java.lang.UnsupportedOperationException
also public behavior

post false;
exception UnsupportedOperationException true;
See superclass
Overrides:
add in class java.util.AbstractCollection

remove

public boolean remove(java.lang.Object o)
               throws java.lang.UnsupportedOperationException
also public behavior

post false;
exception UnsupportedOperationException true;
See superclass
Overrides:
remove in class java.util.AbstractCollection

addAll

public boolean addAll(java.util.Collection c)
               throws java.lang.UnsupportedOperationException
also public behavior

post false;
exception UnsupportedOperationException true;
See superclass
Overrides:
addAll in class java.util.AbstractCollection

retainAll

public boolean retainAll(java.util.Collection c)
                  throws java.lang.UnsupportedOperationException
also public behavior

post false;
exception UnsupportedOperationException true;
See superclass
Overrides:
retainAll in class java.util.AbstractCollection

removeAll

public boolean removeAll(java.util.Collection c)
                  throws java.lang.UnsupportedOperationException
also public behavior

post false;
exception UnsupportedOperationException true;
See superclass
Overrides:
removeAll in class java.util.AbstractSet

clear

public void clear()
           throws java.lang.UnsupportedOperationException
also public behavior

post false;
exception UnsupportedOperationException true;
See superclass
Overrides:
clear in class java.util.AbstractCollection