Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/time/chrono/HijrahEra.java
38918 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* This file is available under and governed by the GNU General Public27* License version 2 only, as published by the Free Software Foundation.28* However, the following notice accompanied the original version of this29* file:30*31* Copyright (c) 2012, Stephen Colebourne & Michael Nascimento Santos32*33* All rights reserved.34*35* Redistribution and use in source and binary forms, with or without36* modification, are permitted provided that the following conditions are met:37*38* * Redistributions of source code must retain the above copyright notice,39* this list of conditions and the following disclaimer.40*41* * Redistributions in binary form must reproduce the above copyright notice,42* this list of conditions and the following disclaimer in the documentation43* and/or other materials provided with the distribution.44*45* * Neither the name of JSR-310 nor the names of its contributors46* may be used to endorse or promote products derived from this software47* without specific prior written permission.48*49* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS50* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT51* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR52* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR53* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,54* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,55* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR56* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF57* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING58* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS59* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.60*/61package java.time.chrono;6263import static java.time.temporal.ChronoField.ERA;6465import java.time.DateTimeException;66import java.time.temporal.ChronoField;67import java.time.temporal.TemporalField;68import java.time.temporal.UnsupportedTemporalTypeException;69import java.time.temporal.ValueRange;7071/**72* An era in the Hijrah calendar system.73* <p>74* The Hijrah calendar system has only one era covering the75* proleptic years greater than zero.76* <p>77* <b>Do not use {@code ordinal()} to obtain the numeric representation of {@code HijrahEra}.78* Use {@code getValue()} instead.</b>79*80* @implSpec81* This is an immutable and thread-safe enum.82*83* @since 1.884*/85public enum HijrahEra implements Era {8687/**88* The singleton instance for the current era, 'Anno Hegirae',89* which has the numeric value 1.90*/91AH;9293//-----------------------------------------------------------------------94/**95* Obtains an instance of {@code HijrahEra} from an {@code int} value.96* <p>97* The current era, which is the only accepted value, has the value 198*99* @param hijrahEra the era to represent, only 1 supported100* @return the HijrahEra.AH singleton, not null101* @throws DateTimeException if the value is invalid102*/103public static HijrahEra of(int hijrahEra) {104if (hijrahEra == 1 ) {105return AH;106} else {107throw new DateTimeException("Invalid era: " + hijrahEra);108}109}110111//-----------------------------------------------------------------------112/**113* Gets the numeric era {@code int} value.114* <p>115* The era AH has the value 1.116*117* @return the era value, 1 (AH)118*/119@Override120public int getValue() {121return 1;122}123124//-----------------------------------------------------------------------125/**126* Gets the range of valid values for the specified field.127* <p>128* The range object expresses the minimum and maximum valid values for a field.129* This era is used to enhance the accuracy of the returned range.130* If it is not possible to return the range, because the field is not supported131* or for some other reason, an exception is thrown.132* <p>133* If the field is a {@link ChronoField} then the query is implemented here.134* The {@code ERA} field returns the range.135* All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.136* <p>137* If the field is not a {@code ChronoField}, then the result of this method138* is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessor)}139* passing {@code this} as the argument.140* Whether the range can be obtained is determined by the field.141* <p>142* The {@code ERA} field returns a range for the one valid Hijrah era.143*144* @param field the field to query the range for, not null145* @return the range of valid values for the field, not null146* @throws DateTimeException if the range for the field cannot be obtained147* @throws UnsupportedTemporalTypeException if the unit is not supported148*/149@Override // override as super would return range from 0 to 1150public ValueRange range(TemporalField field) {151if (field == ERA) {152return ValueRange.of(1, 1);153}154return Era.super.range(field);155}156157}158159160