1 /* 2 * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos 3 * 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * * Redistributions of source code must retain the above copyright notice, 10 * this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright notice, 13 * this list of conditions and the following disclaimer in the documentation 14 * and/or other materials provided with the distribution. 15 * 16 * * Neither the name of JSR-310 nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 package org.threeten.bp.format; 33 34 /** 35 * Enumeration of the style of text formatting and parsing. 36 * <p> 37 * Text styles define three sizes for the formatted text - 'full', 'short' and 'narrow'. 38 * Each of these three sizes is available in both 'standard' and 'stand-alone' variations. 39 * <p> 40 * The difference between the three sizes is obvious in most languages. 41 * For example, in English the 'full' month is 'January', the 'short' month is 'Jan' 42 * and the 'narrow' month is 'J'. Note that the narrow size is often not unique. 43 * For example, 'January', 'June' and 'July' all have the 'narrow' text 'J'. 44 * <p> 45 * The difference between the 'standard' and 'stand-alone' forms is trickier to describe 46 * as there is no difference in English. However, in other languages there is a difference 47 * in the word used when the text is used alone, as opposed to in a complete date. 48 * For example, the word used for a month when used alone in a date picker is different 49 * to the word used for month in association with a day and year in a date. 50 * 51 * <h3>Specification for implementors</h3> 52 * This is immutable and thread-safe enum. 53 */ 54 public enum TextStyle { 55 // ordered from large to small 56 57 /** 58 * Full text, typically the full description. 59 * For example, day-of-week Monday might output "Monday". 60 */ 61 FULL, 62 /** 63 * Full text for stand-alone use, typically the full description. 64 * For example, day-of-week Monday might output "Monday". 65 */ 66 FULL_STANDALONE, 67 /** 68 * Short text, typically an abbreviation. 69 * For example, day-of-week Monday might output "Mon". 70 */ 71 SHORT, 72 /** 73 * Short text for stand-alone use, typically an abbreviation. 74 * For example, day-of-week Monday might output "Mon". 75 */ 76 SHORT_STANDALONE, 77 /** 78 * Narrow text, typically a single letter. 79 * For example, day-of-week Monday might output "M". 80 */ 81 NARROW, 82 /** 83 * Narrow text for stand-alone use, typically a single letter. 84 * For example, day-of-week Monday might output "M". 85 */ 86 NARROW_STANDALONE; 87 88 /** 89 * Checks if the style is stand-alone. 90 * 91 * @return true if the style is stand-alone 92 */ isStandalone()93 public boolean isStandalone() { 94 return (ordinal() & 1) == 1; 95 } 96 97 /** 98 * Converts the style to the equivalent stand-alone style. 99 * 100 * @return the matching stand-alone style 101 */ asStandalone()102 public TextStyle asStandalone() { 103 return TextStyle.values()[ordinal() | 1]; 104 } 105 106 /** 107 * Converts the style to the equivalent normal style. 108 * 109 * @return the matching normal style 110 */ asNormal()111 public TextStyle asNormal() { 112 return TextStyle.values()[ordinal() & ~1]; 113 } 114 115 } 116