All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.time4j.format.DisplayElement Maven / Gradle / Ivy

There is a newer version: 4.38
Show newest version
/*
 * -----------------------------------------------------------------------
 * Copyright © 2013-2016 Meno Hochschild, 
 * -----------------------------------------------------------------------
 * This file (DisplayElement.java) is part of project Time4J.
 *
 * Time4J is free software: You can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * Time4J is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Time4J. If not, see .
 * -----------------------------------------------------------------------
 */

package net.time4j.format;

import net.time4j.engine.BasicElement;

import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;


/**
 * 

Standard element which offers localized names for display purposes (in most cases).

* *

The implementation looks up the CLDR format symbol of the element and then associate it * with the suitable i18n-resources. Supported symbols are: G (era), u/y/Y (year), Q (quarter), * M (month), d (day-of-month), E (weekday), h/H/k/K (hour), m (minute), s (second).

* * @author Meno Hochschild * @since 3.22/4.18 */ /*[deutsch] *

Standardelement, das lokalisierte Anzeigenamen bietet (in den meisten Fällen).

* *

Die Implementierung greift auf das CLDR-Formatsymbol des Elements zu und assoziiert es * mit den geeigneten i18n-Ressourcen. Unterstützte Symbole sind: G (Ära), u/y/Y (Jahr), * Q (Quartal), M (Monat), d (Monatstag), E (Wochentag), h/H/k/K (Stunde), m (Minute), s (Sekunde).

* * @author Meno Hochschild * @since 3.22/4.18 */ public abstract class DisplayElement> extends BasicElement { //~ Statische Felder/Initialisierungen -------------------------------- private static final Map OTHER_DISPLAY_KEYS; static { Map map = new HashMap<>(); map.put("YEAR_OF_DISPLAY", "L_year"); map.put("MONTH_AS_NUMBER", "L_month"); map.put("ISO_HOUR", "L_hour"); OTHER_DISPLAY_KEYS = Collections.unmodifiableMap(map); } //~ Konstruktoren ----------------------------------------------------- /** *

Called by subclasses which will usually assign an instance to * a static constant (creating a singleton).

* * @param name name of element * @throws IllegalArgumentException if the name is empty or only * contains white space (spaces, tabs etc.) */ /*[deutsch] *

Konstruktor für Subklassen, die eine so erzeugte Instanz * in der Regel statischen Konstanten zuweisen und damit Singletons * erzeugen können.

* * @param name name of element * @throws IllegalArgumentException if the name is empty or only * contains white space (spaces, tabs etc.) */ protected DisplayElement(String name) { super(name); } //~ Methoden ---------------------------------------------------------- @Override public String getDisplayName(Locale language) { String key; switch (this.getSymbol()) { case 'G': key = "L_era"; break; case 'u': case 'y': case 'Y': key = "L_year"; break; case 'Q': key = "L_quarter"; break; case 'M': key = "L_month"; break; case 'w': case 'W': key = "L_week"; break; case 'd': key = "L_day"; break; case 'E': case 'e': key = "L_weekday"; break; case 'H': case 'h': case 'K': case 'k': key = "L_hour"; break; case 'm': key = "L_minute"; break; case 's': key = "L_second"; break; default: String n = this.name(); key = OTHER_DISPLAY_KEYS.get(n); if (key == null) { return n; } } String lname = CalendarText.getIsoInstance(language).getTextForms().get(key); return ((lname == null) ? this.name() : lname); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy