# Class DefaultTemporalExtent

Object
AbstractMetadata
ModifiableMetadata
ISOMetadata
DefaultTemporalExtent

All Implemented Interfaces:
  `Serializable`, `Emptiable`, `LenientComparable`, `IdentifiedObject`, `TemporalExtent`

Direct Known Subclasses:
  `DefaultSpatialTemporalExtent`

public class DefaultTemporalExtent extends ISOMetadata implements TemporalExtent
Time period covered by the content of the dataset. The following property is mandatory in a well-formed metadata according ISO 19115:
`EX_TemporalExtent` `└─extent…………………` The date and time for the content of the dataset.
In addition to the standard properties, SIS provides the following methods:

- `getBeginning()` for fetching the start time from the temporal primitive.
- `getEnding()` for fetching the end time from the temporal primitive.
- `setBounds(Date, Date)` for setting the extent from the given start and end time.
- `setBounds(Envelope)` for setting the extent from the given envelope.

## Limitations

- Instances of this class are not synchronized for multi-threading. Synchronization, if needed, is caller's responsibility.
- Serialized objects of this class are not guaranteed to be compatible with future Apache SIS releases. Serialization support is appropriate for short term storage or RMI between applications running the same version of Apache SIS. For long term storage, use `XML` instead.

Since:
  0.3
See Also:
  - Serialized Form

- ## Nested Class Summary

  ### Nested classes/interfaces inherited from class ModifiableMetadata

  `ModifiableMetadata​.State`

- ## Field Summary

  ### Fields inherited from class ISOMetadata

  `identifiers`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DefaultTemporalExtent()`
  Constructs an initially empty temporal extent.
  `DefaultTemporalExtent(Temporal beginning, Temporal ending)`
  Constructs a new instance initialized with the specified values.
  `DefaultTemporalExtent(TemporalExtent object)`
  Constructs a new instance initialized with the values from the specified metadata object.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static DefaultTemporalExtent`
  `castOrCopy(TemporalExtent object)`
  Returns a SIS metadata implementation with the values of the given arbitrary implementation.
  `Optional<Temporal>`
  `getBeginning()`
  Returns the start of the temporal range for the content of the dataset.
  `Optional<Temporal>`
  `getEnding()`
  Returns the end of the temporal range for the content of the dataset.
  `Date`
  `getEndTime()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Replaced by `getEnding()` in order to transition to `java​.time` API.
  `TemporalPrimitive`
  `getExtent()`
  Returns the date and time for the content of the dataset.
  `Date`
  `getStartTime()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Replaced by `getBeginning()` in order to transition to `java​.time` API.
  `void`
  `intersect(TemporalExtent other)`
  Sets this temporal extent to the intersection of this extent with the specified one.
  `void`
  `setBounds(Temporal beginning, Temporal ending)`
  Sets the temporal extent to the specified values.
  `void`
  `setBounds(Date startTime, Date endTime)`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Replaced by `setBounds(Temporal, Temporal)` in order to transition to `java​.time` API.
  `void`
  `setBounds(Envelope envelope)`
  Sets this temporal extent to values inferred from the specified envelope.
  `void`
  `setExtent(TemporalPrimitive newValue)`
  Sets the date and time for the content of the dataset.

  ### Methods inherited from class ISOMetadata

  `getIdentifier, getIdentifierMap, getIdentifiers, getStandard, setIdentifier`

  ### Methods inherited from class ModifiableMetadata

  `checkWritePermission, collectionType, copyCollection, copyList, copyMap, copySet, deepCopy, nonNullCollection, nonNullList, nonNullMap, nonNullSet, singleton, state, writeCollection, writeList, writeMap, writeSet`

  ### Methods inherited from class AbstractMetadata

  `asMap, asTreeTable, clone, equals, equals, getInterface, hashCode, isEmpty, nilReasons, prune, toString`

  ### Methods inherited from class Object

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

- ## Constructor Details

  - ### DefaultTemporalExtent

    public DefaultTemporalExtent()
    Constructs an initially empty temporal extent.

  - ### DefaultTemporalExtent

    public DefaultTemporalExtent(Temporal beginning, Temporal ending)
    Constructs a new instance initialized with the specified values.
    Parameters:
      `beginning` - the start date and time for the content of the dataset, or `null` if none.
      `ending` - the end date and time for the content of the dataset, or `null` if none.
    Since:
      1.5
    See Also:
      - `setBounds(Temporal, Temporal)`

  - ### DefaultTemporalExtent

    public DefaultTemporalExtent(TemporalExtent object)
    Constructs a new instance initialized with the values from the specified metadata object. This is a shallow copy constructor, because the other metadata contained in the given object are not recursively copied.
    Parameters:
      `object` - the metadata to copy values from, or `null` if none.
    See Also:
      - `castOrCopy(TemporalExtent)`

- ## Method Details

  - ### castOrCopy

    public static DefaultTemporalExtent castOrCopy(TemporalExtent object)
    Returns a SIS metadata implementation with the values of the given arbitrary implementation. This method performs the first applicable action in the following choices:
    - If the given object is `null`, then this method returns `null`.
    - Otherwise if the given object is an instance of `SpatialTemporalExtent`, then this method delegates to the `castOrCopy(…)` method of the corresponding SIS subclass.
    - Otherwise if the given object is already an instance of `DefaultTemporalExtent`, then it is returned unchanged.
    - Otherwise a new `DefaultTemporalExtent` instance is created using the copy constructor and returned. Note that this is a shallow copy operation, because the other metadata contained in the given object are not recursively copied.
    Parameters:
      `object` - the object to get as a SIS implementation, or `null` if none.
    Returns:
      a SIS implementation containing the values of the given object (may be the given object itself), or `null` if the argument was null.

  - ### getExtent

    public TemporalPrimitive getExtent()
    Returns the date and time for the content of the dataset.
    Specified by:
      `getExtent` in interface `TemporalExtent`
    Returns:
      the date and time for the content, or `null`.

  - ### setExtent

    public void setExtent(TemporalPrimitive newValue)
    Sets the date and time for the content of the dataset.
    Parameters:
      `newValue` - the new content date.

  - ### getBeginning

    public Optional<Temporal> getBeginning()
    Returns the start of the temporal range for the content of the dataset. This method tries to infer this value from the extent. The returned object is often an `Instant`, but not necessarily.
    Returns:
      the start of the temporal range.
    Since:
      1.5

  - ### getEnding

    public Optional<Temporal> getEnding()
    Returns the end of the temporal range for the content of the dataset. This method tries to infer this value from the extent. The returned object is often an `Instant`, but not necessarily.
    Returns:
      the end of the temporal range.
    Since:
      1.5

  - ### getStartTime

    @Deprecated(since="1.5", forRemoval=true) public Date getStartTime()
    Deprecated, for removal: This API element is subject to removal in a future version.
    Replaced by `getBeginning()` in order to transition to `java​.time` API.
    The start date and time for the content of the dataset. This method tries to infer it from the extent.
    Returns:
      the start time, or `null` if none.

  - ### getEndTime

    @Deprecated(since="1.5", forRemoval=true) public Date getEndTime()
    Deprecated, for removal: This API element is subject to removal in a future version.
    Replaced by `getEnding()` in order to transition to `java​.time` API.
    Returns the end date and time for the content of the dataset. This method tries to infer it from the extent.
    Returns:
      the end time, or `null` if none.

  - ### setBounds

    @Deprecated(since="1.5", forRemoval=true) public void setBounds(Date startTime, Date endTime)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Replaced by `setBounds(Temporal, Temporal)` in order to transition to `java​.time` API.
    Sets the temporal extent to the specified values. This convenience method creates a temporal primitive for the given dates, then invokes `setExtent(TemporalPrimitive)`.
    Parameters:
      `startTime` - the start date and time for the content of the dataset, or `null` if none.
      `endTime` - the end date and time for the content of the dataset, or `null` if none.

  - ### setBounds

    public void setBounds(Temporal beginning, Temporal ending)
    Sets the temporal extent to the specified values. This convenience method creates a temporal primitive for the given dates and/or times, then invokes `setExtent(TemporalPrimitive)`.
    Parameters:
      `beginning` - the start date and time for the content of the dataset, or `null` if none.
      `ending` - the end date and time for the content of the dataset, or `null` if none.
    Since:
      1.5

  - ### setBounds

    public void setBounds(Envelope envelope) throws TransformException
    Sets this temporal extent to values inferred from the specified envelope. The given envelope must have a CRS, and at least one dimension of that CRS shall be assignable to a property of this extent.

    Note: this method is available only if the `org​.apache​.sis​.referencing` module is available on the module path.

    Parameters:
      `envelope` - the envelope to use for setting this temporal extent.
    Throws:
      `UnsupportedOperationException` - if the referencing module is not on the module path.
      `TransformException` - if the envelope cannot be transformed to a temporal extent.
    See Also:
      - `DefaultExtent​.addElements(Envelope)`
      - `DefaultGeographicBoundingBox​.setBounds(Envelope)`
      - `DefaultVerticalExtent​.setBounds(Envelope)`

  - ### intersect

    public void intersect(TemporalExtent other)
    Sets this temporal extent to the intersection of this extent with the specified one. If there is no intersection between the two extents, then this method sets the temporal primitive to nil. If either this extent or the specified extent has nil primitive, then the intersection result will also be nil.
    Parameters:
      `other` - the temporal extent to intersect with this extent.
    Since:
      0.8
    See Also:
      - `Extents​.intersection(TemporalExtent, TemporalExtent)`
      - `GeneralEnvelope​.intersect(Envelope)`