TimeDomainFactory is an interface for defining and retrieving {@link TimeDomain} objects. A time domain factory ensures that there is onlyone domain for a given set of properties. A factory can provide built-in domains guaranteed to be available whenever the factory is present. They are created when the factory class is loaded. The labels of such domains can be used as external identifiers.
There are ways to access a given time domain which are more direct than retrieving it from the factory, but in the end the domain is still one managed by the factory. The following example code shows 4 different ways to get the same domain object, in this case the daily domain implemented by {@link Day}:
TimeDomainFactory fac = TimeDomainManager.getFactory(); TimeDomain d1 = new Day("0102-03-04").getTimeDomain(); TimeDomain d2 = Day.DOMAIN; TimeDomain d3 = fac.get("daily"); TimeDomain d4 = fac.get(new TimeDomainDefinition(null, Resolution.DAY, 0L)); assertSame(d1, d2); assertSame(d1, d3); assertSame(d1, d4);
TimeDomainFactory was designed under the following assumptions:
- A time domain factory is implemented as a singleton, return by the static method
getInstance()
. - The reason to have different factories is to provide different sets of built-in domains to applications.
- A Time2 application uses a single factory. The factory is accessed via the {@link TimeDomainManager}.
See the class comment in {@link AbstractTimeDomainFactory} for an example of a concretefactory.
It is possible to bypass the factory mechanism, but this requires using non-public methods.
@author Jean-Paul Vetterli
@see TimeDomainDefinition
@see DefaultTimeDomainFactory