# Class MemoryGridCoverageResource

Object
AbstractResource
AbstractGridCoverageResource
MemoryGridCoverageResource

All Implemented Interfaces:
  `DataSet, GridCoverageResource, Resource`

public class MemoryGridCoverageResource extends AbstractGridCoverageResource
A Grid Coverage Resource stored in memory. This resource wraps an arbitrary `GridCoverage` specified at construction time. Metadata can be specified by overriding the `AbstractGridCoverageResource​.createMetadata()` method.

## When to use

This class is useful for small grid coverages, or for testing purposes, or when the coverage is in memory anyway (for example, a computation result). It should generally not be used for large coverages read from files or databases.

Since:
  1.6

- ## Nested Class Summary

  ### Nested classes/interfaces inherited from interface Resource

  `Resource​.FileSet`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final GridCoverage`
  `coverage`
  The grid coverage specified at construction time.
  `protected final GridCoverageProcessor`
  `processor`
  The grid coverage processor to use for selecting bands.

  ### Fields inherited from class AbstractResource

  `listeners`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MemoryGridCoverageResource(Resource parent, GenericName identifier, GridCoverage coverage, GridCoverageProcessor processor)`
  Creates a new coverage stored in memory.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `equals(Object obj)`
  Tests whether this memory grid coverage resource is wrapping the same coverage as the given object.
  `GridCoverage`
  `getGridCoverage()`
  Returns the grid coverage wrapped by this resource.
  `GridGeometry`
  `getGridGeometry()`
  Returns information about the domain of wrapped grid coverage.
  `Optional<GenericName>`
  `getIdentifier()`
  Returns the resource identifier specified at construction time, if any.
  `RasterLoadingStrategy`
  `getLoadingStrategy()`
  Returns an indication about whether `read(…)` tries to force the loading of data.
  `List<SampleDimension>`
  `getSampleDimensions()`
  Returns information about the ranges of wrapped grid coverage.
  `int`
  `hashCode()`
  Returns a hash code value for consistency with `equals(Object)`.
  `GridCoverage`
  `read(GridGeometry domain, int... ranges)`
  Returns a subset of the wrapped grid coverage.
  `boolean`
  `setLoadingStrategy(RasterLoadingStrategy strategy)`
  Sets the preference about whether `read(…)` should try to force the loading of data.
  `String`
  `toString()`
  Returns a string representation of this resource.

  ### Methods inherited from class AbstractGridCoverageResource

  `canNotRead, createMetadata, getEnvelope, logReadOperation`

  ### Methods inherited from class AbstractResource

  `addListener, clearCache, getMetadata, getSynchronizationLock, removeListener`

  ### Methods inherited from class Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface GridCoverageResource

  `getResolutions, subset`

  ### Methods inherited from interface Resource

  `addListener, getFileSet, getMetadata, removeListener`

- ## Field Details

  - ### coverage

    protected final GridCoverage coverage
    The grid coverage specified at construction time.
    See Also:
      - `getGridCoverage()`

  - ### processor

    protected final GridCoverageProcessor processor
    The grid coverage processor to use for selecting bands. It may be configured with a colorizer for determining the color models.

- ## Constructor Details

  - ### MemoryGridCoverageResource

    public MemoryGridCoverageResource(Resource parent, GenericName identifier, GridCoverage coverage, GridCoverageProcessor processor)
    Creates a new coverage stored in memory.
    Parameters:
      `parent` - the parent resource, or `null` if none.
      `identifier` - resource identifier, or `null` if none.
      `coverage` - stored coverage retained as-is (not copied). Cannot be null.
      `processor` - the grid coverage processor for selecting bands, or `null` for default.

- ## Method Details

  - ### getIdentifier

    public Optional<GenericName> getIdentifier()
    Returns the resource identifier specified at construction time, if any.
    Returns:
      a persistent identifier unique within the data store, or absent if this resource has no such identifier.
    See Also:
      - `DataStore​.getIdentifier()`
      - `DataStore​.findResource(String)`

  - ### getGridCoverage

    public GridCoverage getGridCoverage()
    Returns the grid coverage wrapped by this resource. The grid coverage returned by this method shall be the same or equivalent to the coverage that would be returned by a call to `read(null)`, and should not be expansive to get.
    Returns:
      the grid coverage wrapped by this resource.
    See Also:
      - `read(GridGeometry, int...)`

  - ### getGridGeometry

    public GridGeometry getGridGeometry()
    Returns information about the domain of wrapped grid coverage.
    Returns:
      extent of grid coordinates together with their mapping to "real world" coordinates.
    See Also:
      - `GridCoverage​.getGridGeometry()`

  - ### getSampleDimensions

    public List<SampleDimension> getSampleDimensions()
    Returns information about the ranges of wrapped grid coverage.
    Returns:
      ranges of sample values together with their mapping to "real values".
    See Also:
      - `GridCoverage​.getSampleDimensions()`

  - ### getLoadingStrategy

    public RasterLoadingStrategy getLoadingStrategy()
    Returns an indication about whether `read(…)` tries to force the loading of data.
    Returns:
      current raster data loading strategy for this resource.

  - ### setLoadingStrategy

    public boolean setLoadingStrategy(RasterLoadingStrategy strategy)
    Sets the preference about whether `read(…)` should try to force the loading of data.
    Parameters:
      `strategy` - the desired strategy for loading raster data.
    Returns:
      `true` if the given strategy has been accepted, or `false` if this implementation replaced the given strategy by an alternative.

  - ### read

    public GridCoverage read(GridGeometry domain, int... ranges)
    Returns a subset of the wrapped grid coverage. If a null grid geometry and a null or empty range is specified, then this method shall return the same grid coverage as `getGridCoverage()` or an equivalent coverage. If a non-null grid geometry is specified, then this method tries to return a grid coverage matching the given grid geometry on a best-effort basis. It may be the whole coverage.
    Parameters:
      `domain` - desired grid extent and resolution, or `null` for the whole domain.
      `ranges` - 0-based indices of sample dimensions to read, or `null` or an empty sequence for reading them all.
    Returns:
      the grid coverage for the specified domain and ranges.

  - ### equals

    public boolean equals(Object obj)
    Tests whether this memory grid coverage resource is wrapping the same coverage as the given object. This method checks also that the listeners and the grid coverage processor are equal.
    Overrides:
      `equals` in class `Object`
    Parameters:
      `obj` - the object to compare.
    Returns:
      whether the two objects are memory resources wrapping the same coverage.

  - ### hashCode

    public int hashCode()
    Returns a hash code value for consistency with `equals(Object)`.
    Overrides:
      `hashCode` in class `Object`
    Returns:
      a hash code value.

  - ### toString

    public String toString()
    Returns a string representation of this resource. The default implementation returns the string representation of the wrapped coverage.
    Overrides:
      `toString` in class `Object`
    Returns:
      the string representation of this resource.