예제 #1
0
  private static char getID(IsoUnit unit) {

    char unitID = unit.getSymbol();

    if (unit == ClockUnit.MINUTES) {
      return 'N';
    }

    return unitID;
  }
예제 #2
0
  private UnitPatterns(Locale language) {
    super();

    this.locale = language;

    Map<IsoUnit, Map<TextWidth, Map<PluralCategory, String>>> map = new HashMap<>(10);
    Map<IsoUnit, Map<PluralCategory, String>> mapPast = new HashMap<>(10);
    Map<IsoUnit, Map<PluralCategory, String>> mapFuture = new HashMap<>(10);
    Map<Integer, Map<TextWidth, String>> mapList = new HashMap<>(10);
    Map<IsoUnit, Map<PluralCategory, String>> mapShortPast = new HashMap<>(10);
    Map<IsoUnit, Map<PluralCategory, String>> mapShortFuture = new HashMap<>(10);

    for (IsoUnit unit : UNIT_IDS) {
      // Standard-Muster
      Map<TextWidth, Map<PluralCategory, String>> tmp1 = new EnumMap<>(TextWidth.class);
      for (TextWidth width : TextWidth.values()) {
        Map<PluralCategory, String> tmp2 = new EnumMap<>(PluralCategory.class);
        for (PluralCategory cat : PluralCategory.values()) {
          tmp2.put(cat, lookup(language, unit, width, cat));
        }
        tmp1.put(width, Collections.unmodifiableMap(tmp2));
      }
      map.put(unit, Collections.unmodifiableMap(tmp1));

      if (!Character.isDigit(unit.getSymbol())) { // no subseconds
        // Vergangenheit
        Map<PluralCategory, String> tmp3 = new EnumMap<>(PluralCategory.class);
        for (PluralCategory cat : PluralCategory.values()) {
          tmp3.put(cat, lookup(language, unit, false, false, cat));
        }
        mapPast.put(unit, Collections.unmodifiableMap(tmp3));
        Map<PluralCategory, String> tmp3a = new EnumMap<>(PluralCategory.class);
        for (PluralCategory cat : PluralCategory.values()) {
          tmp3a.put(cat, lookup(language, unit, false, true, cat));
        }
        mapShortPast.put(unit, Collections.unmodifiableMap(tmp3a));

        // Zukunft
        Map<PluralCategory, String> tmp4 = new EnumMap<>(PluralCategory.class);
        for (PluralCategory cat : PluralCategory.values()) {
          tmp4.put(cat, lookup(language, unit, true, false, cat));
        }
        mapFuture.put(unit, Collections.unmodifiableMap(tmp4));
        Map<PluralCategory, String> tmp4a = new EnumMap<>(PluralCategory.class);
        for (PluralCategory cat : PluralCategory.values()) {
          tmp4a.put(cat, lookup(language, unit, true, true, cat));
        }
        mapShortFuture.put(unit, Collections.unmodifiableMap(tmp4a));
      }
    }

    // Liste
    for (int i = MIN_LIST_INDEX; i <= MAX_LIST_INDEX; i++) {
      Integer index = Integer.valueOf(i);
      Map<TextWidth, String> tmp5 = new EnumMap<>(TextWidth.class);
      for (TextWidth width : TextWidth.values()) {
        tmp5.put(width, lookup(language, width, index));
      }
      mapList.put(index, Collections.unmodifiableMap(tmp5));
    }

    this.patterns = Collections.unmodifiableMap(map);
    this.past = Collections.unmodifiableMap(mapPast);
    this.future = Collections.unmodifiableMap(mapFuture);
    this.shortPast = Collections.unmodifiableMap(mapShortPast);
    this.shortFuture = Collections.unmodifiableMap(mapShortFuture);
    this.list = Collections.unmodifiableMap(mapList);

    String n;

    String y = "";
    String t1 = "";
    String t2 = "";

    try {
      n = PROVIDER.getNowWord(language);

      if (PROVIDER instanceof RelativeTimeProvider) {
        RelativeTimeProvider rp = RelativeTimeProvider.class.cast(PROVIDER);
        y = rp.getYesterdayWord(language);
        t1 = rp.getTodayWord(language);
        t2 = rp.getTomorrowWord(language);
      }
    } catch (MissingResourceException mre) {
      n = FALLBACK.getNowWord(language); // should not happen
    }

    this.now = n;
    this.yesterday = y;
    this.today = t1;
    this.tomorrow = t2;
  }