예제 #1
0
  private static String[] lookupBundle(
      ResourceBundle rb,
      int len,
      String elementName,
      TextWidth tw,
      OutputContext oc,
      int baseIndex) {

    String[] names = new String[len];
    boolean shortKey = (elementName.length() == 1);

    for (int i = 0; i < len; i++) {
      StringBuilder b = new StringBuilder();
      b.append(elementName);
      b.append('(');

      if (shortKey) {
        char c = tw.name().charAt(0);

        if (oc != OutputContext.STANDALONE) {
          c = Character.toLowerCase(c);
        }

        b.append(c);
      } else {
        b.append(tw.name());

        if (oc == OutputContext.STANDALONE) {
          b.append('|');
          b.append(oc.name());
        }
      }

      b.append(')');
      b.append('_');
      b.append(i + baseIndex);
      String key = b.toString();

      if (rb.containsKey(key)) {
        names[i] = rb.getString(key);
      } else {
        return null;
      }
    }

    return names;
  }
예제 #2
0
  private static String meridiemKey(String meridiem, TextWidth tw, OutputContext oc) {

    char c = tw.name().charAt(0);

    if (oc == OutputContext.FORMAT) {
      c = Character.toLowerCase(c);
    }

    return "P(" + String.valueOf(c) + ")_" + meridiem;
  }
예제 #3
0
    private static String getEnglishPattern(
        String wide, String abbr, String narrow, TextWidth width, PluralCategory category) {

      switch (width) {
        case WIDE:
          return getPluralPattern(wide, category);
        case ABBREVIATED:
        case SHORT:
          return getPluralPattern(abbr, category);
        case NARROW:
          return "{0}" + narrow;
        default:
          throw new UnsupportedOperationException(width.name());
      }
    }
예제 #4
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;
  }