001/* 002 * GeoAPI - Java interfaces for OGC/ISO standards 003 * Copyright © 2006-2023 Open Geospatial Consortium, Inc. 004 * http://www.geoapi.org 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.opengis.temporal; 019 020import java.time.DateTimeException; 021import java.time.temporal.TemporalAmount; 022import org.opengis.annotation.UML; 023 024import static org.opengis.annotation.Obligation.*; 025import static org.opengis.annotation.Specification.*; 026 027 028/** 029 * A one-dimensional temporal primitive that represent extent in time. 030 * A period is an open interval bounded by beginning and ending points. 031 * Those two points <em>should</em> be of the same class. For example, 032 * if the {@linkplain #getBeginning() beginning} is an instance of {@link java.time.LocalDate}, 033 * then the {@link #getEnding() ending} should also be an instance of {@code LocalDate}. 034 * If the two points are {@linkplain org.opengis.geometry.DirectPosition direct positions}, 035 * then they <em>shall</em> be associated to the same {@linkplain org.opengis.referencing.crs.TemporalCRS}. 036 * 037 * @author ISO 19108 (for abstract model and documentation) 038 * @author Stephane Fellah (Image Matters) 039 * @author Alexander Petkov 040 * @author Martin Desruisseaux (Geomatys) 041 * @author Remi Marechal (Geomatys). 042 * @since 3.1 043 * @version 3.1 044 */ 045@UML(identifier="TM_Period", specification=ISO_19108) 046public interface Period extends TemporalPrimitive { 047 /** 048 * Returns the beginning instant at which this period starts. 049 * Its position on the timeline shall be before the period {@linkplain #getEnding() ending}. 050 * 051 * @return the beginning instant at which this period starts. 052 */ 053 @UML(identifier="Beginning", obligation=MANDATORY, specification=ISO_19108) 054 Instant getBeginning(); 055 056 /** 057 * Returns the ending instant at which this period ends. 058 * Its position on the timeline shall be after the period {@linkplain #getBeginning() beginning}. 059 * 060 * @return the ending instant at which this period ends. 061 */ 062 @UML(identifier="Ending", obligation=MANDATORY, specification=ISO_19108) 063 Instant getEnding(); 064 065 /** 066 * Returns the duration of this period (optional operation). 067 * This is the {@linkplain Instant#distance(TemporalPrimitive) distance} 068 * between the period beginning and ending positions. 069 * The default implementation is as below: 070 * 071 * {@snippet lang="java" : 072 * return getBeginning().distance(getEnding()); 073 * } 074 * 075 * <h4>Exceptions</h4> 076 * This method shall throw an {@link IndeterminatePositionException} if the temporal 077 * position of a bound is {@linkplain Instant#getIndeterminatePosition() indeterminate}. 078 * A {@link DateTimeException} may also be thrown if the coordinates are 079 * {@link org.opengis.referencing.cs.CoordinateDataType#INTEGER ordinal values}. 080 * 081 * @return duration of this period. 082 * @throws UnsupportedOperationException if this operation is not supported. 083 * @throws IndeterminatePositionException if the temporal position of a bound is indeterminate. 084 * @throws DateTimeException if the duration cannot be computed between the temporal objects used as bounds. 085 * @throws ArithmeticException if the duration exceeds the capacity of the implementation. 086 * 087 * @see Instant#distance(TemporalPrimitive) 088 * @see java.time.Duration#between(Temporal, Temporal) 089 */ 090 @UML(identifier="TM_Separation.length", obligation=OPTIONAL, specification=ISO_19108) 091 default TemporalAmount length() { 092 return getBeginning().distance(getEnding()); 093 } 094}