/** * <p>Factory method as constructor replacement. </p> * * @param lang language setting * @return chached instance */ static UnitPatterns of(Locale lang) { if (lang == null) { throw new NullPointerException("Missing language."); } UnitPatterns p = CACHE.get(lang); if (p == null) { p = new UnitPatterns(lang); UnitPatterns old = CACHE.putIfAbsent(lang, p); if (old != null) { p = old; } } return p; }
private static void checkNull( TextWidth width, PluralCategory category ) { if (width == null) { throw new NullPointerException("Missing text width."); } checkNull(category); }
private String getEmptyRelativeString(TimeUnit precision) { UnitPatterns patterns = UnitPatterns.of(this.locale); if (precision.equals(TimeUnit.DAYS)) { String replacement = patterns.getTodayWord(); if (!replacement.isEmpty()) { return replacement; } } return patterns.getNowWord(); }
private String getFuturePattern( long amount, CalendarUnit unit ) { UnitPatterns patterns = UnitPatterns.of(this.locale); PluralCategory category = this.getCategory(amount); return patterns.getPatternInFuture(category, this.shortStyle, unit); }
private String getPastPattern( long amount, CalendarUnit unit ) { UnitPatterns patterns = UnitPatterns.of(this.locale); PluralCategory category = this.getCategory(amount); return patterns.getPatternInPast(category, this.shortStyle, unit); }
&& unit.equals(CalendarUnit.DAYS) ) { UnitPatterns patterns = UnitPatterns.of(this.locale); String replacement = (duration.isNegative() ? patterns.getYesterdayWord() : patterns.getTomorrowWord());
/** * <p>Formats given duration in clock units. </p> * * @param amount count of units (quantity) * @param unit clock unit * @param width text width (ABBREVIATED as synonym for SHORT) * @return formatted output * @since 1.2 * @see #print(Duration, TextWidth) */ /*[deutsch] * <p>Formatiert die angegebene Dauer in Uhrzeiteinheiten. </p> * * @param amount Anzahl der Einheiten * @param unit Uhrzeiteinheit * @param width text width (ABBREVIATED as synonym for SHORT) * @return formatierte Ausgabe * @since 1.2 * @see #print(Duration, TextWidth) */ public String print( long amount, ClockUnit unit, TextWidth width ) { String pattern = UnitPatterns.of(this.locale).getPattern(width, this.getCategory(amount), unit); return this.format(pattern, amount); }
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:
/** * <p>Determines the localized word for "today". </p> * * @return String * @since 3.24/4.20 */ /*[deutsch] * <p>Ermittelt das lokalisierte Wort für "heute". </p> * * @return String * @since 3.24/4.20 */ public String printToday() { return UnitPatterns.of(this.getLocale()).getTodayWord(); }
/** * <p>Determines the localized word for "tomorrow". </p> * * @return String * @since 3.43/4.38 */ /*[deutsch] * <p>Ermittelt das lokalisierte Wort für "morgen". </p> * * @return String * @since 3.43/4.38 */ public String printTomorrow() { return UnitPatterns.of(this.getLocale()).getTomorrowWord(); }
private String printRelativeSeconds( Moment t1, Moment t2, long delta ) { if (t1.getPosixTime() >= START_1972 && t2.getPosixTime() >= START_1972) { delta = SI.SECONDS.between(t1, t2); // leap second correction } if (delta == 0) { return UnitPatterns.of(this.locale).getNowWord(); } long amount = Math.abs(delta); String pattern = ( (delta < 0) ? this.getPastPattern(amount, ClockUnit.SECONDS) : this.getFuturePattern(amount, ClockUnit.SECONDS)); return this.format(pattern, amount); }
UnitPatterns.of(this.locale).getListPattern(width, count), parts.toArray(new Object[count]));
&& unit.equals(CalendarUnit.DAYS) ) { UnitPatterns patterns = UnitPatterns.of(this.locale); String replacement = (duration.isNegative() ? patterns.getYesterdayWord() : patterns.getTomorrowWord());
private String getFuturePattern( long amount, ClockUnit unit ) { UnitPatterns patterns = UnitPatterns.of(this.locale); PluralCategory category = this.getCategory(amount); return patterns.getPatternInFuture(category, this.shortStyle, unit); }
private String getPastPattern( long amount, ClockUnit unit ) { UnitPatterns patterns = UnitPatterns.of(this.locale); PluralCategory category = this.getCategory(amount); return patterns.getPatternInPast(category, this.shortStyle, unit); }
) { UnitPatterns p = UnitPatterns.of(this.locale); CalendarUnit u; String pattern = p.getPattern(width, this.getCategory(amount), u); return this.format(pattern, amount);
/** * <p>Yields a unit pattern which optionally contains a placeholder * of the form "{0}" standing for the count of units. </p> * * @param width text width (ABBREVIATED as synonym for SHORT) * @param category plural category * @param unit associated iso unit * @return unit pattern */ String getPattern( TextWidth width, PluralCategory category, IsoUnit unit ) { checkNull(width, category); return this.patterns.get(unit).get(width).get(category); }
/** * <p>Yields a unit pattern which optionally contains a placeholder * of the form "{0}" standing for the count of units in the * past. </p> * * @param category plural category * @param abbreviated using short form or not * @param unit associated iso unit * @return unit pattern in the past * @since 3.6/4.4 */ String getPatternInPast( PluralCategory category, boolean abbreviated, IsoUnit unit ) { checkNull(category); if (abbreviated) { return this.shortPast.get(unit).get(category); } else { return this.past.get(unit).get(category); } }
/** * <p>Yields a unit pattern which optionally contains a placeholder * of the form "{0}" standing for the count of units in the * future. </p> * * @param category plural category * @param abbreviated using short form or not * @param unit associated iso unit * @return unit pattern in the future * @since 3.6/4.4 */ String getPatternInFuture( PluralCategory category, boolean abbreviated, IsoUnit unit ) { checkNull(category); if (abbreviated) { return this.shortFuture.get(unit).get(category); } else { return this.future.get(unit).get(category); } }