示例#1
0
  private static String lookup(
      UnitPatternProvider p,
      Locale language,
      char unitID,
      TextWidth width,
      PluralCategory category) {

    switch (unitID) {
      case 'Y':
        return p.getYearPattern(language, width, category);
      case 'M':
        return p.getMonthPattern(language, width, category);
      case 'W':
        return p.getWeekPattern(language, width, category);
      case 'D':
        return p.getDayPattern(language, width, category);
      case 'H':
        return p.getHourPattern(language, width, category);
      case 'N':
        return p.getMinutePattern(language, width, category);
      case 'S':
        return p.getSecondPattern(language, width, category);
      case '3':
        return p.getMilliPattern(language, width, category);
      case '6':
        return p.getMicroPattern(language, width, category);
      case '9':
        return p.getNanoPattern(language, width, category);
      default:
        throw new UnsupportedOperationException("Unit-ID: " + unitID);
    }
  }
示例#2
0
  private static String lookup(Locale language, TextWidth width, int size) {

    try {
      return PROVIDER.getListPattern(language, width, size);
    } catch (MissingResourceException mre) { // should not happen
      return FALLBACK.getListPattern(language, width, size);
    }
  }
示例#3
0
  private static String lookup(
      UnitPatternProvider p,
      Locale language,
      char unitID,
      boolean future,
      boolean abbreviated,
      PluralCategory category) {

    if (abbreviated && (p instanceof RelativeTimeProvider)) {
      RelativeTimeProvider rp = RelativeTimeProvider.class.cast(p);
      switch (unitID) {
        case 'Y':
          return rp.getShortYearPattern(language, future, category);
        case 'M':
          return rp.getShortMonthPattern(language, future, category);
        case 'W':
          return rp.getShortWeekPattern(language, future, category);
        case 'D':
          return rp.getShortDayPattern(language, future, category);
        case 'H':
          return rp.getShortHourPattern(language, future, category);
        case 'N':
          return rp.getShortMinutePattern(language, future, category);
        case 'S':
          return rp.getShortSecondPattern(language, future, category);
        default:
          throw new UnsupportedOperationException("Unit-ID: " + unitID);
      }
    }

    switch (unitID) {
      case 'Y':
        return p.getYearPattern(language, future, category);
      case 'M':
        return p.getMonthPattern(language, future, category);
      case 'W':
        return p.getWeekPattern(language, future, category);
      case 'D':
        return p.getDayPattern(language, future, category);
      case 'H':
        return p.getHourPattern(language, future, category);
      case 'N':
        return p.getMinutePattern(language, future, category);
      case 'S':
        return p.getSecondPattern(language, future, category);
      default:
        throw new UnsupportedOperationException("Unit-ID: " + unitID);
    }
  }
示例#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;
  }