ICU-11986 rename ICUResource to UResource, consistent with UResourceBundle, in case we want to make the resource enumeration public

X-SVN-Rev: 38088
This commit is contained in:
Markus Scherer 2015-11-18 00:19:31 +00:00
parent d5877ebe4e
commit d1b77c4e66
5 changed files with 35 additions and 32 deletions

View File

@ -447,18 +447,18 @@ public class ICUResourceBundle extends UResourceBundle {
return result;
}
public void getAllArrayItemsWithFallback(String path, ICUResource.ArraySink sink)
public void getAllArrayItemsWithFallback(String path, UResource.ArraySink sink)
throws MissingResourceException {
getAllContainerItemsWithFallback(path, sink, null);
}
public void getAllTableItemsWithFallback(String path, ICUResource.TableSink sink)
public void getAllTableItemsWithFallback(String path, UResource.TableSink sink)
throws MissingResourceException {
getAllContainerItemsWithFallback(path, null, sink);
}
private void getAllContainerItemsWithFallback(
String path, ICUResource.ArraySink arraySink, ICUResource.TableSink tableSink)
String path, UResource.ArraySink arraySink, UResource.TableSink tableSink)
throws MissingResourceException {
// Collect existing and parsed key objects into an array of keys,
// rather than assembling and parsing paths.
@ -484,14 +484,14 @@ public class ICUResourceBundle extends UResourceBundle {
throw new UResourceTypeMismatchException("");
}
// Get all table items with fallback.
ICUResource.Key key = new ICUResource.Key();
UResource.Key key = new UResource.Key();
ReaderValue readerValue = new ReaderValue();
rb.getAllContainerItemsWithFallback(key, readerValue, arraySink, tableSink);
}
private void getAllContainerItemsWithFallback(
ICUResource.Key key, ReaderValue readerValue,
ICUResource.ArraySink arraySink, ICUResource.TableSink tableSink) {
UResource.Key key, ReaderValue readerValue,
UResource.ArraySink arraySink, UResource.TableSink tableSink) {
// We recursively enumerate child-first,
// only storing parent items in the absence of child items.
// We store a placeholder value for the no-fallback/no-inheritance marker
@ -506,7 +506,7 @@ public class ICUResourceBundle extends UResourceBundle {
if (getType() == expectedType) {
if (arraySink != null) {
((ICUResourceBundleImpl.ResourceArray)this).getAllItems(key, readerValue, arraySink);
} else if (tableSink != null) {
} else /* tableSink != null */ {
((ICUResourceBundleImpl.ResourceTable)this).getAllItems(key, readerValue, tableSink);
}
}

View File

@ -195,7 +195,7 @@ class ICUResourceBundleImpl extends ICUResourceBundle {
* @param readerValue will be set during enumeration; input contents is ignored
* @param sink receives all array item values
*/
void getAllItems(ICUResource.Key key, ReaderValue readerValue, ICUResource.ArraySink sink) {
void getAllItems(UResource.Key key, ReaderValue readerValue, UResource.ArraySink sink) {
ICUResourceBundleReader reader = wholeBundle.reader;
readerValue.reader = reader;
((ICUResourceBundleReader.Array)value).getAllItems(reader, key, readerValue, sink);
@ -292,7 +292,7 @@ class ICUResourceBundleImpl extends ICUResourceBundle {
* @param readerValue will be set during enumeration; input contents is ignored
* @param sink receives all table item key-value pairs
*/
void getAllItems(ICUResource.Key key, ReaderValue readerValue, ICUResource.TableSink sink) {
void getAllItems(UResource.Key key, ReaderValue readerValue, UResource.TableSink sink) {
ICUResourceBundleReader reader = wholeBundle.reader;
readerValue.reader = reader;
((ICUResourceBundleReader.Table)value).getAllItems(reader, key, readerValue, sink);

View File

@ -13,8 +13,8 @@ import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.IntBuffer;
import com.ibm.icu.impl.ICUResource.ArraySink;
import com.ibm.icu.impl.ICUResource.TableSink;
import com.ibm.icu.impl.UResource.ArraySink;
import com.ibm.icu.impl.UResource.TableSink;
import com.ibm.icu.util.ICUException;
import com.ibm.icu.util.ICUUncheckedIOException;
import com.ibm.icu.util.ULocale;
@ -463,14 +463,14 @@ public final class ICUResourceBundleReader {
return makeKeyStringFromBytes(poolBundleReader.keyBytes, keyOffset & 0x7fffffff);
}
}
private void setKeyFromKey16(int keyOffset, ICUResource.Key key) {
private void setKeyFromKey16(int keyOffset, UResource.Key key) {
if(keyOffset < localKeyLimit) {
key.setBytes(keyBytes, keyOffset);
} else {
key.setBytes(poolBundleReader.keyBytes, keyOffset - localKeyLimit);
}
}
private void setKeyFromKey32(int keyOffset, ICUResource.Key key) {
private void setKeyFromKey32(int keyOffset, UResource.Key key) {
if(keyOffset >= 0) {
key.setBytes(keyBytes, keyOffset);
} else {
@ -831,7 +831,7 @@ public final class ICUResourceBundleReader {
UResourceBundle.NONE
};
static class ReaderValue extends ICUResource.Value {
static class ReaderValue extends UResource.Value {
ICUResourceBundleReader reader;
private int res;
@ -890,7 +890,7 @@ public final class ICUResourceBundleReader {
protected int size;
protected int itemsOffset;
int getSize() {
final int getSize() {
return size;
}
int getContainerResource(ICUResourceBundleReader reader, int index) {
@ -925,7 +925,7 @@ public final class ICUResourceBundleReader {
static class Array extends Container {
Array() {}
void getAllItems(ICUResourceBundleReader reader,
ICUResource.Key key, ReaderValue value, ArraySink sink) {
UResource.Key key, ReaderValue value, ArraySink sink) {
for (int i = 0; i < size; ++i) {
int res = getContainerResource(reader, i);
int type = RES_GET_TYPE(res);
@ -1019,7 +1019,7 @@ public final class ICUResourceBundleReader {
return getContainerResource(reader, findTableItem(reader, resKey));
}
void getAllItems(ICUResourceBundleReader reader,
ICUResource.Key key, ReaderValue value, TableSink sink) {
UResource.Key key, ReaderValue value, TableSink sink) {
for (int i = 0; i < size; ++i) {
if (keyOffsets != null) {
reader.setKeyFromKey16(keyOffsets[i], key);

View File

@ -24,8 +24,8 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import com.ibm.icu.impl.ICUResource.TableSink;
import com.ibm.icu.impl.TextTrieMap.ResultHandler;
import com.ibm.icu.impl.UResource.TableSink;
import com.ibm.icu.text.TimeZoneNames;
import com.ibm.icu.util.TimeZone;
import com.ibm.icu.util.TimeZone.SystemTimeZoneType;
@ -294,21 +294,21 @@ public class TimeZoneNamesImpl extends TimeZoneNames {
/**
* Loads all meta zone and time zone names for this TimeZoneNames' locale.
*/
private final class ZoneStringsLoader extends ICUResource.TableSink {
private final class ZoneStringsLoader extends UResource.TableSink {
/**
* Prepare for several hundred time zones and meta zones.
* _zoneStrings.getSize() is ineffective in a sparsely populated locale like en-GB.
*/
private static final int INITIAL_NUM_ZONES = 300;
private HashMap<ICUResource.Key, ZNamesLoader> keyToLoader =
new HashMap<ICUResource.Key, ZNamesLoader>(INITIAL_NUM_ZONES);
private HashMap<UResource.Key, ZNamesLoader> keyToLoader =
new HashMap<UResource.Key, ZNamesLoader>(INITIAL_NUM_ZONES);
private StringBuilder sb = new StringBuilder(32);
/** Caller must synchronize. */
void load() {
_zoneStrings.getAllTableItemsWithFallback("", this);
for (Map.Entry<ICUResource.Key, ZNamesLoader> entry : keyToLoader.entrySet()) {
ICUResource.Key key = entry.getKey();
for (Map.Entry<UResource.Key, ZNamesLoader> entry : keyToLoader.entrySet()) {
UResource.Key key = entry.getKey();
ZNamesLoader loader = entry.getValue();
if (loader == ZNamesLoader.DUMMY_LOADER) {
// skip
@ -325,7 +325,7 @@ public class TimeZoneNamesImpl extends TimeZoneNames {
}
@Override
public TableSink getOrCreateTableSink(ICUResource.Key key, int initialSize) {
public TableSink getOrCreateTableSink(UResource.Key key, int initialSize) {
ZNamesLoader loader = keyToLoader.get(key);
if (loader != null) {
if (loader == ZNamesLoader.DUMMY_LOADER) {
@ -356,7 +356,7 @@ public class TimeZoneNamesImpl extends TimeZoneNames {
}
@Override
public void putNoFallback(ICUResource.Key key) {
public void putNoFallback(UResource.Key key) {
if (!keyToLoader.containsKey(key)) {
keyToLoader.put(key.clone(), ZNamesLoader.DUMMY_LOADER);
}
@ -366,7 +366,7 @@ public class TimeZoneNamesImpl extends TimeZoneNames {
* Equivalent to key.substring(MZ_PREFIX.length())
* except reuses our StringBuilder.
*/
private String mzIDFromKey(ICUResource.Key key) {
private String mzIDFromKey(UResource.Key key) {
sb.setLength(0);
for (int i = MZ_PREFIX.length(); i < key.length(); ++i) {
sb.append(key.charAt(i));
@ -374,7 +374,7 @@ public class TimeZoneNamesImpl extends TimeZoneNames {
return sb.toString();
}
private String tzIDFromKey(ICUResource.Key key) {
private String tzIDFromKey(UResource.Key key) {
sb.setLength(0);
for (int i = 0; i < key.length(); ++i) {
char c = key.charAt(i);
@ -572,7 +572,7 @@ public class TimeZoneNamesImpl extends TimeZoneNames {
}
}
private static final class ZNamesLoader extends ICUResource.TableSink {
private static final class ZNamesLoader extends UResource.TableSink {
private static int NUM_META_ZONE_NAMES = 6;
private static int NUM_TIME_ZONE_NAMES = 7; // incl. EXEMPLAR_LOCATION
@ -612,7 +612,7 @@ public class TimeZoneNamesImpl extends TimeZoneNames {
return getNames();
}
private static NameType nameTypeFromKey(ICUResource.Key key) {
private static NameType nameTypeFromKey(UResource.Key key) {
// Avoid key.toString() object creation.
if (key.length() != 2) {
return null;
@ -634,7 +634,7 @@ public class TimeZoneNamesImpl extends TimeZoneNames {
}
@Override
public void put(ICUResource.Key key, ICUResource.Value value) {
public void put(UResource.Key key, UResource.Value value) {
if (value.getType() == UResourceBundle.STRING) {
if (names == null) {
names = new String[numNames];
@ -647,7 +647,7 @@ public class TimeZoneNamesImpl extends TimeZoneNames {
}
@Override
public void putNoFallback(ICUResource.Key key) {
public void putNoFallback(UResource.Key key) {
if (names == null) {
names = new String[numNames];
}

View File

@ -11,10 +11,13 @@ import java.nio.ByteBuffer;
import com.ibm.icu.util.UResourceBundle;
import com.ibm.icu.util.UResourceTypeMismatchException;
// Class UResource is named consistently with the public class UResourceBundle,
// in case we want to make it public at some point.
/**
* ICU resource bundle key and value types.
*/
public final class ICUResource {
public final class UResource {
/**
* Represents a resource bundle item's key string.
* Avoids object creations as much as possible.