org.geotoolkit.image.io
Class DimensionSet

Object
  extended by AbstractCollection<E>
      extended by AbstractSet<DimensionIdentification>
          extended by DimensionSet
All Implemented Interfaces:
Iterable<DimensionIdentification>, Collection<DimensionIdentification>, Set<DimensionIdentification>, WarningProducer, Localized

public class DimensionSet
extends AbstractSet<DimensionIdentification>
implements WarningProducer

The set of DimensionIdentification instances managed by a given MultidimensionalImageStore instance. This class is provided for MultidimensionalImageStore implementations and usually don't need to be accessed directly by users. The code snippet below gives an example of implementation using a DimensionSet:

public class MyReader extends SpatialImageReader implements MultidimensionalImageStore {
    private final DimensionSet dimensionsForAPI;

    public SpatialImageReader(Spi provider) {
        super(provider);
        dimensionsForAPI = new DimensionSet(this);
    }

    public DimensionIdentification getDimensionForAPI(DimensionSlice.API api) {
        return dimensionsForAPI.getOrCreate(api);
    }

    public DimensionSlice.API getAPIForDimension(Object... identifiers) {
        return dimensionsForAPI.getAPI(identifiers);
    }

    public Set<DimensionSlice.API> getAPIForDimensions() {
        return dimensionsForAPI.getAPIs();
    }

    public BufferedImage read(int imageIndex, ImageReadParam param) {
        DimensionIdentification bandsDimension = dimensionsForAPI.get(DimensionSlice.API.BANDS);
        if (bandsDimension != null) {
            Collection<?> propertiesOfAxes = ...; // This is plugin-specific.
            int index = bandsDimension.findDimensionIndex(propertiesOfAxes);
            if (index >= 0) {
                // We have found the dimension index of bands.
            }
        }
        // Continue the process of reading the image...
    }
}
DimensionSet is not modifiable through the Set interface, since it doesn't support the add method. However new elements can be created by calls to the getOrCreate(DimensionSlice.API) method.

Since:
3.15 (derived from 3.08)
Version:
3.15
Author:
Martin Desruisseaux (Geomatys)
See Also:
MultidimensionalImageStore, DimensionIdentification
Module:
coverage/geotk-coverageio (download)    View source code for this class

Field Summary
 
Fields inherited from interface WarningProducer
LOGGER
 
Constructor Summary
DimensionSet(MultidimensionalImageStore store)
          Creates a new DimensionSet instance for the given image reader or writer.
 
Method Summary
 void clear()
          Clears any setting in this object.
 boolean contains(Object value)
          Returns true if this set contains the given dimension.
 DimensionIdentification get(DimensionSlice.API api)
          Returns the dimension which has been assigned to the given API, or null if none.
 DimensionSlice.API getAPI(Object... identifiers)
          Returns the API assigned to the given dimension identifiers.
 Set<DimensionSlice.API> getAPIs()
          Returns the set of APIs for which at least one dimension has identifiers.
 Locale getLocale()
          Returns the locale used for formatting error messages, or null if none.
 DimensionIdentification getOrCreate(DimensionSlice.API api)
          Returns the dimension assigned to the given API.
 boolean isEmpty()
          Returns true if this set doesn't contains any dimension.
 Iterator<DimensionIdentification> iterator()
          Returns an iterator over all dimensions contained in this set.
 int size()
          Returns the number of dimensions contained in this set.
 boolean warningOccurred(LogRecord record)
          Invoked when a warning occurred.
 
Methods inherited from class AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class AbstractCollection
add, addAll, containsAll, remove, retainAll, toArray, toArray, toString
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface Set
add, addAll, containsAll, remove, retainAll, toArray, toArray
 

Constructor Detail

DimensionSet

public DimensionSet(MultidimensionalImageStore store)
Creates a new DimensionSet instance for the given image reader or writer.

Parameters:
store - The image reader or writer for which this instance is created, or null.
Method Detail

clear

public void clear()
Clears any setting in this object. After this method call, the state of this object is than same than after construction.

Specified by:
clear in interface Collection<DimensionIdentification>
Specified by:
clear in interface Set<DimensionIdentification>
Overrides:
clear in class AbstractCollection<DimensionIdentification>

isEmpty

public boolean isEmpty()
Returns true if this set doesn't contains any dimension.

Specified by:
isEmpty in interface Collection<DimensionIdentification>
Specified by:
isEmpty in interface Set<DimensionIdentification>
Overrides:
isEmpty in class AbstractCollection<DimensionIdentification>

size

public int size()
Returns the number of dimensions contained in this set.

Specified by:
size in interface Collection<DimensionIdentification>
Specified by:
size in interface Set<DimensionIdentification>
Specified by:
size in class AbstractCollection<DimensionIdentification>

iterator

public Iterator<DimensionIdentification> iterator()
Returns an iterator over all dimensions contained in this set.

Specified by:
iterator in interface Iterable<DimensionIdentification>
Specified by:
iterator in interface Collection<DimensionIdentification>
Specified by:
iterator in interface Set<DimensionIdentification>
Specified by:
iterator in class AbstractCollection<DimensionIdentification>

contains

public boolean contains(Object value)
Returns true if this set contains the given dimension.

Specified by:
contains in interface Collection<DimensionIdentification>
Specified by:
contains in interface Set<DimensionIdentification>
Overrides:
contains in class AbstractCollection<DimensionIdentification>
Parameters:
value - The dimension to test for inclusion.
Returns:
true if this set contains the given dimension.

get

public DimensionIdentification get(DimensionSlice.API api)
Returns the dimension which has been assigned to the given API, or null if none.

This method is typically invoked by SpatialImageReader implementations together with DimensionIdentification.findDimensionIndex(Iterable) in order to locate the index of the dimension to read as bands. See Assigning a third dimension to bands in the MultidimensionalImageStore class javadoc.

Parameters:
api - The API for which to test if a dimension slice has been assigned.
Returns:
The dimension slice assigned to the given API, or null if none.

getOrCreate

public DimensionIdentification getOrCreate(DimensionSlice.API api)
Returns the dimension assigned to the given API. If a dimension has been previously created for the given API, it is returned. Otherwise a new dimension is created and returned.

In order to check if a dimension exists without creating a new one, use the get(DimensionSlice.API) method instead.

Parameters:
api - The API for which to return a dimension.
Returns:
The dimension assigned to the given API.

getAPI

public DimensionSlice.API getAPI(Object... identifiers)
Returns the API assigned to the given dimension identifiers. If more than one dimension is found for the given identifiers, then a warning is emitted and this method returns the first dimension matching the given identifiers. If no dimension is found, null is returned.

Parameters:
identifiers - The identifiers of the dimension to query.
Returns:
The API assigned to the given dimension, or DimensionSlice.API.NONE if none.

getAPIs

public Set<DimensionSlice.API> getAPIs()
Returns the set of APIs for which at least one dimension has identifiers. This is typically an empty set until the following code is invoked at least once:
getOrCreate(...).addDimensionId(...);

Returns:
The API for which at least one dimension has identifiers.

getLocale

public Locale getLocale()
Returns the locale used for formatting error messages, or null if none. The default implementation delegates to the store given at construction time, if it implements the Localized interface.

Specified by:
getLocale in interface Localized
Returns:
The locale, or null if not explicitly defined.

warningOccurred

public boolean warningOccurred(LogRecord record)
Invoked when a warning occurred. The default implementation forwards the warning to the store given at construction time if possible, or logs the warning otherwise.

Specified by:
warningOccurred in interface WarningProducer
Parameters:
record - The warning that occurred.
Returns:
true if the message has been sent to at least one warning listener, or false if it has been sent to the logging system as a fallback.


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.