jdk/src/share/classes/java/time/temporal/TemporalField.java
author dsamersoff
Tue, 12 Feb 2013 16:02:14 +0400
changeset 15657 c588664d547e
parent 15289 3ac550392e43
child 15658 55b829ca2334
permissions -rw-r--r--
8007786: JDK-8002048 testcase doesn't work on Solaris Summary: test built in into Solaris shell doesn't have -e operator Reviewed-by: sla, sspitsyn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15289
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     1
/*
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     4
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    10
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    15
 * accompanied this code).
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    16
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    20
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    23
 * questions.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    24
 */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    25
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    26
/*
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    27
 * This file is available under and governed by the GNU General Public
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    28
 * License version 2 only, as published by the Free Software Foundation.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    29
 * However, the following notice accompanied the original version of this
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    30
 * file:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    31
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    32
 * Copyright (c) 2012, Stephen Colebourne & Michael Nascimento Santos
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    33
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    34
 * All rights reserved.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    35
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    36
 * Redistribution and use in source and binary forms, with or without
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    37
 * modification, are permitted provided that the following conditions are met:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    38
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    39
 *  * Redistributions of source code must retain the above copyright notice,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    40
 *    this list of conditions and the following disclaimer.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    41
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    42
 *  * Redistributions in binary form must reproduce the above copyright notice,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    43
 *    this list of conditions and the following disclaimer in the documentation
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    44
 *    and/or other materials provided with the distribution.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    45
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    46
 *  * Neither the name of JSR-310 nor the names of its contributors
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    47
 *    may be used to endorse or promote products derived from this software
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    48
 *    without specific prior written permission.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    49
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    50
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    51
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    52
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    53
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    54
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    55
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    56
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    57
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    58
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    59
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    60
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    61
 */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    62
package java.time.temporal;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    63
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    64
import java.time.DateTimeException;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    65
import java.time.format.DateTimeBuilder;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    66
import java.util.Comparator;
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    67
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    68
/**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    69
 * A field of date-time, such as month-of-year or hour-of-minute.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    70
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    71
 * Date and time is expressed using fields which partition the time-line into something
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    72
 * meaningful for humans. Implementations of this interface represent those fields.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    73
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    74
 * The most commonly used units are defined in {@link ChronoField}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    75
 * Further fields are supplied in {@link ISOFields}, {@link WeekFields} and {@link JulianFields}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    76
 * Fields can also be written by application code by implementing this interface.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    77
 * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    78
 * The field works using double dispatch. Client code calls methods on a date-time like
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    79
 * {@code LocalDateTime} which check if the field is a {@code ChronoField}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    80
 * If it is, then the date-time must handle it.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    81
 * Otherwise, the method call is re-dispatched to the matching method in this interface.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    82
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    83
 * <h3>Specification for implementors</h3>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    84
 * This interface must be implemented with care to ensure other classes operate correctly.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    85
 * All implementations that can be instantiated must be final, immutable and thread-safe.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    86
 * It is recommended to use an enum where possible.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    87
 *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    88
 * @since 1.8
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    89
 */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    90
public interface TemporalField extends Comparator<TemporalAccessor> {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    91
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    92
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    93
     * Gets a descriptive name for the field.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    94
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    95
     * The should be of the format 'BaseOfRange', such as 'MonthOfYear',
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    96
     * unless the field has a range of {@code FOREVER}, when only
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    97
     * the base unit is mentioned, such as 'Year' or 'Era'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    98
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
    99
     * @return the name, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   100
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   101
    String getName();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   102
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   103
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   104
     * Gets the unit that the field is measured in.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   105
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   106
     * The unit of the field is the period that varies within the range.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   107
     * For example, in the field 'MonthOfYear', the unit is 'Months'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   108
     * See also {@link #getRangeUnit()}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   109
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   110
     * @return the period unit defining the base unit of the field, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   111
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   112
    TemporalUnit getBaseUnit();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   113
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   114
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   115
     * Gets the range that the field is bound by.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   116
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   117
     * The range of the field is the period that the field varies within.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   118
     * For example, in the field 'MonthOfYear', the range is 'Years'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   119
     * See also {@link #getBaseUnit()}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   120
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   121
     * The range is never null. For example, the 'Year' field is shorthand for
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   122
     * 'YearOfForever'. It therefore has a unit of 'Years' and a range of 'Forever'.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   123
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   124
     * @return the period unit defining the range of the field, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   125
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   126
    TemporalUnit getRangeUnit();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   127
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   128
    //-----------------------------------------------------------------------
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   129
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   130
     * Compares the value of this field in two temporal objects.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   131
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   132
     * All fields implement {@link Comparator} on {@link TemporalAccessor}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   133
     * This allows a list of date-times to be compared using the value of a field.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   134
     * For example, you could sort a list of arbitrary temporal objects by the value of
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   135
     * the month-of-year field - {@code Collections.sort(list, MONTH_OF_YEAR)}
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   136
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   137
     * The default implementation must behave equivalent to this code:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   138
     * <pre>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   139
     *  return Long.compare(temporal1.getLong(this), temporal2.getLong(this));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   140
     * </pre>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   141
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   142
     * @param temporal1  the first temporal object to compare, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   143
     * @param temporal2  the second temporal object to compare, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   144
     * @throws DateTimeException if unable to obtain the value for this field
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   145
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   146
    public default int compare(TemporalAccessor temporal1, TemporalAccessor temporal2) {
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   147
         return Long.compare(temporal1.getLong(this), temporal2.getLong(this));
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   148
    }
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   149
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   150
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   151
     * Gets the range of valid values for the field.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   152
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   153
     * All fields can be expressed as a {@code long} integer.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   154
     * This method returns an object that describes the valid range for that value.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   155
     * This method is generally only applicable to the ISO-8601 calendar system.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   156
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   157
     * Note that the result only describes the minimum and maximum valid values
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   158
     * and it is important not to read too much into them. For example, there
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   159
     * could be values within the range that are invalid for the field.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   160
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   161
     * @return the range of valid values for the field, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   162
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   163
    ValueRange range();
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   164
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   165
    //-----------------------------------------------------------------------
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   166
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   167
     * Checks if this field is supported by the temporal object.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   168
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   169
     * This determines whether the temporal accessor supports this field.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   170
     * If this returns false, the the temporal cannot be queried for this field.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   171
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   172
     * There are two equivalent ways of using this method.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   173
     * The first is to invoke this method directly.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   174
     * The second is to use {@link TemporalAccessor#isSupported(TemporalField)}:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   175
     * <pre>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   176
     *   // these two lines are equivalent, but the second approach is recommended
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   177
     *   temporal = thisField.doIsSupported(temporal);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   178
     *   temporal = temporal.isSupported(thisField);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   179
     * </pre>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   180
     * It is recommended to use the second approach, {@code isSupported(TemporalField)},
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   181
     * as it is a lot clearer to read in code.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   182
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   183
     * Implementations should determine whether they are supported using the fields
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   184
     * available in {@link ChronoField}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   185
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   186
     * @param temporal  the temporal object to query, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   187
     * @return true if the date-time can be queried for this field, false if not
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   188
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   189
    boolean doIsSupported(TemporalAccessor temporal);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   190
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   191
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   192
     * Get the range of valid values for this field using the temporal object to
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   193
     * refine the result.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   194
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   195
     * This uses the temporal object to find the range of valid values for the field.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   196
     * This is similar to {@link #range()}, however this method refines the result
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   197
     * using the temporal. For example, if the field is {@code DAY_OF_MONTH} the
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   198
     * {@code range} method is not accurate as there are four possible month lengths,
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   199
     * 28, 29, 30 and 31 days. Using this method with a date allows the range to be
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   200
     * accurate, returning just one of those four options.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   201
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   202
     * There are two equivalent ways of using this method.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   203
     * The first is to invoke this method directly.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   204
     * The second is to use {@link TemporalAccessor#range(TemporalField)}:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   205
     * <pre>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   206
     *   // these two lines are equivalent, but the second approach is recommended
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   207
     *   temporal = thisField.doRange(temporal);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   208
     *   temporal = temporal.range(thisField);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   209
     * </pre>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   210
     * It is recommended to use the second approach, {@code range(TemporalField)},
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   211
     * as it is a lot clearer to read in code.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   212
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   213
     * Implementations should perform any queries or calculations using the fields
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   214
     * available in {@link ChronoField}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   215
     * If the field is not supported a {@code DateTimeException} must be thrown.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   216
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   217
     * @param temporal  the temporal object used to refine the result, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   218
     * @return the range of valid values for this field, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   219
     * @throws DateTimeException if the range for the field cannot be obtained
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   220
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   221
    ValueRange doRange(TemporalAccessor temporal);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   222
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   223
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   224
     * Gets the value of this field from the specified temporal object.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   225
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   226
     * This queries the temporal object for the value of this field.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   227
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   228
     * There are two equivalent ways of using this method.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   229
     * The first is to invoke this method directly.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   230
     * The second is to use {@link TemporalAccessor#getLong(TemporalField)}
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   231
     * (or {@link TemporalAccessor#get(TemporalField)}):
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   232
     * <pre>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   233
     *   // these two lines are equivalent, but the second approach is recommended
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   234
     *   temporal = thisField.doGet(temporal);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   235
     *   temporal = temporal.getLong(thisField);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   236
     * </pre>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   237
     * It is recommended to use the second approach, {@code getLong(TemporalField)},
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   238
     * as it is a lot clearer to read in code.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   239
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   240
     * Implementations should perform any queries or calculations using the fields
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   241
     * available in {@link ChronoField}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   242
     * If the field is not supported a {@code DateTimeException} must be thrown.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   243
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   244
     * @param temporal  the temporal object to query, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   245
     * @return the value of this field, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   246
     * @throws DateTimeException if a value for the field cannot be obtained
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   247
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   248
    long doGet(TemporalAccessor temporal);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   249
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   250
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   251
     * Returns a copy of the specified temporal object with the value of this field set.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   252
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   253
     * This returns a new temporal object based on the specified one with the value for
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   254
     * this field changed. For example, on a {@code LocalDate}, this could be used to
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   255
     * set the year, month or day-of-month.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   256
     * The returned object has the same observable type as the specified object.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   257
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   258
     * In some cases, changing a field is not fully defined. For example, if the target object is
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   259
     * a date representing the 31st January, then changing the month to February would be unclear.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   260
     * In cases like this, the implementation is responsible for resolving the result.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   261
     * Typically it will choose the previous valid date, which would be the last valid
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   262
     * day of February in this example.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   263
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   264
     * There are two equivalent ways of using this method.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   265
     * The first is to invoke this method directly.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   266
     * The second is to use {@link Temporal#with(TemporalField, long)}:
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   267
     * <pre>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   268
     *   // these two lines are equivalent, but the second approach is recommended
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   269
     *   temporal = thisField.doWith(temporal);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   270
     *   temporal = temporal.with(thisField);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   271
     * </pre>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   272
     * It is recommended to use the second approach, {@code with(TemporalField)},
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   273
     * as it is a lot clearer to read in code.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   274
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   275
     * Implementations should perform any queries or calculations using the fields
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   276
     * available in {@link ChronoField}.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   277
     * If the field is not supported a {@code DateTimeException} must be thrown.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   278
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   279
     * Implementations must not alter the specified temporal object.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   280
     * Instead, an adjusted copy of the original must be returned.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   281
     * This provides equivalent, safe behavior for immutable and mutable implementations.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   282
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   283
     * @param <R>  the type of the Temporal object
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   284
     * @param temporal the temporal object to adjust, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   285
     * @param newValue the new value of the field
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   286
     * @return the adjusted temporal object, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   287
     * @throws DateTimeException if the field cannot be set
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   288
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   289
    <R extends Temporal> R doWith(R temporal, long newValue);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   290
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   291
    /**
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   292
     * Resolves the date/time information in the builder
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   293
     * <p>
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   294
     * This method is invoked during the resolve of the builder.
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   295
     * Implementations should combine the associated field with others to form
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   296
     * objects like {@code LocalDate}, {@code LocalTime} and {@code LocalDateTime}
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   297
     *
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   298
     * @param builder  the builder to resolve, not null
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   299
     * @param value  the value of the associated field
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   300
     * @return true if builder has been changed, false otherwise
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   301
     * @throws DateTimeException if unable to resolve
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   302
     */
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   303
    boolean resolve(DateTimeBuilder builder, long value);
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   304
3ac550392e43 8003680: JSR 310 Date/Time API
sherman
parents:
diff changeset
   305
}