Top Description Inners Fields Constructors Methods
org.threeten.extra

public final Class AmountFormats

extends Object
Class Inheritance
Imports
java.time.Duration, .Period, java.time.format.DateTimeParseException, java.time.temporal.TemporalAmount, java.util.Arrays, .List, .Locale, .Objects, .Optional, .ResourceBundle, java.util.function.Function, .IntPredicate, java.util.regex.Pattern, java.util.stream.Stream

Provides the ability to format a temporal amount.

This allows a TemporalAmount, such as Duration or Period, to be formatted. Only selected formatting options are provided.

Implementation Requirements:

This class is immutable and thread-safe.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface
pack-priv static class
pack-priv static class
pack-priv static class
pack-priv static class
pack-priv static class
pack-priv static class
pack-priv static interface
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final String
BUNDLE_NAME

The resource bundle name.

private static final int
DAYS_PER_WEEK

The number of days per week.

private static final List<AmountFormats.DurationUnit>
DURATION_UNITS

List of DurationUnit values ordered by longest suffix first.

private static final AmountFormats.FractionScalarPart
EMPTY_FRACTION

Zero value for an absent fractional component of a numeric duration string.

private static final int
HOURS_PER_DAY

The number of hours per day.

private static final int
MINUTES_PER_HOUR

The number of minutes per hour.

private static final int
NANOS_PER_MILLIS

The number of nanosecond per millisecond.

private static final IntPredicate
PREDICATE_1

The predicate that matches 1 or -1.

private static final IntPredicate
PREDICATE_END1_NOT11

The predicate that matches numbers ending 1 but not ending 11.

private static final IntPredicate
PREDICATE_END234_NOTTEENS

The predicate that matches numbers ending 2, 3 or 4, but not ending 12, 13 or 14.

private static final int
SECONDS_PER_MINUTE

The number of seconds per minute.

private static final Pattern
SPLITTER

The pattern to split lists with.

private static final String
WORDBASED_COMMASPACE

The property file key for the separator ", ".

private static final String
WORDBASED_DAY

The property file key for the word "day".

private static final String
WORDBASED_HOUR

The property file key for the word "hour".

private static final String
WORDBASED_MILLISECOND

The property file key for the word "millisecond".

private static final String
WORDBASED_MINUTE

The property file key for the word "minute".

private static final String
WORDBASED_MONTH

The property file key for the word "month".

private static final String
WORDBASED_SECOND

The property file key for the word "second".

private static final String
WORDBASED_SPACEANDSPACE

The property file key for the separator " and ".

private static final String
WORDBASED_WEEK

The property file key for the word "week".

private static final String
WORDBASED_YEAR

The property file key for the word "year".

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static AmountFormats.ParsedUnitPart
private static AmountFormats.ParsedUnitPart
private static Optional<CharSequence>
consumePrefix(CharSequence text, char prefix)

private static Optional<AmountFormats.DurationUnit>
public static String

Returns:

the ISO-8601 format for the period and duration
iso8601
(Period
the period to format
period
,
Duration
the duration to format
duration
)

Formats a period and duration to a string in ISO-8601 format.

private static boolean
oppositeSigns(int a, int b)

public static Duration

Returns:

the Duration value represented by the string, if possible.
parseUnitBasedDuration
(CharSequence
the formatted unit-based duration string.
durationText
)

Parses formatted durations based on units.

public static String

Returns:

the localized word-based format for the period
wordBased
(Period
the period to format
period
,
Locale
the locale to use
locale
)

Formats a period to a string in a localized word-based format.

public static String

Returns:

the localized word-based format for the duration
wordBased
(Duration
the duration to format
duration
,
Locale
the locale to use
locale
)

Formats a duration to a string in a localized word-based format.

public static String

Returns:

the localized word-based format for the period and duration
wordBased
(Period
the period to format
period
,
Duration
the duration to format
duration
,
Locale
the locale to use
locale
)

Formats a period and duration to a string in a localized word-based format.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BUNDLE_NAMEback to summary
private static final String BUNDLE_NAME

The resource bundle name.

DAYS_PER_WEEKback to summary
private static final int DAYS_PER_WEEK

The number of days per week.

DURATION_UNITSback to summary
private static final List<AmountFormats.DurationUnit> DURATION_UNITS

List of DurationUnit values ordered by longest suffix first.

EMPTY_FRACTIONback to summary
private static final AmountFormats.FractionScalarPart EMPTY_FRACTION

Zero value for an absent fractional component of a numeric duration string.

HOURS_PER_DAYback to summary
private static final int HOURS_PER_DAY

The number of hours per day.

MINUTES_PER_HOURback to summary
private static final int MINUTES_PER_HOUR

The number of minutes per hour.

NANOS_PER_MILLISback to summary
private static final int NANOS_PER_MILLIS

The number of nanosecond per millisecond.

PREDICATE_1back to summary
private static final IntPredicate PREDICATE_1

The predicate that matches 1 or -1.

PREDICATE_END1_NOT11back to summary
private static final IntPredicate PREDICATE_END1_NOT11

The predicate that matches numbers ending 1 but not ending 11.

PREDICATE_END234_NOTTEENSback to summary
private static final IntPredicate PREDICATE_END234_NOTTEENS

The predicate that matches numbers ending 2, 3 or 4, but not ending 12, 13 or 14.

SECONDS_PER_MINUTEback to summary
private static final int SECONDS_PER_MINUTE

The number of seconds per minute.

SPLITTERback to summary
private static final Pattern SPLITTER

The pattern to split lists with.

WORDBASED_COMMASPACEback to summary
private static final String WORDBASED_COMMASPACE

The property file key for the separator ", ".

WORDBASED_DAYback to summary
private static final String WORDBASED_DAY

The property file key for the word "day".

WORDBASED_HOURback to summary
private static final String WORDBASED_HOUR

The property file key for the word "hour".

WORDBASED_MILLISECONDback to summary
private static final String WORDBASED_MILLISECOND

The property file key for the word "millisecond".

WORDBASED_MINUTEback to summary
private static final String WORDBASED_MINUTE

The property file key for the word "minute".

WORDBASED_MONTHback to summary
private static final String WORDBASED_MONTH

The property file key for the word "month".

WORDBASED_SECONDback to summary
private static final String WORDBASED_SECOND

The property file key for the word "second".

WORDBASED_SPACEANDSPACEback to summary
private static final String WORDBASED_SPACEANDSPACE

The property file key for the separator " and ".

WORDBASED_WEEKback to summary
private static final String WORDBASED_WEEK

The property file key for the word "week".

WORDBASED_YEARback to summary
private static final String WORDBASED_YEAR

The property file key for the word "year".

Constructor Detail

AmountFormatsback to summary
private AmountFormats()

Method Detail

consumeDurationFractionback to summary
private static AmountFormats.ParsedUnitPart consumeDurationFraction(CharSequence text, CharSequence original, int offset)
consumeDurationLeadingIntback to summary
private static AmountFormats.ParsedUnitPart consumeDurationLeadingInt(CharSequence text, CharSequence original, int offset)
consumePrefixback to summary
private static Optional<CharSequence> consumePrefix(CharSequence text, char prefix)
findUnitback to summary
private static Optional<AmountFormats.DurationUnit> findUnit(CharSequence text)
iso8601back to summary
public static String iso8601(Period period, Duration duration)

Formats a period and duration to a string in ISO-8601 format.

To obtain the ISO-8601 format of a Period or Duration individually, simply call toString(). See also PeriodDuration.

Parameters
period:Period

the period to format

duration:Duration

the duration to format

Returns:String

the ISO-8601 format for the period and duration

oppositeSignsback to summary
private static boolean oppositeSigns(int a, int b)
parseUnitBasedDurationback to summary
public static Duration parseUnitBasedDuration(CharSequence durationText)

Parses formatted durations based on units.

The behaviour matches the Golang duration parser, however, infinite durations are not supported.

The duration format is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".

Note, the value "0" is specially supported as Duration.ZERO.

Parameters
durationText:CharSequence

the formatted unit-based duration string.

Returns:Duration

the Duration value represented by the string, if possible.

wordBasedback to summary
public static String wordBased(Period period, Locale locale)

Formats a period to a string in a localized word-based format.

This returns a word-based format for the period. The year and month are printed as supplied unless the signs differ, in which case they are normalized. The words are configured in a resource bundle text file - org.threeten.extra.wordbased.properties - with overrides per language.

Parameters
period:Period

the period to format

locale:Locale

the locale to use

Returns:String

the localized word-based format for the period

wordBasedback to summary
public static String wordBased(Duration duration, Locale locale)

Formats a duration to a string in a localized word-based format.

This returns a word-based format for the duration. The words are configured in a resource bundle text file - org.threeten.extra.wordbased.properties - with overrides per language.

Parameters
duration:Duration

the duration to format

locale:Locale

the locale to use

Returns:String

the localized word-based format for the duration

wordBasedback to summary
public static String wordBased(Period period, Duration duration, Locale locale)

Formats a period and duration to a string in a localized word-based format.

This returns a word-based format for the period. The year and month are printed as supplied unless the signs differ, in which case they are normalized. The words are configured in a resource bundle text file - org.threeten.extra.wordbased.properties - with overrides per language.

Parameters
period:Period

the period to format

duration:Duration

the duration to format

locale:Locale

the locale to use

Returns:String

the localized word-based format for the period and duration

org.threeten.extra back to summary

pack-priv Interface AmountFormats.DurationScalar

Known Direct Implementers
org.threeten.extra.AmountFormats.ParsedUnitPart, org.threeten.extra.AmountFormats.IntegerScalarPart, org.threeten.extra.AmountFormats.FractionScalarPart

Method Summary

Modifier and TypeMethod and Description
public Duration

Method Detail

applyToback to summary
public Duration applyTo(AmountFormats.DurationUnit unit)
org.threeten.extra back to summary

pack-priv final Class AmountFormats.DurationUnit

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final String
private final Duration

Constructor Summary

AccessConstructor and Description
private
DurationUnit(String abbrev, Duration value)

Method Summary

Modifier and TypeMethod and Description
pack-priv CharSequence
pack-priv boolean
pack-priv Duration
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

abbrevback to summary
private final String abbrev
valueback to summary
private final Duration value

Constructor Detail

DurationUnitback to summary
private DurationUnit(String abbrev, Duration value)

Method Detail

consumeDurationUnitback to summary
pack-priv CharSequence consumeDurationUnit(CharSequence text)
prefixMatchesUnitback to summary
pack-priv boolean prefixMatchesUnit(CharSequence text)
scaleByback to summary
pack-priv Duration scaleBy(Function<Duration, Duration> scaleFunc)
org.threeten.extra back to summary

pack-priv final Class AmountFormats.FractionScalarPart

extends Object
implements DurationScalar
Class Inheritance
All Implemented Interfaces
org.threeten.extra.AmountFormats.DurationScalar

Field Summary

Modifier and TypeField and Description
private final long
private final long

Constructor Summary

AccessConstructor and Description
private
FractionScalarPart(long value, long scale)

Method Summary

Modifier and TypeMethod and Description
public Duration
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

scaleback to summary
private final long scale
valueback to summary
private final long value

Constructor Detail

FractionScalarPartback to summary
private FractionScalarPart(long value, long scale)

Method Detail

applyToback to summary
public Duration applyTo(AmountFormats.DurationUnit unit)

Implements org.threeten.extra.AmountFormats.DurationScalar.applyTo.

Annotations
@Override
org.threeten.extra back to summary

pack-priv final Class AmountFormats.IntegerScalarPart

extends Object
implements DurationScalar
Class Inheritance
All Implemented Interfaces
org.threeten.extra.AmountFormats.DurationScalar

Field Summary

Modifier and TypeField and Description
private final long

Constructor Summary

AccessConstructor and Description
private
IntegerScalarPart(long value)

Method Summary

Modifier and TypeMethod and Description
public Duration
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

valueback to summary
private final long value

Constructor Detail

IntegerScalarPartback to summary
private IntegerScalarPart(long value)

Method Detail

applyToback to summary
public Duration applyTo(AmountFormats.DurationUnit unit)

Implements org.threeten.extra.AmountFormats.DurationScalar.applyTo.

Annotations
@Override
org.threeten.extra back to summary

pack-priv final Class AmountFormats.ParsedUnitPart

extends Object
implements DurationScalar
Class Inheritance
All Implemented Interfaces
org.threeten.extra.AmountFormats.DurationScalar

Field Summary

Modifier and TypeField and Description
private final CharSequence
private final AmountFormats.DurationScalar

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Duration
pack-priv CharSequence
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

remainingTextback to summary
private final CharSequence remainingText
scalarback to summary
private final AmountFormats.DurationScalar scalar

Constructor Detail

ParsedUnitPartback to summary
private ParsedUnitPart(CharSequence remainingText, AmountFormats.DurationScalar scalar)

Method Detail

applyToback to summary
public Duration applyTo(AmountFormats.DurationUnit unit)

Implements org.threeten.extra.AmountFormats.DurationScalar.applyTo.

Annotations
@Override
remainingTextback to summary
pack-priv CharSequence remainingText()
org.threeten.extra back to summary

pack-priv final Class AmountFormats.PredicateFormat

extends Object
implements UnitFormat
Class Inheritance
All Implemented Interfaces
org.threeten.extra.AmountFormats.UnitFormat

Field Summary

Modifier and TypeField and Description
private final IntPredicate[]
private final String[]

Constructor Summary

AccessConstructor and Description
pack-priv
PredicateFormat(String[] predicateStrs, String[] text)

Method Summary

Modifier and TypeMethod and Description
private IntPredicate
findPredicate(String predicateStr)

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

predicatesback to summary
private final IntPredicate[] predicates
textback to summary
private final String[] text

Constructor Detail

PredicateFormatback to summary
pack-priv PredicateFormat(String[] predicateStrs, String[] text)

Method Detail

findPredicateback to summary
private IntPredicate findPredicate(String predicateStr)
formatToback to summary
public void formatTo(int value, StringBuilder buf)

Implements org.threeten.extra.AmountFormats.UnitFormat.formatTo.

Annotations
@Override
org.threeten.extra back to summary

pack-priv final Class AmountFormats.SinglePluralFormat

extends Object
implements UnitFormat
Class Inheritance
All Implemented Interfaces
org.threeten.extra.AmountFormats.UnitFormat

Field Summary

Modifier and TypeField and Description
private final String
private final String

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

pluralback to summary
private final String plural
singleback to summary
private final String single

Constructor Detail

SinglePluralFormatback to summary
pack-priv SinglePluralFormat(String single, String plural)

Method Detail

formatToback to summary
public void formatTo(int value, StringBuilder buf)

Implements org.threeten.extra.AmountFormats.UnitFormat.formatTo.

Annotations
@Override
org.threeten.extra back to summary

pack-priv Interface AmountFormats.UnitFormat

Known Direct Implementers
org.threeten.extra.AmountFormats.SinglePluralFormat, org.threeten.extra.AmountFormats.PredicateFormat

Method Summary

Modifier and TypeMethod and Description
public void
formatTo(int value, StringBuilder buf)

public static AmountFormats.UnitFormat
of(ResourceBundle bundle, String keyStem)

Method Detail

formatToback to summary
public void formatTo(int value, StringBuilder buf)
ofback to summary
public static AmountFormats.UnitFormat of(ResourceBundle bundle, String keyStem)
org.threeten.extra back to summary

pack-priv final Class AmountFormats.WordBased

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final String
private final String
private final AmountFormats.UnitFormat[]

Constructor Summary

AccessConstructor and Description
public
WordBased(AmountFormats.UnitFormat[] units, String separator, String lastSeparator)

Method Summary

Modifier and TypeMethod and Description
pack-priv String
format(int[] values)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

lastSeparatorback to summary
private final String lastSeparator
separatorback to summary
private final String separator
unitsback to summary
private final AmountFormats.UnitFormat[] units

Constructor Detail

WordBasedback to summary
public WordBased(AmountFormats.UnitFormat[] units, String separator, String lastSeparator)

Method Detail

formatback to summary
pack-priv String format(int[] values)