Path: blob/master/test/jdk/sun/util/calendar/zi/Month.java
41153 views
/*1* Copyright (c) 2000, 2018, 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.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.util.ArrayList;24import java.util.HashMap;25import java.util.List;26import java.util.Map;2728/**29* Month enum handles month related manipulation.30*31* @since 1.432*/33enum Month {34JANUARY("Jan"),35FEBRUARY("Feb"),36MARCH("Mar"),37APRIL("Apr"),38MAY("May"),39JUNE("Jun"),40JULY("Jul"),41AUGUST("Aug"),42SEPTEMBER("Sep"),43OCTOBER("Oct"),44NOVEMBER("Nov"),45DECEMBER("Dec");4647private final String abbr;4849private static final Map<String,Month> abbreviations50= new HashMap<String,Month>(12);5152static {53for (Month m : Month.values()) {54abbreviations.put(m.abbr, m);55}56}5758private Month(String abbr) {59this.abbr = abbr;60}6162int value() {63return ordinal() + 1;64}6566/**67* Parses the specified string as a month abbreviation.68* @param name the month abbreviation69* @return the Month value70*/71static Month parse(String name) {72Month m = abbreviations.get(name);73if (m != null) {74return m;75}76return null;77}7879/**80* @param month the nunmth number (1-based)81* @return the month name in uppercase of the specified month82*/83static String toString(int month) {84if (month >= JANUARY.value() && month <= DECEMBER.value()) {85return "Calendar." + Month.values()[month - 1];86}87throw new IllegalArgumentException("wrong month number: " + month);88}89}909192