1 // © 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html#License 3 /* 4 ****************************************************************************** 5 * Copyright (C) 2007-2010, International Business Machines Corporation and * 6 * others. All Rights Reserved. * 7 ****************************************************************************** 8 */ 9 10 package com.ibm.icu.impl.duration; 11 12 import java.util.Collection; 13 14 import com.ibm.icu.impl.duration.impl.PeriodFormatterDataService; 15 import com.ibm.icu.impl.duration.impl.ResourceBasedPeriodFormatterDataService; 16 17 /** 18 * An implementation of PeriodFormatterService that constructs a 19 * BasicPeriodFormatterFactory. 20 */ 21 public class BasicPeriodFormatterService implements PeriodFormatterService { 22 private static BasicPeriodFormatterService instance; 23 private PeriodFormatterDataService ds; 24 25 /** 26 * Return the default service instance. This uses the default data service. 27 * 28 * @return an BasicPeriodFormatterService 29 */ getInstance()30 public static BasicPeriodFormatterService getInstance() { 31 if (instance == null) { 32 PeriodFormatterDataService ds = ResourceBasedPeriodFormatterDataService 33 .getInstance(); 34 instance = new BasicPeriodFormatterService(ds); 35 } 36 return instance; 37 } 38 39 /** 40 * Construct a BasicPeriodFormatterService using the given 41 * PeriodFormatterDataService. 42 * 43 * @param ds the data service to use 44 */ BasicPeriodFormatterService(PeriodFormatterDataService ds)45 public BasicPeriodFormatterService(PeriodFormatterDataService ds) { 46 this.ds = ds; 47 } 48 49 @Override newDurationFormatterFactory()50 public DurationFormatterFactory newDurationFormatterFactory() { 51 return new BasicDurationFormatterFactory(this); 52 } 53 54 @Override newPeriodFormatterFactory()55 public PeriodFormatterFactory newPeriodFormatterFactory() { 56 return new BasicPeriodFormatterFactory(ds); 57 } 58 59 @Override newPeriodBuilderFactory()60 public PeriodBuilderFactory newPeriodBuilderFactory() { 61 return new BasicPeriodBuilderFactory(ds); 62 } 63 64 @Override getAvailableLocaleNames()65 public Collection<String> getAvailableLocaleNames() { 66 return ds.getAvailableLocales(); 67 } 68 } 69