Package com.ibm.icu.impl.duration
Class BasicPeriodBuilderFactory
- java.lang.Object
-
- com.ibm.icu.impl.duration.BasicPeriodBuilderFactory
-
- All Implemented Interfaces:
PeriodBuilderFactory
class BasicPeriodBuilderFactory extends java.lang.Object implements PeriodBuilderFactory
Default implementation of PeriodBuilderFactory. This creates builders that use approximate durations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
BasicPeriodBuilderFactory.Settings
-
Field Summary
Fields Modifier and Type Field Description private static short
allBits
private PeriodFormatterDataService
ds
private BasicPeriodBuilderFactory.Settings
settings
-
Constructor Summary
Constructors Constructor Description BasicPeriodBuilderFactory(PeriodFormatterDataService ds)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static long
approximateDurationOf(TimeUnit unit)
PeriodBuilder
getFixedUnitBuilder(TimeUnit unit)
Return a builder that represents relative time in terms of the single given TimeUnitPeriodBuilder
getMultiUnitBuilder(int periodCount)
Return a builder that formats the given number of periods, starting with the largest period less than or equal to the duration.PeriodBuilder
getOneOrTwoUnitBuilder()
Return a builder that formats the largest one or two periods, Starting with the largest period less than or equal to the duration.private BasicPeriodBuilderFactory.Settings
getSettings()
PeriodBuilder
getSingleUnitBuilder()
Return a builder that represents relative time in terms of the largest period less than or equal to the duration.PeriodBuilderFactory
setAllowMilliseconds(boolean allow)
Sets whether milliseconds are allowed.PeriodBuilderFactory
setAllowZero(boolean allow)
Sets whether units with a value of zero are represented in a period when 'gaps' appear between time units, e.g.PeriodBuilderFactory
setAvailableUnitRange(TimeUnit minUnit, TimeUnit maxUnit)
Sets the time units available for use.PeriodBuilderFactory
setLocale(java.lang.String localeName)
Sets the locale for the factory.PeriodBuilderFactory
setMaxLimit(float maxLimit)
Sets the maximum value for the largest available time unit (as set in setUnits).PeriodBuilderFactory
setMinLimit(float minLimit)
Sets the minimum value for the smallest available time unit (as set in setUnits).PeriodBuilderFactory
setTimeZone(java.util.TimeZone timeZone)
Sets the time zone for the factory.PeriodBuilderFactory
setUnitIsAvailable(TimeUnit unit, boolean available)
Sets whether the time unit is available for use.PeriodBuilderFactory
setWeeksAloneOnly(boolean aloneOnly)
Sets whether weeks are used with other units, or only when weeks are the only unit.
-
-
-
Field Detail
-
ds
private PeriodFormatterDataService ds
-
settings
private BasicPeriodBuilderFactory.Settings settings
-
allBits
private static final short allBits
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BasicPeriodBuilderFactory
BasicPeriodBuilderFactory(PeriodFormatterDataService ds)
-
-
Method Detail
-
approximateDurationOf
static long approximateDurationOf(TimeUnit unit)
-
setAvailableUnitRange
public PeriodBuilderFactory setAvailableUnitRange(TimeUnit minUnit, TimeUnit maxUnit)
Description copied from interface:PeriodBuilderFactory
Sets the time units available for use. Default is all units.- Specified by:
setAvailableUnitRange
in interfacePeriodBuilderFactory
- Parameters:
minUnit
- the smallest time unit available for usemaxUnit
- the largest time unit available for use- Returns:
- this factory
-
setUnitIsAvailable
public PeriodBuilderFactory setUnitIsAvailable(TimeUnit unit, boolean available)
Description copied from interface:PeriodBuilderFactory
Sets whether the time unit is available for use.- Specified by:
setUnitIsAvailable
in interfacePeriodBuilderFactory
- Parameters:
unit
- the time unitavailable
- true if the unit is available for use- Returns:
- this factory
-
setMaxLimit
public PeriodBuilderFactory setMaxLimit(float maxLimit)
Description copied from interface:PeriodBuilderFactory
Sets the maximum value for the largest available time unit (as set in setUnits). Periods that represent a longer duration than this will be pinned to this value of that time unit and return true for 'isMoreThan'. Default is no limit. Setting a value of zero restores the default.- Specified by:
setMaxLimit
in interfacePeriodBuilderFactory
-
setMinLimit
public PeriodBuilderFactory setMinLimit(float minLimit)
Description copied from interface:PeriodBuilderFactory
Sets the minimum value for the smallest available time unit (as set in setUnits). Periods that represent a shorter duration than this will be pinned to this value of that time unit and return true for 'isLessThan'. Default is no limit. Setting a value of zero restores the default.- Specified by:
setMinLimit
in interfacePeriodBuilderFactory
-
setAllowZero
public PeriodBuilderFactory setAllowZero(boolean allow)
Description copied from interface:PeriodBuilderFactory
Sets whether units with a value of zero are represented in a period when 'gaps' appear between time units, e.g. '2 hours, 0 minutes, and 33 seconds'. Default is to not represent these explicitly ('2 hours and 33 seconds').- Specified by:
setAllowZero
in interfacePeriodBuilderFactory
-
setWeeksAloneOnly
public PeriodBuilderFactory setWeeksAloneOnly(boolean aloneOnly)
Description copied from interface:PeriodBuilderFactory
Sets whether weeks are used with other units, or only when weeks are the only unit. For example '3 weeks and 2 days' versus '23 days'. Default is to use them alone only.- Specified by:
setWeeksAloneOnly
in interfacePeriodBuilderFactory
-
setAllowMilliseconds
public PeriodBuilderFactory setAllowMilliseconds(boolean allow)
Description copied from interface:PeriodBuilderFactory
Sets whether milliseconds are allowed. This is only examined when milliseconds are an available field. The default is to allow milliseconds to display normally.This is intended to be used to set locale-specific behavior. Typically clients will not call this API and instead call
PeriodBuilderFactory.setLocale(java.lang.String)
.- Specified by:
setAllowMilliseconds
in interfacePeriodBuilderFactory
- Parameters:
allow
- whether milliseconds should be allowed.- Returns:
- a builder
-
setLocale
public PeriodBuilderFactory setLocale(java.lang.String localeName)
Description copied from interface:PeriodBuilderFactory
Sets the locale for the factory. Setting the locale can adjust the values for some or all of the other properties to reflect language or cultural conventions. Default is to use the default locale.- Specified by:
setLocale
in interfacePeriodBuilderFactory
-
setTimeZone
public PeriodBuilderFactory setTimeZone(java.util.TimeZone timeZone)
Description copied from interface:PeriodBuilderFactory
Sets the time zone for the factory. This can affect the timezone used for date computations.- Specified by:
setTimeZone
in interfacePeriodBuilderFactory
- Parameters:
timeZone
- the timeZone- Returns:
- a builder
-
getSettings
private BasicPeriodBuilderFactory.Settings getSettings()
-
getFixedUnitBuilder
public PeriodBuilder getFixedUnitBuilder(TimeUnit unit)
Return a builder that represents relative time in terms of the single given TimeUnit- Specified by:
getFixedUnitBuilder
in interfacePeriodBuilderFactory
- Parameters:
unit
- the single TimeUnit with which to represent times- Returns:
- a builder
-
getSingleUnitBuilder
public PeriodBuilder getSingleUnitBuilder()
Return a builder that represents relative time in terms of the largest period less than or equal to the duration.- Specified by:
getSingleUnitBuilder
in interfacePeriodBuilderFactory
- Returns:
- a builder
-
getOneOrTwoUnitBuilder
public PeriodBuilder getOneOrTwoUnitBuilder()
Return a builder that formats the largest one or two periods, Starting with the largest period less than or equal to the duration. It formats two periods if the first period has a count < 2 and the next period has a count >= 1.- Specified by:
getOneOrTwoUnitBuilder
in interfacePeriodBuilderFactory
- Returns:
- a builder
-
getMultiUnitBuilder
public PeriodBuilder getMultiUnitBuilder(int periodCount)
Return a builder that formats the given number of periods, starting with the largest period less than or equal to the duration.- Specified by:
getMultiUnitBuilder
in interfacePeriodBuilderFactory
- Returns:
- a builder
-
-