author | rriggs |
Thu, 17 Oct 2013 10:37:23 -0400 | |
changeset 20873 | e91d5b1cb8e6 |
parent 20519 | eee7a92074fd |
permissions | -rw-r--r-- |
20519
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
1 |
/* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
4 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
10 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
15 |
* accompanied this code). |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
16 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
20 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
23 |
* questions. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
24 |
*/ |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
25 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
26 |
/* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
27 |
* This file is available under and governed by the GNU General Public |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
28 |
* License version 2 only, as published by the Free Software Foundation. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
29 |
* However, the following notice accompanied the original version of this |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
30 |
* file: |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
31 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
32 |
* Copyright (c) 2013, Stephen Colebourne & Michael Nascimento Santos |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
33 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
34 |
* All rights reserved. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
35 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
36 |
* Redistribution and use in source and binary forms, with or without |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
37 |
* modification, are permitted provided that the following conditions are met: |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
38 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
39 |
* * Redistributions of source code must retain the above copyright notice, |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
40 |
* this list of conditions and the following disclaimer. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
41 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
42 |
* * Redistributions in binary form must reproduce the above copyright notice, |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
43 |
* this list of conditions and the following disclaimer in the documentation |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
44 |
* and/or other materials provided with the distribution. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
45 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
46 |
* * Neither the name of JSR-310 nor the names of its contributors |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
47 |
* may be used to endorse or promote products derived from this software |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
48 |
* without specific prior written permission. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
49 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
50 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
51 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
52 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
53 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
54 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
55 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
56 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
57 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
58 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
59 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
60 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
61 |
*/ |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
62 |
package java.time.chrono; |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
63 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
64 |
import java.time.DateTimeException; |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
65 |
import java.time.temporal.ChronoUnit; |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
66 |
import java.time.temporal.Temporal; |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
67 |
import java.time.temporal.TemporalAmount; |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
68 |
import java.time.temporal.TemporalUnit; |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
69 |
import java.time.temporal.UnsupportedTemporalTypeException; |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
70 |
import java.util.List; |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
71 |
import java.util.Objects; |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
72 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
73 |
/** |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
74 |
* A date-based amount of time, such as '3 years, 4 months and 5 days' in an |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
75 |
* arbitrary chronology, intended for advanced globalization use cases. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
76 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
77 |
* This interface models a date-based amount of time in a calendar system. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
78 |
* While most calendar systems use years, months and days, some do not. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
79 |
* Therefore, this interface operates solely in terms of a set of supported |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
80 |
* units that are defined by the {@code Chronology}. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
81 |
* The set of supported units is fixed for a given chronology. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
82 |
* The amount of a supported unit may be set to zero. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
83 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
84 |
* The period is modeled as a directed amount of time, meaning that individual |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
85 |
* parts of the period may be negative. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
86 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
87 |
* @implSpec |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
88 |
* This interface must be implemented with care to ensure other classes operate correctly. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
89 |
* All implementations that can be instantiated must be final, immutable and thread-safe. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
90 |
* Subclasses should be Serializable wherever possible. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
91 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
92 |
* @since 1.8 |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
93 |
*/ |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
94 |
public interface ChronoPeriod |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
95 |
extends TemporalAmount { |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
96 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
97 |
/** |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
98 |
* Obtains a {@code ChronoPeriod} consisting of amount of time between two dates. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
99 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
100 |
* The start date is included, but the end date is not. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
101 |
* The period is calculated using {@link ChronoLocalDate#until(ChronoLocalDate)}. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
102 |
* As such, the calculation is chronology specific. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
103 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
104 |
* The chronology of the first date is used. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
105 |
* The chronology of the second date is ignored, with the date being converted |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
106 |
* to the target chronology system before the calculation starts. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
107 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
108 |
* The result of this method can be a negative period if the end is before the start. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
109 |
* In most cases, the positive/negative sign will be the same in each of the supported fields. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
110 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
111 |
* @param startDateInclusive the start date, inclusive, specifying the chronology of the calculation, not null |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
112 |
* @param endDateExclusive the end date, exclusive, in any chronology, not null |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
113 |
* @return the period between this date and the end date, not null |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
114 |
* @see ChronoLocalDate#until(ChronoLocalDate) |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
115 |
*/ |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
116 |
public static ChronoPeriod between(ChronoLocalDate startDateInclusive, ChronoLocalDate endDateExclusive) { |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
117 |
Objects.requireNonNull(startDateInclusive, "startDateInclusive"); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
118 |
Objects.requireNonNull(endDateExclusive, "endDateExclusive"); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
119 |
return startDateInclusive.until(endDateExclusive); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
120 |
} |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
121 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
122 |
//----------------------------------------------------------------------- |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
123 |
/** |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
124 |
* Gets the value of the requested unit. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
125 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
126 |
* The supported units are chronology specific. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
127 |
* They will typically be {@link ChronoUnit#YEARS YEARS}, |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
128 |
* {@link ChronoUnit#MONTHS MONTHS} and {@link ChronoUnit#DAYS DAYS}. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
129 |
* Requesting an unsupported unit will throw an exception. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
130 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
131 |
* @param unit the {@code TemporalUnit} for which to return the value |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
132 |
* @return the long value of the unit |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
133 |
* @throws DateTimeException if the unit is not supported |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
134 |
* @throws UnsupportedTemporalTypeException if the unit is not supported |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
135 |
*/ |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
136 |
@Override |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
137 |
long get(TemporalUnit unit); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
138 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
139 |
/** |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
140 |
* Gets the set of units supported by this period. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
141 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
142 |
* The supported units are chronology specific. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
143 |
* They will typically be {@link ChronoUnit#YEARS YEARS}, |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
144 |
* {@link ChronoUnit#MONTHS MONTHS} and {@link ChronoUnit#DAYS DAYS}. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
145 |
* They are returned in order from largest to smallest. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
146 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
147 |
* This set can be used in conjunction with {@link #get(TemporalUnit)} |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
148 |
* to access the entire state of the period. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
149 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
150 |
* @return a list containing the supported units, not null |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
151 |
*/ |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
152 |
@Override |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
153 |
List<TemporalUnit> getUnits(); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
154 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
155 |
/** |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
156 |
* Gets the chronology that defines the meaning of the supported units. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
157 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
158 |
* The period is defined by the chronology. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
159 |
* It controls the supported units and restricts addition/subtraction |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
160 |
* to {@code ChronoLocalDate} instances of the same chronology. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
161 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
162 |
* @return the chronology defining the period, not null |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
163 |
*/ |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
164 |
Chronology getChronology(); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
165 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
166 |
//----------------------------------------------------------------------- |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
167 |
/** |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
168 |
* Checks if all the supported units of this period are zero. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
169 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
170 |
* @return true if this period is zero-length |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
171 |
*/ |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
172 |
default boolean isZero() { |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
173 |
for (TemporalUnit unit : getUnits()) { |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
174 |
if (get(unit) != 0) { |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
175 |
return false; |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
176 |
} |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
177 |
} |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
178 |
return true; |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
179 |
} |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
180 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
181 |
/** |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
182 |
* Checks if any of the supported units of this period are negative. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
183 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
184 |
* @return true if any unit of this period is negative |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
185 |
*/ |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
186 |
default boolean isNegative() { |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
187 |
for (TemporalUnit unit : getUnits()) { |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
188 |
if (get(unit) < 0) { |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
189 |
return true; |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
190 |
} |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
191 |
} |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
192 |
return false; |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
193 |
} |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
194 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
195 |
//----------------------------------------------------------------------- |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
196 |
/** |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
197 |
* Returns a copy of this period with the specified period added. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
198 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
199 |
* If the specified amount is a {@code ChronoPeriod} then it must have |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
200 |
* the same chronology as this period. Implementations may choose to |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
201 |
* accept or reject other {@code TemporalAmount} implementations. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
202 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
203 |
* This instance is immutable and unaffected by this method call. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
204 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
205 |
* @param amountToAdd the period to add, not null |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
206 |
* @return a {@code ChronoPeriod} based on this period with the requested period added, not null |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
207 |
* @throws ArithmeticException if numeric overflow occurs |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
208 |
*/ |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
209 |
ChronoPeriod plus(TemporalAmount amountToAdd); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
210 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
211 |
/** |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
212 |
* Returns a copy of this period with the specified period subtracted. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
213 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
214 |
* If the specified amount is a {@code ChronoPeriod} then it must have |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
215 |
* the same chronology as this period. Implementations may choose to |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
216 |
* accept or reject other {@code TemporalAmount} implementations. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
217 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
218 |
* This instance is immutable and unaffected by this method call. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
219 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
220 |
* @param amountToSubtract the period to subtract, not null |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
221 |
* @return a {@code ChronoPeriod} based on this period with the requested period subtracted, not null |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
222 |
* @throws ArithmeticException if numeric overflow occurs |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
223 |
*/ |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
224 |
ChronoPeriod minus(TemporalAmount amountToSubtract); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
225 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
226 |
//----------------------------------------------------------------------- |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
227 |
/** |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
228 |
* Returns a new instance with each amount in this period in this period |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
229 |
* multiplied by the specified scalar. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
230 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
231 |
* This returns a period with each supported unit individually multiplied. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
232 |
* For example, a period of "2 years, -3 months and 4 days" multiplied by |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
233 |
* 3 will return "6 years, -9 months and 12 days". |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
234 |
* No normalization is performed. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
235 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
236 |
* @param scalar the scalar to multiply by, not null |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
237 |
* @return a {@code ChronoPeriod} based on this period with the amounts multiplied |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
238 |
* by the scalar, not null |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
239 |
* @throws ArithmeticException if numeric overflow occurs |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
240 |
*/ |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
241 |
ChronoPeriod multipliedBy(int scalar); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
242 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
243 |
/** |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
244 |
* Returns a new instance with each amount in this period negated. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
245 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
246 |
* This returns a period with each supported unit individually negated. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
247 |
* For example, a period of "2 years, -3 months and 4 days" will be |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
248 |
* negated to "-2 years, 3 months and -4 days". |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
249 |
* No normalization is performed. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
250 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
251 |
* @return a {@code ChronoPeriod} based on this period with the amounts negated, not null |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
252 |
* @throws ArithmeticException if numeric overflow occurs, which only happens if |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
253 |
* one of the units has the value {@code Long.MIN_VALUE} |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
254 |
*/ |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
255 |
default ChronoPeriod negated() { |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
256 |
return multipliedBy(-1); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
257 |
} |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
258 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
259 |
//----------------------------------------------------------------------- |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
260 |
/** |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
261 |
* Returns a copy of this period with the amounts of each unit normalized. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
262 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
263 |
* The process of normalization is specific to each calendar system. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
264 |
* For example, in the ISO calendar system, the years and months are |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
265 |
* normalized but the days are not, such that "15 months" would be |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
266 |
* normalized to "1 year and 3 months". |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
267 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
268 |
* This instance is immutable and unaffected by this method call. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
269 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
270 |
* @return a {@code ChronoPeriod} based on this period with the amounts of each |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
271 |
* unit normalized, not null |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
272 |
* @throws ArithmeticException if numeric overflow occurs |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
273 |
*/ |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
274 |
ChronoPeriod normalized(); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
275 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
276 |
//------------------------------------------------------------------------- |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
277 |
/** |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
278 |
* Adds this period to the specified temporal object. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
279 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
280 |
* This returns a temporal object of the same observable type as the input |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
281 |
* with this period added. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
282 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
283 |
* In most cases, it is clearer to reverse the calling pattern by using |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
284 |
* {@link Temporal#plus(TemporalAmount)}. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
285 |
* <pre> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
286 |
* // these two lines are equivalent, but the second approach is recommended |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
287 |
* dateTime = thisPeriod.addTo(dateTime); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
288 |
* dateTime = dateTime.plus(thisPeriod); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
289 |
* </pre> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
290 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
291 |
* The specified temporal must have the same chronology as this period. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
292 |
* This returns a temporal with the non-zero supported units added. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
293 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
294 |
* This instance is immutable and unaffected by this method call. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
295 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
296 |
* @param temporal the temporal object to adjust, not null |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
297 |
* @return an object of the same type with the adjustment made, not null |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
298 |
* @throws DateTimeException if unable to add |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
299 |
* @throws ArithmeticException if numeric overflow occurs |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
300 |
*/ |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
301 |
@Override |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
302 |
Temporal addTo(Temporal temporal); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
303 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
304 |
/** |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
305 |
* Subtracts this period from the specified temporal object. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
306 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
307 |
* This returns a temporal object of the same observable type as the input |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
308 |
* with this period subtracted. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
309 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
310 |
* In most cases, it is clearer to reverse the calling pattern by using |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
311 |
* {@link Temporal#minus(TemporalAmount)}. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
312 |
* <pre> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
313 |
* // these two lines are equivalent, but the second approach is recommended |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
314 |
* dateTime = thisPeriod.subtractFrom(dateTime); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
315 |
* dateTime = dateTime.minus(thisPeriod); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
316 |
* </pre> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
317 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
318 |
* The specified temporal must have the same chronology as this period. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
319 |
* This returns a temporal with the non-zero supported units subtracted. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
320 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
321 |
* This instance is immutable and unaffected by this method call. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
322 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
323 |
* @param temporal the temporal object to adjust, not null |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
324 |
* @return an object of the same type with the adjustment made, not null |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
325 |
* @throws DateTimeException if unable to subtract |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
326 |
* @throws ArithmeticException if numeric overflow occurs |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
327 |
*/ |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
328 |
@Override |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
329 |
Temporal subtractFrom(Temporal temporal); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
330 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
331 |
//----------------------------------------------------------------------- |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
332 |
/** |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
333 |
* Checks if this period is equal to another period, including the chronology. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
334 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
335 |
* Compares this period with another ensuring that the type, each amount and |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
336 |
* the chronology are the same. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
337 |
* Note that this means that a period of "15 Months" is not equal to a period |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
338 |
* of "1 Year and 3 Months". |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
339 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
340 |
* @param obj the object to check, null returns false |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
341 |
* @return true if this is equal to the other period |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
342 |
*/ |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
343 |
@Override |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
344 |
boolean equals(Object obj); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
345 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
346 |
/** |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
347 |
* A hash code for this period. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
348 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
349 |
* @return a suitable hash code |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
350 |
*/ |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
351 |
@Override |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
352 |
int hashCode(); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
353 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
354 |
//----------------------------------------------------------------------- |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
355 |
/** |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
356 |
* Outputs this period as a {@code String}. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
357 |
* <p> |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
358 |
* The output will include the period amounts and chronology. |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
359 |
* |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
360 |
* @return a string representation of this period, not null |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
361 |
*/ |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
362 |
@Override |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
363 |
String toString(); |
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
364 |
|
eee7a92074fd
8023762: Add ChronoPeriod interface and bind period to Chronology
rriggs
parents:
diff
changeset
|
365 |
} |