< prev index next >

src/java.base/share/classes/java/time/chrono/ChronoLocalDate.java

Print this page
rev 17010 : 8178889: Move creation of AbstractChronology comparators to call sites
Reviewed-by: tbd


  49  *
  50  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  54  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  55  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  56  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  57  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  58  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  59  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  60  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61  */
  62 package java.time.chrono;
  63 
  64 import static java.time.temporal.ChronoField.EPOCH_DAY;
  65 import static java.time.temporal.ChronoField.ERA;
  66 import static java.time.temporal.ChronoField.YEAR;
  67 import static java.time.temporal.ChronoUnit.DAYS;
  68 

  69 import java.time.DateTimeException;
  70 import java.time.LocalDate;
  71 import java.time.LocalTime;
  72 import java.time.format.DateTimeFormatter;
  73 import java.time.temporal.ChronoField;
  74 import java.time.temporal.ChronoUnit;
  75 import java.time.temporal.Temporal;
  76 import java.time.temporal.TemporalAccessor;
  77 import java.time.temporal.TemporalAdjuster;
  78 import java.time.temporal.TemporalAmount;
  79 import java.time.temporal.TemporalField;
  80 import java.time.temporal.TemporalQueries;
  81 import java.time.temporal.TemporalQuery;
  82 import java.time.temporal.TemporalUnit;
  83 import java.time.temporal.UnsupportedTemporalTypeException;
  84 import java.util.Comparator;
  85 import java.util.Objects;
  86 
  87 /**
  88  * A date without time-of-day or time-zone in an arbitrary chronology, intended


 239  */
 240 public interface ChronoLocalDate
 241         extends Temporal, TemporalAdjuster, Comparable<ChronoLocalDate> {
 242 
 243     /**
 244      * Gets a comparator that compares {@code ChronoLocalDate} in
 245      * time-line order ignoring the chronology.
 246      * <p>
 247      * This comparator differs from the comparison in {@link #compareTo} in that it
 248      * only compares the underlying date and not the chronology.
 249      * This allows dates in different calendar systems to be compared based
 250      * on the position of the date on the local time-line.
 251      * The underlying comparison is equivalent to comparing the epoch-day.
 252      *
 253      * @return a comparator that compares in time-line order ignoring the chronology
 254      * @see #isAfter
 255      * @see #isBefore
 256      * @see #isEqual
 257      */
 258     static Comparator<ChronoLocalDate> timeLineOrder() {
 259         return AbstractChronology.DATE_ORDER;


 260     }
 261 
 262     //-----------------------------------------------------------------------
 263     /**
 264      * Obtains an instance of {@code ChronoLocalDate} from a temporal object.
 265      * <p>
 266      * This obtains a local date based on the specified temporal.
 267      * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 268      * which this factory converts to an instance of {@code ChronoLocalDate}.
 269      * <p>
 270      * The conversion extracts and combines the chronology and the date
 271      * from the temporal object. The behavior is equivalent to using
 272      * {@link Chronology#date(TemporalAccessor)} with the extracted chronology.
 273      * Implementations are permitted to perform optimizations such as accessing
 274      * those fields that are equivalent to the relevant objects.
 275      * <p>
 276      * This method matches the signature of the functional interface {@link TemporalQuery}
 277      * allowing it to be used as a query via method reference, {@code ChronoLocalDate::from}.
 278      *
 279      * @param temporal  the temporal object to convert, not null




  49  *
  50  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  54  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  55  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  56  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  57  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  58  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  59  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  60  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61  */
  62 package java.time.chrono;
  63 
  64 import static java.time.temporal.ChronoField.EPOCH_DAY;
  65 import static java.time.temporal.ChronoField.ERA;
  66 import static java.time.temporal.ChronoField.YEAR;
  67 import static java.time.temporal.ChronoUnit.DAYS;
  68 
  69 import java.io.Serializable;
  70 import java.time.DateTimeException;
  71 import java.time.LocalDate;
  72 import java.time.LocalTime;
  73 import java.time.format.DateTimeFormatter;
  74 import java.time.temporal.ChronoField;
  75 import java.time.temporal.ChronoUnit;
  76 import java.time.temporal.Temporal;
  77 import java.time.temporal.TemporalAccessor;
  78 import java.time.temporal.TemporalAdjuster;
  79 import java.time.temporal.TemporalAmount;
  80 import java.time.temporal.TemporalField;
  81 import java.time.temporal.TemporalQueries;
  82 import java.time.temporal.TemporalQuery;
  83 import java.time.temporal.TemporalUnit;
  84 import java.time.temporal.UnsupportedTemporalTypeException;
  85 import java.util.Comparator;
  86 import java.util.Objects;
  87 
  88 /**
  89  * A date without time-of-day or time-zone in an arbitrary chronology, intended


 240  */
 241 public interface ChronoLocalDate
 242         extends Temporal, TemporalAdjuster, Comparable<ChronoLocalDate> {
 243 
 244     /**
 245      * Gets a comparator that compares {@code ChronoLocalDate} in
 246      * time-line order ignoring the chronology.
 247      * <p>
 248      * This comparator differs from the comparison in {@link #compareTo} in that it
 249      * only compares the underlying date and not the chronology.
 250      * This allows dates in different calendar systems to be compared based
 251      * on the position of the date on the local time-line.
 252      * The underlying comparison is equivalent to comparing the epoch-day.
 253      *
 254      * @return a comparator that compares in time-line order ignoring the chronology
 255      * @see #isAfter
 256      * @see #isBefore
 257      * @see #isEqual
 258      */
 259     static Comparator<ChronoLocalDate> timeLineOrder() {
 260         return (Comparator<ChronoLocalDate> & Serializable) (date1, date2) -> {
 261             return Long.compare(date1.toEpochDay(), date2.toEpochDay());
 262         };
 263     }
 264 
 265     //-----------------------------------------------------------------------
 266     /**
 267      * Obtains an instance of {@code ChronoLocalDate} from a temporal object.
 268      * <p>
 269      * This obtains a local date based on the specified temporal.
 270      * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
 271      * which this factory converts to an instance of {@code ChronoLocalDate}.
 272      * <p>
 273      * The conversion extracts and combines the chronology and the date
 274      * from the temporal object. The behavior is equivalent to using
 275      * {@link Chronology#date(TemporalAccessor)} with the extracted chronology.
 276      * Implementations are permitted to perform optimizations such as accessing
 277      * those fields that are equivalent to the relevant objects.
 278      * <p>
 279      * This method matches the signature of the functional interface {@link TemporalQuery}
 280      * allowing it to be used as a query via method reference, {@code ChronoLocalDate::from}.
 281      *
 282      * @param temporal  the temporal object to convert, not null


< prev index next >