org.geotools.util
Class DerivedSet

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

public abstract class DerivedSet
extends java.util.AbstractSet
implements java.io.Serializable

A set whose values are derived from an other set. The values are derived only when requested, which make it possible to backup potentially large sets. Implementations need only to overrides baseToDerived(java.lang.Object) and derivedToBase(java.lang.Object) methods. This set do not supports value, since is used when no mapping from base to exists. This class is serializable if the underlying base set is serializable too.

Since:
2.0
Version:
$Id: DerivedSet.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux
See Also:
Serialized Form

Field Summary
protected  java.util.Set base
          The base set whose values are derived from.
 
Constructor Summary
DerivedSet(java.util.Set base)
          Creates a new derived set from the specified base set.
 
Method Summary
 boolean add(java.lang.Object element)
          Ensures that this set contains the specified element.
protected abstract  java.lang.Object baseToDerived(java.lang.Object element)
          Transforms a value in the base set to a value in this set.
 boolean contains(java.lang.Object element)
          Returns if this set contains the specified element.
protected abstract  java.lang.Object derivedToBase(java.lang.Object element)
          Transforms a value in this set to a value in the base set.
 boolean isEmpty()
          Returns if this set contains no elements.
 java.util.Iterator iterator()
          Returns an iterator over the elements contained in this set.
 boolean remove(java.lang.Object element)
          Removes a single instance of the specified element from this set.
 int size()
          Returns the number of elements in this set.
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, clear, 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, clear, containsAll, retainAll, toArray, toArray
 

Field Detail

base

protected final java.util.Set base
The base set whose values are derived from.

See Also:
baseToDerived(java.lang.Object), derivedToBase(java.lang.Object)
Constructor Detail

DerivedSet

public DerivedSet(java.util.Set base)
Creates a new derived set from the specified base set.

Parameters:
base - The base set.
Method Detail

baseToDerived

protected abstract java.lang.Object baseToDerived(java.lang.Object element)
Transforms a value in the base set to a value in this set. If there is no mapping in the derived set for the specified element, then this method returns .

Parameters:
element - A value in the base set.
Returns:
The value that this view should contains instead of , or .

derivedToBase

protected abstract java.lang.Object derivedToBase(java.lang.Object element)
Transforms a value in this set to a value in the base set.

Parameters:
element - A value in this set.
Returns:
The value stored in the base set.

iterator

public java.util.Iterator iterator()
Returns an iterator over the elements contained in this set. The iterator will invokes baseToDerived(java.lang.Object) for each element.

Specified by:
iterator in interface java.util.Set
Returns:
an iterator over the elements contained in this set.

size

public int size()
Returns the number of elements in this set. The default implementation counts the number of elements returned by the iterator.

Specified by:
size in interface java.util.Set
Returns:
the number of elements in this set.

isEmpty

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

Specified by:
isEmpty in interface java.util.Set
Returns:
if this set contains no elements.

contains

public boolean contains(java.lang.Object element)
Returns if this set contains the specified element. The default implementation invokes base.contains(derivedToBase(element)).

Specified by:
contains in interface java.util.Set
Parameters:
element - object to be checked for containment in this set.
Returns:
if this set contains the specified element.

add

public boolean add(java.lang.Object element)
            throws java.lang.UnsupportedOperationException
Ensures that this set contains the specified element. The default implementation invokes base.add(derivedToBase(element)).

Specified by:
add in interface java.util.Set
Parameters:
element - element whose presence in this set is to be ensured.
Returns:
if the set changed as a result of the call.
Throws:
java.lang.UnsupportedOperationException - if the base set doesn't supports the operation.

remove

public boolean remove(java.lang.Object element)
               throws java.lang.UnsupportedOperationException
Removes a single instance of the specified element from this set. The default implementation invokes base.remove(derivedToBase(element)).

Specified by:
remove in interface java.util.Set
Parameters:
element - element to be removed from this set, if present.
Returns:
if the set contained the specified element.
Throws:
java.lang.UnsupportedOperationException - if the base set doesn't supports the operation.


Copyright © GeoTools. All Rights Reserved.