Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/time/format/TextStyle.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) 2008-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.format;6263import java.util.Calendar;6465/**66* Enumeration of the style of text formatting and parsing.67* <p>68* Text styles define three sizes for the formatted text - 'full', 'short' and 'narrow'.69* Each of these three sizes is available in both 'standard' and 'stand-alone' variations.70* <p>71* The difference between the three sizes is obvious in most languages.72* For example, in English the 'full' month is 'January', the 'short' month is 'Jan'73* and the 'narrow' month is 'J'. Note that the narrow size is often not unique.74* For example, 'January', 'June' and 'July' all have the 'narrow' text 'J'.75* <p>76* The difference between the 'standard' and 'stand-alone' forms is trickier to describe77* as there is no difference in English. However, in other languages there is a difference78* in the word used when the text is used alone, as opposed to in a complete date.79* For example, the word used for a month when used alone in a date picker is different80* to the word used for month in association with a day and year in a date.81*82* @implSpec83* This is immutable and thread-safe enum.84*/85public enum TextStyle {86// ordered from large to small87// ordered so that bit 0 of the ordinal indicates stand-alone.8889/**90* Full text, typically the full description.91* For example, day-of-week Monday might output "Monday".92*/93FULL(Calendar.LONG_FORMAT, 0),94/**95* Full text for stand-alone use, typically the full description.96* For example, day-of-week Monday might output "Monday".97*/98FULL_STANDALONE(Calendar.LONG_STANDALONE, 0),99/**100* Short text, typically an abbreviation.101* For example, day-of-week Monday might output "Mon".102*/103SHORT(Calendar.SHORT_FORMAT, 1),104/**105* Short text for stand-alone use, typically an abbreviation.106* For example, day-of-week Monday might output "Mon".107*/108SHORT_STANDALONE(Calendar.SHORT_STANDALONE, 1),109/**110* Narrow text, typically a single letter.111* For example, day-of-week Monday might output "M".112*/113NARROW(Calendar.NARROW_FORMAT, 1),114/**115* Narrow text for stand-alone use, typically a single letter.116* For example, day-of-week Monday might output "M".117*/118NARROW_STANDALONE(Calendar.NARROW_STANDALONE, 1);119120private final int calendarStyle;121private final int zoneNameStyleIndex;122123private TextStyle(int calendarStyle, int zoneNameStyleIndex) {124this.calendarStyle = calendarStyle;125this.zoneNameStyleIndex = zoneNameStyleIndex;126}127128/**129* Returns true if the Style is a stand-alone style.130* @return true if the style is a stand-alone style.131*/132public boolean isStandalone() {133return (ordinal() & 1) == 1;134}135136/**137* Returns the stand-alone style with the same size.138* @return the stand-alone style with the same size139*/140public TextStyle asStandalone() {141return TextStyle.values()[ordinal() | 1];142}143144/**145* Returns the normal style with the same size.146*147* @return the normal style with the same size148*/149public TextStyle asNormal() {150return TextStyle.values()[ordinal() & ~1];151}152153/**154* Returns the {@code Calendar} style corresponding to this {@code TextStyle}.155*156* @return the corresponding {@code Calendar} style157*/158int toCalendarStyle() {159return calendarStyle;160}161162/**163* Returns the relative index value to an element of the {@link164* java.text.DateFormatSymbols#getZoneStrings() DateFormatSymbols.getZoneStrings()}165* value, 0 for long names and 1 for short names (abbreviations). Note that these values166* do <em>not</em> correspond to the {@link java.util.TimeZone#LONG} and {@link167* java.util.TimeZone#SHORT} values.168*169* @return the relative index value to time zone names array170*/171int zoneNameStyleIndex() {172return zoneNameStyleIndex;173}174}175176177