ICU-7323 move API classes to text package, clean up some whitespace
X-SVN-Rev: 27153
This commit is contained in:
parent
5129297cf3
commit
11acc7e54f
@ -6,6 +6,7 @@
|
||||
*/
|
||||
package com.ibm.icu.impl;
|
||||
|
||||
import com.ibm.icu.text.CurrencyDisplayNames;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -4,8 +4,9 @@
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.impl;
|
||||
package com.ibm.icu.text;
|
||||
|
||||
import com.ibm.icu.impl.CurrencyData;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
import java.util.Map;
|
||||
|
@ -4,7 +4,7 @@
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.impl;
|
||||
package com.ibm.icu.text;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2001-2009, International Business Machines Corporation and *
|
||||
* Copyright (C) 2001-2010, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -16,15 +16,16 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import com.ibm.icu.impl.CurrencyDisplayNames;
|
||||
import com.ibm.icu.impl.CurrencyMetaInfo;
|
||||
import com.ibm.icu.impl.ICUCache;
|
||||
import com.ibm.icu.impl.ICUDebug;
|
||||
import com.ibm.icu.impl.ICUResourceBundle;
|
||||
import com.ibm.icu.impl.SimpleCache;
|
||||
import com.ibm.icu.impl.TextTrieMap;
|
||||
import com.ibm.icu.impl.CurrencyMetaInfo.CurrencyDigits;
|
||||
import com.ibm.icu.impl.CurrencyMetaInfo.CurrencyFilter;
|
||||
|
||||
import com.ibm.icu.text.CurrencyDisplayNames;
|
||||
import com.ibm.icu.text.CurrencyMetaInfo;
|
||||
import com.ibm.icu.text.CurrencyMetaInfo.CurrencyDigits;
|
||||
import com.ibm.icu.text.CurrencyMetaInfo.CurrencyFilter;
|
||||
|
||||
/**
|
||||
* A class encapsulating a currency, as defined by ISO 4217. A
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2009, International Business Machines Corporation and *
|
||||
* Copyright (C) 2009-2010, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -36,7 +36,7 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
||||
}
|
||||
return new ICUCurrencyDisplayInfo(rb, withFallback);
|
||||
}
|
||||
|
||||
|
||||
public boolean hasData() {
|
||||
return true;
|
||||
}
|
||||
@ -48,7 +48,7 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
||||
private final ICUResourceBundle plurals;
|
||||
private SoftReference<Map<String, String>> _symbolMapRef;
|
||||
private SoftReference<Map<String, String>> _nameMapRef;
|
||||
|
||||
|
||||
public ICUCurrencyDisplayInfo(ICUResourceBundle rb, boolean fallback) {
|
||||
this.fallback = fallback;
|
||||
this.rb = rb;
|
||||
@ -70,14 +70,14 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
||||
public String getSymbol(String isoCode) {
|
||||
return getName(isoCode, true);
|
||||
}
|
||||
|
||||
|
||||
private String getName(String isoCode, boolean symbolName) {
|
||||
if (currencies != null) {
|
||||
ICUResourceBundle result = currencies.findWithFallback(isoCode);
|
||||
if (result != null) {
|
||||
if (!fallback) {
|
||||
int status = result.getLoadingStatus();
|
||||
if (status == ICUResourceBundle.FROM_DEFAULT ||
|
||||
if (status == ICUResourceBundle.FROM_DEFAULT ||
|
||||
status == ICUResourceBundle.FROM_ROOT) {
|
||||
return null;
|
||||
}
|
||||
@ -108,10 +108,10 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
||||
return pluralBundle.getString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return fallback ? getName(isoCode) : null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, String> symbolMap() {
|
||||
Map<String, String> map = _symbolMapRef == null ? null : _symbolMapRef.get();
|
||||
@ -122,7 +122,7 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, String> nameMap() {
|
||||
Map<String, String> map = _nameMapRef == null ? null : _nameMapRef.get();
|
||||
@ -133,11 +133,11 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, String> getUnitPatterns() {
|
||||
Map<String, String> result = new HashMap<String, String>();
|
||||
|
||||
|
||||
ULocale locale = rb.getULocale();
|
||||
for (;locale != null; locale = locale.getFallback()) {
|
||||
ICUResourceBundle r = (ICUResourceBundle) UResourceBundle.getBundleInstance(
|
||||
@ -158,12 +158,12 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
||||
result.put(key, b.getString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Default result is the empty map. Callers who require a pattern will have to
|
||||
// supply a default.
|
||||
return Collections.unmodifiableMap(result);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CurrencyFormatInfo getFormatInfo(String isoCode) {
|
||||
ICUResourceBundle crb = currencies.findWithFallback(isoCode);
|
||||
@ -192,7 +192,7 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
||||
String afterCurrencyMatch = arb.findWithFallback("currencyMatch").getString();
|
||||
String afterContextMatch = arb.findWithFallback("surroundingMatch").getString();
|
||||
String afterInsert = arb.findWithFallback("insertBetween").getString();
|
||||
|
||||
|
||||
return new CurrencySpacingInfo(
|
||||
beforeCurrencyMatch, beforeContextMatch, beforeInsert,
|
||||
afterCurrencyMatch, afterContextMatch, afterInsert);
|
||||
@ -200,10 +200,10 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
||||
}
|
||||
return fallback ? CurrencySpacingInfo.DEFAULT : null;
|
||||
}
|
||||
|
||||
|
||||
private Map<String, String> _createSymbolMap() {
|
||||
Map<String, String> result = new HashMap<String, String>();
|
||||
|
||||
|
||||
for (ULocale locale = rb.getULocale(); locale != null; locale = locale.getFallback()) {
|
||||
ICUResourceBundle bundle = (ICUResourceBundle)
|
||||
UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_CURR_BASE_NAME, locale);
|
||||
@ -223,14 +223,14 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Collections.unmodifiableMap(result);
|
||||
}
|
||||
|
||||
|
||||
private Map<String, String> _createNameMap() {
|
||||
// ignore case variants
|
||||
Map<String, String> result = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
|
||||
Set<String> visited = new HashSet<String>();
|
||||
Map<String, Set<String>> visitedPlurals = new HashMap<String, Set<String>>();
|
||||
for (ULocale locale = rb.getULocale(); locale != null; locale = locale.getFallback()) {
|
||||
@ -249,7 +249,7 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ICUResourceBundle plurals = bundle.findTopLevel("CurrencyPlurals");
|
||||
if (plurals != null) {
|
||||
for (int i = 0; i < plurals.getSize(); ++i) {
|
||||
@ -272,7 +272,7 @@ public class ICUCurrencyDisplayInfoProvider implements CurrencyDisplayInfoProvid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Collections.unmodifiableMap(result);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2009, International Business Machines Corporation and *
|
||||
* Copyright (C) 2009-2010, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.impl;
|
||||
|
||||
import com.ibm.icu.text.CurrencyMetaInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@ -18,7 +20,7 @@ import java.util.Set;
|
||||
public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
|
||||
private ICUResourceBundle regionInfo;
|
||||
private ICUResourceBundle digitInfo;
|
||||
|
||||
|
||||
public ICUCurrencyMetaInfo() {
|
||||
ICUResourceBundle bundle = (ICUResourceBundle) ICUResourceBundle.getBundleInstance(
|
||||
ICUResourceBundle.ICU_CURR_BASE_NAME, "supplementalData",
|
||||
@ -26,22 +28,22 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
|
||||
regionInfo = bundle.findTopLevel("CurrencyMap");
|
||||
digitInfo = bundle.findTopLevel("CurrencyMeta");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<CurrencyInfo> currencyInfo(CurrencyFilter filter) {
|
||||
return collect(new InfoCollector(), filter);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> currencies(CurrencyFilter filter) {
|
||||
return collect(new CurrencyCollector(), filter);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> regions(CurrencyFilter filter) {
|
||||
return collect(new RegionCollector(), filter);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CurrencyDigits currencyDigits(String isoCode) {
|
||||
ICUResourceBundle b = digitInfo.findWithFallback(isoCode);
|
||||
@ -51,12 +53,12 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
|
||||
int[] data = b.getIntVector();
|
||||
return new CurrencyDigits(data[0], data[1]);
|
||||
}
|
||||
|
||||
|
||||
private <T> List<T> collect(Collector<T> collector, CurrencyFilter filter) {
|
||||
// We rely on the fact that the data lists the regions in order, and the
|
||||
// We rely on the fact that the data lists the regions in order, and the
|
||||
// priorities in order within region. This means we don't need
|
||||
// to sort the results to ensure the ordering matches the spec.
|
||||
|
||||
|
||||
if (filter == null) {
|
||||
filter = CurrencyFilter.all();
|
||||
}
|
||||
@ -70,7 +72,7 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
|
||||
if (filter.from != Long.MIN_VALUE || filter.to != Long.MAX_VALUE) {
|
||||
needed |= Date;
|
||||
}
|
||||
|
||||
|
||||
if (needed != 0) {
|
||||
if (filter.region != null) {
|
||||
ICUResourceBundle b = regionInfo.findWithFallback(filter.region);
|
||||
@ -83,13 +85,13 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return collector.getList();
|
||||
}
|
||||
|
||||
private <T> void collectRegion(Collector<T> collector, CurrencyFilter filter,
|
||||
|
||||
private <T> void collectRegion(Collector<T> collector, CurrencyFilter filter,
|
||||
int needed, ICUResourceBundle b) {
|
||||
|
||||
|
||||
String region = b.getKey();
|
||||
if ((needed & nonRegion) == 0) {
|
||||
collector.collect(b.getKey(), null, 0, 0, -1);
|
||||
@ -107,7 +109,7 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
|
||||
String currency = null;
|
||||
long from = Long.MIN_VALUE;
|
||||
long to = Long.MAX_VALUE;
|
||||
|
||||
|
||||
if ((needed & Currency) != 0) {
|
||||
ICUResourceBundle currBundle = r.at("id");
|
||||
currency = currBundle.getString();
|
||||
@ -115,7 +117,7 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ((needed & Date) != 0) {
|
||||
from = getDate(r.at("from"), Long.MIN_VALUE);
|
||||
to = getDate(r.at("to"), Long.MAX_VALUE);
|
||||
@ -130,12 +132,12 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// data lists elements in priority order, so 'i' suffices
|
||||
collector.collect(region, currency, from, to, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static final long MASK = 4294967295L;
|
||||
private long getDate(ICUResourceBundle b, long defaultValue) {
|
||||
if (b == null) {
|
||||
@ -144,34 +146,34 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
|
||||
int[] values = b.getIntVector();
|
||||
return ((long) values[0] << 32) | ((long) values[1] & MASK);
|
||||
}
|
||||
|
||||
|
||||
// Utility, just because I don't like the n^2 behavior of using list.contains to build a
|
||||
// list of unique items. If we used java 6 we could use their class for this.
|
||||
private static class UniqueList<T> {
|
||||
private Set<T> seen = new HashSet<T>();
|
||||
private List<T> list = new ArrayList<T>();
|
||||
|
||||
|
||||
private static <T> UniqueList<T> create() {
|
||||
return new UniqueList<T>();
|
||||
}
|
||||
|
||||
|
||||
void add(T value) {
|
||||
if (!seen.contains(value)) {
|
||||
list.add(value);
|
||||
seen.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
List<T> list() {
|
||||
return Collections.unmodifiableList(list);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class InfoCollector implements Collector<CurrencyInfo> {
|
||||
// Data is already unique by region/priority, so we don't need to be concerned
|
||||
// about duplicates.
|
||||
private List<CurrencyInfo> result = new ArrayList<CurrencyInfo>();
|
||||
|
||||
|
||||
public void collect(String region, String currency, long from, long to, int priority) {
|
||||
result.add(new CurrencyInfo(region, currency, from, to, priority));
|
||||
}
|
||||
@ -184,10 +186,10 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
|
||||
return Region | Currency | Date;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class RegionCollector implements Collector<String> {
|
||||
private final UniqueList<String> result = UniqueList.create();
|
||||
|
||||
|
||||
public void collect(String region, String currency, long from, long to, int priority) {
|
||||
result.add(region);
|
||||
}
|
||||
@ -200,10 +202,10 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
|
||||
return result.list();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class CurrencyCollector implements Collector<String> {
|
||||
private final UniqueList<String> result = UniqueList.create();
|
||||
|
||||
|
||||
public void collect(String region, String currency, long from, long to, int priority) {
|
||||
result.add(currency);
|
||||
}
|
||||
@ -216,20 +218,20 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
|
||||
return result.list();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static final int Region = 1;
|
||||
private static final int Currency = 2;
|
||||
private static final int Date = 4;
|
||||
|
||||
|
||||
private static final int nonRegion = Currency | Date;
|
||||
|
||||
|
||||
private static interface Collector<T> {
|
||||
/**
|
||||
* A bitmask of Region/Currency/Date indicating which features we collect.
|
||||
* @return the bitmask
|
||||
*/
|
||||
int collects();
|
||||
|
||||
|
||||
/**
|
||||
* Called with data passed by filter. Values not collected by filter should be ignored.
|
||||
* @param region the region code (null if ignored)
|
||||
@ -239,7 +241,7 @@ public class ICUCurrencyMetaInfo extends CurrencyMetaInfo {
|
||||
* @param priority priority (-1 if ignored)
|
||||
*/
|
||||
void collect(String region, String currency, long from, long to, int priority);
|
||||
|
||||
|
||||
/**
|
||||
* Return the list of unique items in the order in which we encountered them for the
|
||||
* first time. The returned list is unmodifiable.
|
||||
|
Loading…
Reference in New Issue
Block a user