Class GroupAggregate

java.lang.Object
org.apache.sis.storage.AbstractResource
org.apache.sis.storage.aggregate.GroupAggregate
All Implemented Interfaces:
Aggregate, AggregatedResource, Resource

final class GroupAggregate extends AbstractResource implements Aggregate, AggregatedResource
An aggregate created when, after grouping resources by CRS and other attributes, more than one group still exist. Those groups become components of an aggregate. This is used as temporary object during analysis, then kept alive in last resort when we cannot build a single time series from a sequence of coverages at different times.

This class intentionally does not override AbstractResource.getIdentifier() because it would not be a persistent identifier.

Since:
1.3
Version:
1.3
  • Field Details

    • KEEP_ALIVE

      private static final int KEEP_ALIVE
      Minimum number of components for keeping this aggregate after analysis.
      See Also:
    • name

      private String name
      Name of this aggregate, or null if none. This is not a persistent identifier.
    • components

      private final Resource[] components
      The components of this aggregate. Array elements are initially null, but should all become non-null after a fill(…) method has been invoked. If the length is smaller than 2, then this aggregate is only a temporary object.
    • componentsAreLeaves

      private boolean componentsAreLeaves
      Whether all components are GridCoverageResource elements. This is used for skipping calls to #simplify() when it is known that no component can be simplified.
    • envelope

      private ImmutableEnvelope envelope
      The envelope of this aggregate, or null if not yet computed. May also be null if no component declare an envelope, or if the union cannot be computed.
      See Also:
    • envelopeIsEvaluated

      private boolean envelopeIsEvaluated
      Whether envelope has been initialized. The envelope may still be null if the initialization failed.
    • sampleDimensions

      List<SampleDimension> sampleDimensions
      The sample dimensions of all children in this group, or an empty collection if they are not the same. This field is initially null, but should become non-null after a fill(…) method has been invoked. This is used for metadata only.
  • Constructor Details

    • GroupAggregate

      GroupAggregate(StoreListeners listeners, String name, int count)
      Creates a new aggregate with the specified number of components. One of the fill(…) methods must be invoked after this constructor.
      Parameters:
      listeners - listeners of the parent resource, or null if none.
      name - name of this aggregate, or null if none.
      count - expected number of components.
      See Also:
    • GroupAggregate

      GroupAggregate(StoreListeners listeners, String name, GridCoverageResource[] components, List<SampleDimension> sampleDimensions)
      Creates a new aggregate with the specified components, which will receive no further processing. This is invoked when the caller has not been able to group the slices in a multi-dimensional cube. The result stay an aggregate of heterogynous resources.
      Parameters:
      listeners - listeners of the parent resource, or null if none.
      name - name of this aggregate, or null if none.
      components - the resources to uses as components of this aggregate.
      sampleDimensions - sample dimensions common to all grid coverage resources.
    • GroupAggregate

      private GroupAggregate(GroupAggregate source, Resource[] components)
      Creates a new resource with the same data than given resource but a different merge strategy.
      Parameters:
      source - the resource to copy.
      components - components with the new merge strategy.
  • Method Details

    • apply

      public final Resource apply(MergeStrategy strategy)
      Returns an aggregate with the same data than this aggregate but a different merge strategy.
      Specified by:
      apply in interface AggregatedResource
      Parameters:
      strategy - the new merge strategy to apply.
      Returns:
      resource using the specified strategy (may be this).
    • fillWithChildAggregates

      final <E extends Group<?>> void fillWithChildAggregates(Group<E> children, BiConsumer<E,GroupAggregate> childFiller)
      Sets all components of this aggregate to sub-aggregates, which are themselves initialized with the given filler. This method may be invoked recursively if the sub-aggregates themselves have sub-sub-aggregates.
      Type Parameters:
      E - type of object in the group.
      Parameters:
      children - data for creating children, as one sub-aggregate per member of the children group.
      childFiller - the action to execute for initializing each sub-aggregate. The first BiConsumer argument is a children member (the source) and the second argument is the sub-aggregate to initialize (the target).
    • fillWithCoverageComponents

      final void fillWithCoverageComponents(List<GroupByTransform> children, List<SampleDimension> ranges)
      Sets all components of this aggregate to grid coverage resources. Children created by this method are leaf nodes.
      Parameters:
      children - date for creating children, as one coverage per member of the children group.
      ranges - sample dimensions of the coverage to create. Stored as-is (not copied).
    • simplify

      final Resource simplify(CoverageAggregator aggregator)
      Simplifies the resource tree by removing all aggregates of 1 component.
      Parameters:
      aggregator - the aggregation builder which is invoking this method.
      Returns:
      the resource to use after simplification.
    • components

      public Collection<Resource> components()
      Returns the components of this aggregate.
      Specified by:
      components in interface Aggregate
      Returns:
      all children resources that are components of this aggregate. Never null.
    • getEnvelope

      public Optional<org.opengis.geometry.Envelope> getEnvelope() throws DataStoreException
      Returns the spatiotemporal envelope of this resource.
      Overrides:
      getEnvelope in class AbstractResource
      Returns:
      the spatiotemporal resource extent.
      Throws:
      DataStoreException - if an error occurred while reading or computing the envelope.
    • unionOfComponents

      static ImmutableEnvelope unionOfComponents(Resource[] components) throws DataStoreException, org.opengis.referencing.operation.TransformException
      Computes the union of envelopes provided by all the given resources.
      Parameters:
      components - the components for which to extract the envelope.
      Returns:
      union of envelope of all components, or null if none.
      Throws:
      DataStoreException
      org.opengis.referencing.operation.TransformException
    • setName

      public void setName(String name)
      Modifies the name of the resource. This information is used for metadata.
      Specified by:
      setName in interface AggregatedResource
      Parameters:
      name - new name of the resource.
    • createMetadata

      protected org.opengis.metadata.Metadata createMetadata() throws DataStoreException
      Creates when first requested the metadata about this aggregate. The metadata contains the title for this aggregation, the sample dimensions (if they are the same for all children) and the geographic bounding box.
      Overrides:
      createMetadata in class AbstractResource
      Returns:
      the newly created metadata, or null if unknown.
      Throws:
      DataStoreException - if an error occurred while reading metadata from this resource.
    • toString

      public String toString()
      Returns a string representation of this aggregate for debugging purposes.
      Overrides:
      toString in class Object