Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/time/chrono/IsoEra.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 java.time.DateTimeException;6465/**66* An era in the ISO calendar system.67* <p>68* The ISO-8601 standard does not define eras.69* A definition has therefore been created with two eras - 'Current era' (CE) for70* years on or after 0001-01-01 (ISO), and 'Before current era' (BCE) for years before that.71*72* <table summary="ISO years and eras" cellpadding="2" cellspacing="3" border="0" >73* <thead>74* <tr class="tableSubHeadingColor">75* <th class="colFirst" align="left">year-of-era</th>76* <th class="colFirst" align="left">era</th>77* <th class="colLast" align="left">proleptic-year</th>78* </tr>79* </thead>80* <tbody>81* <tr class="rowColor">82* <td>2</td><td>CE</td><td>2</td>83* </tr>84* <tr class="altColor">85* <td>1</td><td>CE</td><td>1</td>86* </tr>87* <tr class="rowColor">88* <td>1</td><td>BCE</td><td>0</td>89* </tr>90* <tr class="altColor">91* <td>2</td><td>BCE</td><td>-1</td>92* </tr>93* </tbody>94* </table>95* <p>96* <b>Do not use {@code ordinal()} to obtain the numeric representation of {@code IsoEra}.97* Use {@code getValue()} instead.</b>98*99* @implSpec100* This is an immutable and thread-safe enum.101*102* @since 1.8103*/104public enum IsoEra implements Era {105106/**107* The singleton instance for the era before the current one, 'Before Current Era',108* which has the numeric value 0.109*/110BCE,111/**112* The singleton instance for the current era, 'Current Era',113* which has the numeric value 1.114*/115CE;116117//-----------------------------------------------------------------------118/**119* Obtains an instance of {@code IsoEra} from an {@code int} value.120* <p>121* {@code IsoEra} is an enum representing the ISO eras of BCE/CE.122* This factory allows the enum to be obtained from the {@code int} value.123*124* @param isoEra the BCE/CE value to represent, from 0 (BCE) to 1 (CE)125* @return the era singleton, not null126* @throws DateTimeException if the value is invalid127*/128public static IsoEra of(int isoEra) {129switch (isoEra) {130case 0:131return BCE;132case 1:133return CE;134default:135throw new DateTimeException("Invalid era: " + isoEra);136}137}138139//-----------------------------------------------------------------------140/**141* Gets the numeric era {@code int} value.142* <p>143* The era BCE has the value 0, while the era CE has the value 1.144*145* @return the era value, from 0 (BCE) to 1 (CE)146*/147@Override148public int getValue() {149return ordinal();150}151152}153154155