ICU-7095 Updated UCharacter not to initialize its internal support classes such as UCaseName, UCharacterProperty and so on. Also updated these UCharacter internal support classes to have a public singleton for each, created at the initialization time.

X-SVN-Rev: 27101
This commit is contained in:
Yoshito Umaoka 2009-12-18 16:10:41 +00:00
parent 52c23e0a47
commit dda62f1106
11 changed files with 221 additions and 347 deletions

View file

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 2004-2007, International Business Machines
* Copyright (C) 2004-2009, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
@ -35,15 +35,21 @@ public final class UBiDiProps {
// constructors etc. --------------------------------------------------- ***
// port of ubidi_openProps()
public UBiDiProps() throws IOException{
private UBiDiProps() throws IOException{
InputStream is=ICUData.getStream(ICUResourceBundle.ICU_BUNDLE+"/"+DATA_FILE_NAME);
BufferedInputStream b=new BufferedInputStream(is, 4096 /* data buffer size */);
readData(b);
b.close();
is.close();
}
private UBiDiProps(boolean makeDummy) { // ignore makeDummy, only creates a unique signature
indexes=new int[IX_TOP];
indexes[0]=IX_TOP;
trie=new CharTrie(0, 0, null); // dummy trie, always returns 0
}
private void readData(InputStream is) throws IOException {
DataInputStream inputStream=new DataInputStream(is);
@ -91,24 +97,18 @@ public final class UBiDiProps {
}
}
// UBiDiProps singleton
private static UBiDiProps gBdp=null;
// port of ubidi_getSingleton()
public static final synchronized UBiDiProps getSingleton() throws IOException {
if(gBdp==null) {
gBdp=new UBiDiProps();
//
// Note: Do we really need this API?
public static UBiDiProps getSingleton() throws IOException {
if (FULL_INSTANCE == null) {
synchronized (UBiDiProps.class) {
if (FULL_INSTANCE == null) {
FULL_INSTANCE = new UBiDiProps();
}
}
}
return gBdp;
}
// UBiDiProps dummy singleton
private static UBiDiProps gBdpDummy=null;
private UBiDiProps(boolean makeDummy) { // ignore makeDummy, only creates a unique signature
indexes=new int[IX_TOP];
indexes[0]=IX_TOP;
trie=new CharTrie(0, 0, null); // dummy trie, always returns 0
return FULL_INSTANCE;
}
/**
@ -117,11 +117,16 @@ public final class UBiDiProps {
* Using the dummy can reduce checks for available data after an initial failure.
* Port of ucase_getDummy().
*/
public static final synchronized UBiDiProps getDummy() {
if(gBdpDummy==null) {
gBdpDummy=new UBiDiProps(true);
// Note: do we really need this API?
public static UBiDiProps getDummy() {
if (DUMMY_INSTANCE == null) {
synchronized (UBiDiProps.class) {
if (DUMMY_INSTANCE == null) {
DUMMY_INSTANCE = new UBiDiProps(true);
}
}
}
return gBdpDummy;
return DUMMY_INSTANCE;
}
// set of property starts for UnicodeSet ------------------------------- ***
@ -323,4 +328,28 @@ public final class UBiDiProps {
private static final int getMirrorIndex(int m) {
return m>>>MIRROR_INDEX_SHIFT;
}
/*
* public singleton instance
*/
public static final UBiDiProps INSTANCE;
private static volatile UBiDiProps FULL_INSTANCE;
private static volatile UBiDiProps DUMMY_INSTANCE;
// This static initializer block must be placed after
// other static member initialization
static {
UBiDiProps bp;
try {
bp = new UBiDiProps();
FULL_INSTANCE = bp;
} catch (IOException e) {
// creating dummy
bp = new UBiDiProps(true);
DUMMY_INSTANCE = bp;
}
INSTANCE = bp;
}
}

View file

@ -34,10 +34,11 @@ import com.ibm.icu.lang.UCharacter;
import com.ibm.icu.lang.UProperty;
public final class UCaseProps {
// constructors etc. --------------------------------------------------- ***
// port of ucase_openProps()
public UCaseProps() throws IOException {
private UCaseProps() throws IOException {
InputStream is=ICUData.getRequiredStream(ICUResourceBundle.ICU_BUNDLE+"/"+DATA_FILE_NAME);
BufferedInputStream b=new BufferedInputStream(is, 4096 /* data buffer size */);
readData(b);
@ -45,6 +46,12 @@ public final class UCaseProps {
is.close();
}
private UCaseProps(boolean makeDummy) { // ignore makeDummy, only creates a unique signature
indexes=new int[IX_TOP];
indexes[0]=IX_TOP;
trie=new CharTrie(0, 0, null); // dummy trie, always returns 0
}
private final void readData(InputStream is) throws IOException {
DataInputStream inputStream=new DataInputStream(is);
@ -94,24 +101,18 @@ public final class UCaseProps {
}
}
// UCaseProps singleton
private static UCaseProps gCsp=null;
// port of ucase_getSingleton()
public static final synchronized UCaseProps getSingleton() throws IOException {
if(gCsp==null) {
gCsp=new UCaseProps();
//
// Note: Do we really need this API?
public static UCaseProps getSingleton() throws IOException {
if (FULL_INSTANCE == null) {
synchronized (UCaseProps.class) {
if (FULL_INSTANCE == null) {
FULL_INSTANCE = new UCaseProps();
}
}
}
return gCsp;
}
// UCaseProps dummy singleton
private static UCaseProps gCspDummy=null;
private UCaseProps(boolean makeDummy) { // ignore makeDummy, only creates a unique signature
indexes=new int[IX_TOP];
indexes[0]=IX_TOP;
trie=new CharTrie(0, 0, null); // dummy trie, always returns 0
return FULL_INSTANCE;
}
/**
@ -120,11 +121,16 @@ public final class UCaseProps {
* Using the dummy can reduce checks for available data after an initial failure.
* Port of ucase_getDummy().
*/
public static final synchronized UCaseProps getDummy() {
if(gCspDummy==null) {
gCspDummy=new UCaseProps(true);
// Note: do we really need this API?
public static UCaseProps getDummy() {
if (DUMMY_INSTANCE == null) {
synchronized (UCaseProps.class) {
if (DUMMY_INSTANCE == null) {
DUMMY_INSTANCE = new UCaseProps(true);
}
}
}
return gCspDummy;
return DUMMY_INSTANCE;
}
// set of property starts for UnicodeSet ------------------------------- ***
@ -1459,4 +1465,28 @@ public final class UCaseProps {
private static final int UNFOLD_ROWS=0;
private static final int UNFOLD_ROW_WIDTH=1;
private static final int UNFOLD_STRING_WIDTH=2;
/*
* public singleton instance
*/
public static final UCaseProps INSTANCE;
private static volatile UCaseProps FULL_INSTANCE;
private static volatile UCaseProps DUMMY_INSTANCE;
// This static initializer block must be placed after
// other static member initialization
static {
UCaseProps cp;
try {
cp = new UCaseProps();
FULL_INSTANCE = cp;
} catch (IOException e) {
// creating dummy
cp = new UCaseProps(true);
DUMMY_INSTANCE = cp;
}
INSTANCE = cp;
}
}

View file

@ -36,6 +36,21 @@ public final class UCharacterName
{
// public data members ----------------------------------------------
/*
* public singleton instance
*/
public static final UCharacterName INSTANCE;
static {
try {
INSTANCE = new UCharacterName();
} catch (IOException e) {
///CLOVER:OFF
throw new MissingResourceException("Could not construct UCharacterName. Missing unames.icu","","");
///CLOVER:ON
}
}
/**
* Number of lines per group
* 1 << GROUP_SHIFT_
@ -48,26 +63,6 @@ public final class UCharacterName
// public methods ---------------------------------------------------
/**
* Gets the only instance of UCharacterName
* @return only instance of UCharacterName
* @exception MissingResourceException thrown when reading of name data fails
*/
public static UCharacterName getInstance()
{
if (INSTANCE_ == null) {
try {
INSTANCE_ = new UCharacterName();
}catch(IOException e){
throw new MissingResourceException("Could not construct UCharacterName. Missing unames.icu","","");
}
catch (Exception e) {
throw new MissingResourceException(e.getMessage(),"","");
}
}
return INSTANCE_;
}
/**
* Retrieve the name of a Unicode code point.
* Depending on <code>choice</code>, the character name written into the
@ -1118,10 +1113,6 @@ public final class UCharacterName
* Maximum name length
*/
private int m_maxNameLength_;
/**
* Singleton instance
*/
private static UCharacterName INSTANCE_ = null;
/**
* Type names used for extended names
*/

View file

@ -42,6 +42,20 @@ public final class UCharacterProperty
{
// public data members -----------------------------------------------
/*
* public singleton instance
*/
public static final UCharacterProperty INSTANCE;
static {
try {
INSTANCE = new UCharacterProperty();
}
catch (IOException e) {
throw new MissingResourceException(e.getMessage(),"","");
}
}
/**
* Trie data
*/
@ -567,23 +581,6 @@ public final class UCharacterProperty
return (lead << LEAD_SURROGATE_SHIFT_) + trail + SURROGATE_OFFSET_;
}
/**
* Loads the property data and initialize the UCharacterProperty instance.
* @throws MissingResourceException when data is missing or data has been corrupted
*/
public static UCharacterProperty getInstance()
{
if(INSTANCE_ == null) {
try {
INSTANCE_ = new UCharacterProperty();
}
catch (Exception e) {
throw new MissingResourceException(e.getMessage(),"","");
}
}
return INSTANCE_;
}
/**
* <p>
* Unicode property names and property value names are compared
@ -734,11 +731,6 @@ public final class UCharacterProperty
int m_maxJTGValue_;
// private variables -------------------------------------------------
/**
* UnicodeData.txt property object
*/
private static UCharacterProperty INSTANCE_ = null;
/**
* Default name of the datafile
*/

View file

@ -118,7 +118,7 @@ public final class UPropertyAliases implements ICUBinary.Authenticate {
* DATA_FILE_NAME is read from the jar/classpath and unflattened
* into member variables of this object.
*/
public UPropertyAliases() throws IOException {
private UPropertyAliases() throws IOException {
// Open the .icu file from the jar/classpath
InputStream is = ICUData.getRequiredStream(DATA_FILE_NAME);
@ -204,19 +204,16 @@ public final class UPropertyAliases implements ICUBinary.Authenticate {
//----------------------------------------------------------------
// Public API
public static UPropertyAliases INSTANCE_;
public static final UPropertyAliases INSTANCE;
public static synchronized UPropertyAliases getInstance() {
if (INSTANCE_ == null) {
try {
INSTANCE_ = new UPropertyAliases();
} catch(IOException e){
///CLOVER:OFF
throw new MissingResourceException("Could not construct UPropertyAliases. Missing pnames.icu","","");
///CLOVER:ON
}
static {
try {
INSTANCE = new UPropertyAliases();
} catch(IOException e) {
///CLOVER:OFF
throw new MissingResourceException("Could not construct UPropertyAliases. Missing pnames.icu","","");
///CLOVER:ON
}
return INSTANCE_;
}
/**

View file

@ -12,7 +12,6 @@ import java.lang.ref.SoftReference;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import com.ibm.icu.impl.IllegalIcuArgumentException;
import com.ibm.icu.impl.NormalizerImpl;
@ -2020,7 +2019,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
return INVALID_CODE;
}
return UnicodeBlock.getInstance((PROPERTY_.getAdditional(ch, 0)
return UnicodeBlock.getInstance((UCharacterProperty.INSTANCE.getAdditional(ch, 0)
& BLOCK_MASK_) >> BLOCK_SHIFT_);
}
@ -2036,7 +2035,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
return -1;
}
return (PROPERTY_.getAdditional(ch, 0) & BLOCK_MASK_) >> BLOCK_SHIFT_;
return (UCharacterProperty.INSTANCE.getAdditional(ch, 0) & BLOCK_MASK_) >> BLOCK_SHIFT_;
}
/**
@ -3114,7 +3113,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
public static int getNumericValue(int ch)
{
// slightly pruned version of getUnicodeNumericValue(), plus getEuropeanDigit()
int props = PROPERTY_.getProperty(ch);
int props = UCharacterProperty.INSTANCE.getProperty(ch);
int ntv = getNumericTypeValue(props);
if(ntv==NTV_NONE_) {
@ -3169,7 +3168,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
public static double getUnicodeNumericValue(int ch)
{
// equivalent to c version double u_getNumericValue(UChar32 c)
int props = PROPERTY_.getProperty(ch);
int props = UCharacterProperty.INSTANCE.getProperty(ch);
int ntv = getNumericTypeValue(props);
if(ntv==NTV_NONE_) {
@ -3631,7 +3630,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
* @stable ICU 2.1
*/
public static int toLowerCase(int ch) {
return gCsp.tolower(ch);
return UCaseProps.INSTANCE.tolower(ch);
}
/**
@ -3684,7 +3683,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
* @stable ICU 2.1
*/
public static int toTitleCase(int ch) {
return gCsp.totitle(ch);
return UCaseProps.INSTANCE.totitle(ch);
}
/**
@ -3707,7 +3706,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
* @stable ICU 2.1
*/
public static int toUpperCase(int ch) {
return gCsp.toupper(ch);
return UCaseProps.INSTANCE.toupper(ch);
}
// extra methods not in java.lang.Character --------------------------
@ -3795,7 +3794,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
*/
public static int getDirection(int ch)
{
return gBdp.getClass(ch);
return UBiDiProps.INSTANCE.getClass(ch);
}
/**
@ -3809,7 +3808,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
*/
public static boolean isMirrored(int ch)
{
return gBdp.isMirrored(ch);
return UBiDiProps.INSTANCE.isMirrored(ch);
}
/**
@ -3828,7 +3827,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
*/
public static int getMirror(int ch)
{
return gBdp.getMirror(ch);
return UBiDiProps.INSTANCE.getMirror(ch);
}
/**
@ -3911,7 +3910,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
*/
public static VersionInfo getUnicodeVersion()
{
return PROPERTY_.m_unicodeVersion_;
return UCharacterProperty.INSTANCE.m_unicodeVersion_;
}
/**
@ -3927,13 +3926,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
*/
public static String getName(int ch)
{
///CLOVER:OFF
// NAME_ is always initialized when the class is initialized
if(NAME_==null){
throw new MissingResourceException("Could not load unames.icu","","");
}
///CLOVER:ON
return NAME_.getName(ch, UCharacterNameChoice.UNICODE_CHAR_NAME);
return UCharacterName.INSTANCE.getName(ch, UCharacterNameChoice.UNICODE_CHAR_NAME);
}
/**
@ -3970,13 +3963,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
*/
public static String getName1_0(int ch)
{
///CLOVER:OFF
// NAME_ is always initialized when the class is initialized
if(NAME_==null){
throw new MissingResourceException("Could not load unames.icu","","");
}
///CLOVER:ON
return NAME_.getName(ch,
return UCharacterName.INSTANCE.getName(ch,
UCharacterNameChoice.UNICODE_10_CHAR_NAME);
}
@ -3999,13 +3986,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
* @stable ICU 2.6
*/
public static String getExtendedName(int ch) {
///CLOVER:OFF
// NAME_ is always initialized when the class is initialized
if(NAME_==null){
throw new MissingResourceException("Could not load unames.icu","","");
}
///CLOVER:ON
return NAME_.getName(ch, UCharacterNameChoice.EXTENDED_CHAR_NAME);
return UCharacterName.INSTANCE.getName(ch, UCharacterNameChoice.EXTENDED_CHAR_NAME);
}
/**
@ -4021,13 +4002,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
*/
public static String getNameAlias(int ch)
{
///CLOVER:OFF
// NAME_ is always initialized when the class is initialized
if(NAME_==null){
throw new MissingResourceException("Could not load unames.icu", "", "");
}
///CLOVER:ON
return NAME_.getName(ch, UCharacterNameChoice.CHAR_NAME_ALIAS);
return UCharacterName.INSTANCE.getName(ch, UCharacterNameChoice.CHAR_NAME_ALIAS);
}
/**
@ -4050,13 +4025,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
return null;
}
///CLOVER:OFF
// NAME_ is always initialized when the class is initialized
if(NAME_==null){
throw new MissingResourceException("Could not load unames.icu","","");
}
///CLOVER:ON
String result = NAME_.getGroupName(ch,
String result = UCharacterName.INSTANCE.getGroupName(ch,
UCharacterNameChoice.ISO_COMMENT_);
return result;
}
@ -4072,13 +4041,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
* @stable ICU 2.1
*/
public static int getCharFromName(String name){
///CLOVER:OFF
// NAME_ is always initialized when the class is initialized
if(NAME_==null){
throw new MissingResourceException("Could not load unames.icu","","");
}
///CLOVER:ON
return NAME_.getCharFromName(
return UCharacterName.INSTANCE.getCharFromName(
UCharacterNameChoice.UNICODE_CHAR_NAME, name);
}
@ -4093,13 +4056,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
* @stable ICU 2.1
*/
public static int getCharFromName1_0(String name){
///CLOVER:OFF
// NAME_ is always initialized when the class is initialized
if(NAME_==null){
throw new MissingResourceException("Could not load unames.icu","","");
}
///CLOVER:ON
return NAME_.getCharFromName(
return UCharacterName.INSTANCE.getCharFromName(
UCharacterNameChoice.UNICODE_10_CHAR_NAME, name);
}
@ -4123,13 +4080,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
* @stable ICU 2.6
*/
public static int getCharFromExtendedName(String name){
///CLOVER:OFF
// NAME_ is always initialized when the class is initialized
if(NAME_==null){
throw new MissingResourceException("Could not load unames.icu","","");
}
///CLOVER:ON
return NAME_.getCharFromName(
return UCharacterName.INSTANCE.getCharFromName(
UCharacterNameChoice.EXTENDED_CHAR_NAME, name);
}
@ -4143,13 +4094,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
* @draft ICU 4.4
*/
public static int getCharFromNameAlias(String name){
///CLOVER:OFF
// NAME_ is always initialized when the class is initialized
if(NAME_==null){
throw new MissingResourceException("Could not load unames.icu", "", "");
}
///CLOVER:ON
return NAME_.getCharFromName(UCharacterNameChoice.CHAR_NAME_ALIAS, name);
return UCharacterName.INSTANCE.getCharFromName(UCharacterNameChoice.CHAR_NAME_ALIAS, name);
}
/**
@ -4187,7 +4132,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
*/
public static String getPropertyName(int property,
int nameChoice) {
return PNAMES_.getPropertyName(property, nameChoice);
return UPropertyAliases.INSTANCE.getPropertyName(property, nameChoice);
}
/**
@ -4213,7 +4158,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
* @stable ICU 2.4
*/
public static int getPropertyEnum(String propertyAlias) {
int propEnum = PNAMES_.getPropertyEnum(propertyAlias);
int propEnum = UPropertyAliases.INSTANCE.getPropertyEnum(propertyAlias);
if (propEnum == UProperty.UNDEFINED) {
throw new IllegalIcuArgumentException("Invalid name: " + propertyAlias);
}
@ -4283,14 +4228,14 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
// this is hard coded for the valid cc
// because PropertyValueAliases.txt does not contain all of them
try {
return PNAMES_.getPropertyValueName(property, value,
return UPropertyAliases.INSTANCE.getPropertyValueName(property, value,
nameChoice);
}
catch (IllegalArgumentException e) {
return null;
}
}
return PNAMES_.getPropertyValueName(property, value, nameChoice);
return UPropertyAliases.INSTANCE.getPropertyValueName(property, value, nameChoice);
}
/**
@ -4325,7 +4270,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
* @stable ICU 2.4
*/
public static int getPropertyValueEnum(int property, String valueAlias) {
int propEnum = PNAMES_.getPropertyValueEnum(property, valueAlias);
int propEnum = UPropertyAliases.INSTANCE.getPropertyValueEnum(property, valueAlias);
if (propEnum == UProperty.UNDEFINED) {
throw new IllegalIcuArgumentException("Invalid name: " + valueAlias);
}
@ -4576,7 +4521,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
locCache[0]=0;
while((c=iter.nextCaseMapCP())>=0) {
c=gCsp.toFullUpper(c, iter, result, locale, locCache);
c = UCaseProps.INSTANCE.toFullUpper(c, iter, result, locale, locCache);
/* decode the result */
if(c<0) {
@ -4629,7 +4574,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
locCache[0]=0;
while((c=iter.nextCaseMapCP())>=0) {
c=gCsp.toFullLower(c, iter, result, locale, locCache);
c = UCaseProps.INSTANCE.toFullLower(c, iter, result, locale, locCache);
/* decode the result */
if(c<0) {
@ -4777,8 +4722,8 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
/* find and copy uncased characters [prev..titleStart[ */
iter.setLimit(index);
c=iter.nextCaseMapCP();
if((options&TITLECASE_NO_BREAK_ADJUSTMENT)==0 && UCaseProps.NONE==gCsp.getType(c)) {
while((c=iter.nextCaseMapCP())>=0 && UCaseProps.NONE==gCsp.getType(c)) {}
if((options&TITLECASE_NO_BREAK_ADJUSTMENT)==0 && UCaseProps.NONE==UCaseProps.INSTANCE.getType(c)) {
while((c=iter.nextCaseMapCP())>=0 && UCaseProps.NONE==UCaseProps.INSTANCE.getType(c)) {}
titleStart=iter.getCPStart();
if(prev<titleStart) {
result.append(str, prev, titleStart);
@ -4790,7 +4735,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
if(titleStart<index) {
FirstIJ = true;
/* titlecase c which is from titleStart */
c=gCsp.toFullTitle(c, iter, result, locale, locCache);
c = UCaseProps.INSTANCE.toFullTitle(c, iter, result, locale, locCache);
/* decode the result and lowercase up to index */
for(;;) {
@ -4834,7 +4779,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
FirstIJ = false;
} else {
/* Normal operation: Lowercase the rest of the word. */
c=gCsp.toFullLower(nc, iter, result, locale, locCache);
c = UCaseProps.INSTANCE.toFullLower(nc, iter, result, locale, locCache);
}
} else {
break;
@ -4932,7 +4877,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
* @stable ICU 2.6
*/
public static int foldCase(int ch, int options) {
return gCsp.fold(ch, options);
return UCaseProps.INSTANCE.fold(ch, options);
}
/**
@ -4958,7 +4903,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
for(i=0; i<length;) {
c=UTF16.charAt(str, i);
i+=UTF16.getCharCount(c);
c=gCsp.toFullFolding(c, result, options);
c = UCaseProps.INSTANCE.toFullFolding(c, result, options);
/* decode the result */
if(c<0) {
@ -5062,7 +5007,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
*/
public static RangeValueIterator getTypeIterator()
{
return new UCharacterTypeIterator(PROPERTY_);
return new UCharacterTypeIterator(UCharacterProperty.INSTANCE);
}
/**
@ -5086,13 +5031,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
* @stable ICU 2.6
*/
public static ValueIterator getNameIterator(){
///CLOVER:OFF
// NAME_ is always initialized when the class is initialized
if(NAME_==null){
throw new RuntimeException("Could not load unames.icu");
}
///CLOVER:ON
return new UCharacterNameIterator(NAME_,
return new UCharacterNameIterator(UCharacterName.INSTANCE,
UCharacterNameChoice.UNICODE_CHAR_NAME);
}
@ -5116,13 +5055,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
* @stable ICU 2.6
*/
public static ValueIterator getName1_0Iterator(){
///CLOVER:OFF
// NAME_ is always initialized when the class is initialized
if(NAME_==null){
throw new RuntimeException("Could not load unames.icu");
}
///CLOVER:ON
return new UCharacterNameIterator(NAME_,
return new UCharacterNameIterator(UCharacterName.INSTANCE,
UCharacterNameChoice.UNICODE_10_CHAR_NAME);
}
@ -5146,13 +5079,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
* @stable ICU 2.6
*/
public static ValueIterator getExtendedNameIterator(){
///CLOVER:OFF
// NAME_ is always initialized when the class is initialized
if(NAME_==null){
throw new MissingResourceException("Could not load unames.icu","","");
}
///CLOVER:ON
return new UCharacterNameIterator(NAME_,
return new UCharacterNameIterator(UCharacterName.INSTANCE,
UCharacterNameChoice.EXTENDED_CHAR_NAME);
}
@ -5173,7 +5100,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
if (ch < MIN_VALUE || ch > MAX_VALUE) {
throw new IllegalArgumentException("Codepoint out of bounds");
}
return PROPERTY_.getAge(ch);
return UCharacterProperty.INSTANCE.getAge(ch);
}
/**
@ -5206,7 +5133,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
if (ch < MIN_VALUE || ch > MAX_VALUE) {
throw new IllegalArgumentException("Codepoint out of bounds");
}
return PROPERTY_.hasBinaryProperty(ch, property);
return UCharacterProperty.INSTANCE.hasBinaryProperty(ch, property);
}
/**
@ -5338,26 +5265,26 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
case UProperty.CANONICAL_COMBINING_CLASS:
return getCombiningClass(ch);
case UProperty.DECOMPOSITION_TYPE:
return PROPERTY_.getAdditional(ch, 2)
return UCharacterProperty.INSTANCE.getAdditional(ch, 2)
& DECOMPOSITION_TYPE_MASK_;
case UProperty.EAST_ASIAN_WIDTH:
return (PROPERTY_.getAdditional(ch, 0)
return (UCharacterProperty.INSTANCE.getAdditional(ch, 0)
& EAST_ASIAN_MASK_) >> EAST_ASIAN_SHIFT_;
case UProperty.GENERAL_CATEGORY:
return getType(ch);
case UProperty.JOINING_GROUP:
return gBdp.getJoiningGroup(ch);
return UBiDiProps.INSTANCE.getJoiningGroup(ch);
case UProperty.JOINING_TYPE:
return gBdp.getJoiningType(ch);
return UBiDiProps.INSTANCE.getJoiningType(ch);
case UProperty.LINE_BREAK:
return (PROPERTY_.getAdditional(ch, LB_VWORD)& LB_MASK)>>LB_SHIFT;
return (UCharacterProperty.INSTANCE.getAdditional(ch, LB_VWORD)& LB_MASK)>>LB_SHIFT;
case UProperty.NUMERIC_TYPE:
return ntvGetType(getNumericTypeValue(PROPERTY_.getProperty(ch)));
return ntvGetType(getNumericTypeValue(UCharacterProperty.INSTANCE.getProperty(ch)));
case UProperty.SCRIPT:
return UScript.getScript(ch);
case UProperty.HANGUL_SYLLABLE_TYPE: {
/* see comments on gcbToHst[] above */
int gcb=(PROPERTY_.getAdditional(ch, 2)&GCB_MASK)>>GCB_SHIFT;
int gcb=(UCharacterProperty.INSTANCE.getAdditional(ch, 2)&GCB_MASK)>>GCB_SHIFT;
if(gcb<gcbToHst.length) {
return gcbToHst[gcb];
} else {
@ -5374,11 +5301,11 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
case UProperty.TRAIL_CANONICAL_COMBINING_CLASS:
return NormalizerImpl.getFCD16(ch)&0xff;
case UProperty.GRAPHEME_CLUSTER_BREAK:
return (PROPERTY_.getAdditional(ch, 2)& GCB_MASK)>>GCB_SHIFT;
return (UCharacterProperty.INSTANCE.getAdditional(ch, 2)& GCB_MASK)>>GCB_SHIFT;
case UProperty.SENTENCE_BREAK:
return (PROPERTY_.getAdditional(ch, 2)& SB_MASK)>>SB_SHIFT;
return (UCharacterProperty.INSTANCE.getAdditional(ch, 2)& SB_MASK)>>SB_SHIFT;
case UProperty.WORD_BREAK:
return (PROPERTY_.getAdditional(ch, 2)& WB_MASK)>>WB_SHIFT;
return (UCharacterProperty.INSTANCE.getAdditional(ch, 2)& WB_MASK)>>WB_SHIFT;
/* Values were tested for variable type from Integer.MIN_VALUE
* to UProperty.INT_LIMIT and none would not reach the default case.
*/
@ -5493,26 +5420,26 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
case UProperty.BIDI_CLASS:
case UProperty.JOINING_GROUP:
case UProperty.JOINING_TYPE:
return gBdp.getMaxValue(type);
return UBiDiProps.INSTANCE.getMaxValue(type);
case UProperty.BLOCK:
return (PROPERTY_.getMaxValues(0) & BLOCK_MASK_) >> BLOCK_SHIFT_;
return (UCharacterProperty.INSTANCE.getMaxValues(0) & BLOCK_MASK_) >> BLOCK_SHIFT_;
case UProperty.CANONICAL_COMBINING_CLASS:
case UProperty.LEAD_CANONICAL_COMBINING_CLASS:
case UProperty.TRAIL_CANONICAL_COMBINING_CLASS:
return 0xff; // TODO do we need to be more precise,
// getting the actual maximum?
case UProperty.DECOMPOSITION_TYPE:
return PROPERTY_.getMaxValues(2) & DECOMPOSITION_TYPE_MASK_;
return UCharacterProperty.INSTANCE.getMaxValues(2) & DECOMPOSITION_TYPE_MASK_;
case UProperty.EAST_ASIAN_WIDTH:
return (PROPERTY_.getMaxValues(0) & EAST_ASIAN_MASK_) >> EAST_ASIAN_SHIFT_;
return (UCharacterProperty.INSTANCE.getMaxValues(0) & EAST_ASIAN_MASK_) >> EAST_ASIAN_SHIFT_;
case UProperty.GENERAL_CATEGORY:
return UCharacterCategory.CHAR_CATEGORY_COUNT - 1;
case UProperty.LINE_BREAK:
return (PROPERTY_.getMaxValues(LB_VWORD) & LB_MASK) >> LB_SHIFT;
return (UCharacterProperty.INSTANCE.getMaxValues(LB_VWORD) & LB_MASK) >> LB_SHIFT;
case UProperty.NUMERIC_TYPE:
return NumericType.COUNT - 1;
case UProperty.SCRIPT:
return PROPERTY_.getMaxValues(0) & SCRIPT_MASK_;
return UCharacterProperty.INSTANCE.getMaxValues(0) & SCRIPT_MASK_;
case UProperty.HANGUL_SYLLABLE_TYPE:
return HangulSyllableType.COUNT-1;
case UProperty.NFD_QUICK_CHECK:
@ -5522,11 +5449,11 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
case UProperty.NFKC_QUICK_CHECK:
return 2; // MAYBE
case UProperty.GRAPHEME_CLUSTER_BREAK:
return (PROPERTY_.getMaxValues(2) & GCB_MASK) >> GCB_SHIFT;
return (UCharacterProperty.INSTANCE.getMaxValues(2) & GCB_MASK) >> GCB_SHIFT;
case UProperty.SENTENCE_BREAK:
return (PROPERTY_.getMaxValues(2) & SB_MASK) >> SB_SHIFT;
return (UCharacterProperty.INSTANCE.getMaxValues(2) & SB_MASK) >> SB_SHIFT;
case UProperty.WORD_BREAK:
return (PROPERTY_.getMaxValues(2) & WB_MASK) >> WB_SHIFT;
return (UCharacterProperty.INSTANCE.getMaxValues(2) & WB_MASK) >> WB_SHIFT;
/* Values were tested for variable type from Integer.MIN_VALUE
* to UProperty.INT_LIMIT and none would not reach the default case.
*/
@ -6054,99 +5981,8 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
return index;
}
// protected data members --------------------------------------------
/**
* Database storing the sets of character name
*/
static UCharacterName NAME_ = UCharacterName.getInstance();
/**
* Singleton object encapsulating the imported pnames.icu property aliases
*/
static UPropertyAliases PNAMES_ = UPropertyAliases.getInstance();
// private variables -------------------------------------------------
/**
* Database storing the sets of character property
*/
private static final UCharacterProperty PROPERTY_;
/**
* For optimization
*/
private static final char[] PROPERTY_TRIE_INDEX_;
private static final char[] PROPERTY_TRIE_DATA_;
private static final int PROPERTY_INITIAL_VALUE_;
private static final UCaseProps gCsp;
private static final UBiDiProps gBdp;
// block to initialise character property database
static
{
try
{
PROPERTY_ = UCharacterProperty.getInstance();
PROPERTY_TRIE_INDEX_ = PROPERTY_.m_trieIndex_;
PROPERTY_TRIE_DATA_ = PROPERTY_.m_trieData_;
PROPERTY_INITIAL_VALUE_ = PROPERTY_.m_trieInitialValue_;
}
catch (Exception e){
///CLOVER:OFF
// This part of code is initialize as part of the class
throw new MissingResourceException(e.getMessage(),"","");
///CLOVER:ON
}
/*
* In ICU4J 3.2, most Unicode properties were loaded from uprops.icu.
* ICU4J 3.4 adds ucase.icu for case mapping properties and
* ubidi.icu for bidi/shaping properties and
* removes case/bidi/shaping properties from uprops.icu.
*
* Loading of uprops.icu was always done during class loading of UCharacter.class.
* In order to maintain performance for all such properties,
* ucase.icu and ubidi.icu are also loaded during class loading of UCharacter.class.
* It will not fail if they are missing.
* These data items are loaded early to avoid having to synchronize access to them,
* for thread safety and performance.
*
* We try to load these data items at most once.
* If it works, we use the resulting singleton object.
* If it fails, then we get a dummy object, which always works unless
* we are seriously out of memory.
* After UCharacter.class loading, we have a never-changing pointer to either the
* real singleton or the dummy.
*
* This method is used in Unicode properties APIs that
* do not have a service object and also do not have an error code parameter.
* Other API implementations get the singleton themselves
* (synchronized), store it in the service object, and report errors.
*/
UCaseProps csp;
try {
csp=UCaseProps.getSingleton();
} catch(IOException e) {
///CLOVER:OFF
// This part of code is initialize as part of the class
csp=UCaseProps.getDummy();
///CLOVER:ON
}
gCsp=csp;
UBiDiProps bdp;
try {
bdp=UBiDiProps.getSingleton();
} catch(IOException e) {
///CLOVER:OFF
// This part of code is initialize as part of the class
bdp=UBiDiProps.getDummy();
///CLOVER:ON
}
gBdp=bdp;
}
/**
* To get the last character out from a data type
*/
@ -6429,22 +6265,22 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
&& ch < UTF16.SUPPLEMENTARY_MIN_VALUE)) {
// BMP codepoint 0000..D7FF or DC00..FFFF
try { // using try for ch < 0 is faster than using an if statement
return PROPERTY_TRIE_DATA_[
(PROPERTY_TRIE_INDEX_[ch >> 5] << 2)
return UCharacterProperty.INSTANCE.m_trieData_[
(UCharacterProperty.INSTANCE.m_trieIndex_[ch >> 5] << 2)
+ (ch & 0x1f)];
} catch (ArrayIndexOutOfBoundsException e) {
// TODO: Tested all the values from 0 ... UTF16.LEAD_SURROGATE_MIN_VALUE
// and UTF16.LEAD_SURROGATE_MAX_VALUE ... UTF16.SUPPLEMENTARY_MIN_VALUE
// but it never results into the catch section of the try-catch
///CLOVER:OFF
return PROPERTY_INITIAL_VALUE_;
return UCharacterProperty.INSTANCE.m_trieInitialValue_;
///CLOVER:ON
}
}
if (ch <= UTF16.LEAD_SURROGATE_MAX_VALUE) {
// lead surrogate D800..DBFF
return PROPERTY_TRIE_DATA_[
(PROPERTY_TRIE_INDEX_[(0x2800 >> 5) + (ch >> 5)] << 2)
return UCharacterProperty.INSTANCE.m_trieData_[
(UCharacterProperty.INSTANCE.m_trieIndex_[(0x2800 >> 5) + (ch >> 5)] << 2)
+ (ch & 0x1f)];
}
// for optimization
@ -6452,7 +6288,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
// supplementary code point 10000..10FFFF
// look at the construction of supplementary characters
// trail forms the ends of it.
return PROPERTY_.m_trie_.getSurrogateValue(
return UCharacterProperty.INSTANCE.m_trie_.getSurrogateValue(
UTF16.getLeadSurrogate(ch),
(char)(ch & 0x3ff));
}
@ -6460,6 +6296,6 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
// the default value: m_initialValue_
// we cannot assume that m_initialValue_ is at offset 0
// this is for optimization.
return PROPERTY_INITIAL_VALUE_;
return UCharacterProperty.INSTANCE.m_trieInitialValue_;
}
}

View file

@ -747,7 +747,6 @@ public final class UScript {
*/
public static final int CODE_LIMIT = 134;
private static final UCharacterProperty prop= UCharacterProperty.getInstance();
private static final String kLocaleScript = "LocaleScript";
//private static final String INVALID_NAME = "Invalid";
@ -872,7 +871,7 @@ public final class UScript {
*/
public static final int getScript(int codepoint){
if (codepoint >= UCharacter.MIN_VALUE & codepoint <= UCharacter.MAX_VALUE) {
return (prop.getAdditional(codepoint,0) & UCharacter.SCRIPT_MASK_);
return (UCharacterProperty.INSTANCE.getAdditional(codepoint,0) & UCharacter.SCRIPT_MASK_);
}else{
throw new IllegalArgumentException(Integer.toString(codepoint));
}

View file

@ -3088,14 +3088,14 @@ public class UnicodeSet extends UnicodeFilter implements Iterable<String>, Compa
try {
switch(src) {
case UCharacterProperty.SRC_CHAR:
UCharacterProperty.getInstance().addPropertyStarts(incl);
UCharacterProperty.INSTANCE.addPropertyStarts(incl);
break;
case UCharacterProperty.SRC_PROPSVEC:
UCharacterProperty.getInstance().upropsvec_addPropertyStarts(incl);
UCharacterProperty.INSTANCE.upropsvec_addPropertyStarts(incl);
break;
case UCharacterProperty.SRC_CHAR_AND_PROPSVEC:
UCharacterProperty.getInstance().addPropertyStarts(incl);
UCharacterProperty.getInstance().upropsvec_addPropertyStarts(incl);
UCharacterProperty.INSTANCE.addPropertyStarts(incl);
UCharacterProperty.INSTANCE.upropsvec_addPropertyStarts(incl);
break;
case UCharacterProperty.SRC_NORM:
NormalizerImpl.addPropertyStarts(incl);
@ -3231,7 +3231,7 @@ public class UnicodeSet extends UnicodeFilter implements Iterable<String>, Compa
if (prop == UProperty.GENERAL_CATEGORY_MASK) {
applyFilter(new GeneralCategoryMaskFilter(value), UCharacterProperty.SRC_CHAR);
} else {
applyFilter(new IntPropertyFilter(prop, value), UCharacterProperty.getInstance().getSource(prop));
applyFilter(new IntPropertyFilter(prop, value), UCharacterProperty.INSTANCE.getSource(prop));
}
return this;
}
@ -3371,7 +3371,7 @@ public class UnicodeSet extends UnicodeFilter implements Iterable<String>, Compa
// valueAlias is empty. Interpret as General Category, Script,
// Binary property, or ANY or ASCII. Upon success, p and v will
// be set.
UPropertyAliases pnames = UPropertyAliases.getInstance();
UPropertyAliases pnames = UPropertyAliases.INSTANCE;
p = UProperty.GENERAL_CATEGORY_MASK;
v = pnames.getPropertyValueEnum(p, propertyAlias);
if (v == UProperty.UNDEFINED) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 1996-2004, International Business Machines Corporation and
* Copyright (C) 1996-2009, International Business Machines Corporation and
* others. All Rights Reserved.
*/
package com.ibm.icu.text;
@ -49,13 +49,13 @@ class NameUnicodeTransliterator extends Transliterator {
protected void handleTransliterate(Replaceable text,
Position offsets, boolean isIncremental) {
int maxLen = UCharacterName.getInstance().getMaxCharNameLength() + 1; // allow for temporary trailing space
int maxLen = UCharacterName.INSTANCE.getMaxCharNameLength() + 1; // allow for temporary trailing space
StringBuffer name = new StringBuffer(maxLen);
// Get the legal character set
UnicodeSet legal = new UnicodeSet();
UCharacterName.getInstance().getCharNameCharacters(legal);
UCharacterName.INSTANCE.getCharNameCharacters(legal);
int cursor = offsets.start;
int limit = offsets.limit;

View file

@ -832,7 +832,7 @@ public final class UCharacterTest extends TestFmwk
public void TestNames()
{
try{
int length = UCharacterName.getInstance().getMaxCharNameLength();
int length = UCharacterName.INSTANCE.getMaxCharNameLength();
if (length < 83) { // Unicode 3.2 max char name length
errln("getMaxCharNameLength()=" + length + " is too short");
}
@ -975,7 +975,7 @@ public final class UCharacterTest extends TestFmwk
// letters than actual character names contain because
// it includes all the characters in lowercased names of
// general categories, for the full possible set of extended names.
UCharacterName.getInstance().getCharNameCharacters(set);
UCharacterName.INSTANCE.getCharNameCharacters(set);
// build set the dumb (but sure-fire) way
Arrays.fill(map, false);
@ -997,7 +997,7 @@ public final class UCharacterTest extends TestFmwk
}
}
length = UCharacterName.getInstance().getMaxCharNameLength();
length = UCharacterName.INSTANCE.getMaxCharNameLength();
if (length != maxLength) {
errln("getMaxCharNameLength()=" + length
+ " differs from the maximum length " + maxLength

View file

@ -1,6 +1,6 @@
/**
*******************************************************************************
* Copyright (C) 1996-2007, International Business Machines Corporation and *
* Copyright (C) 1996-2009, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
@ -479,7 +479,7 @@ public final class TrieTest extends TestFmwk
{
CharTrie trie = null;
try {
trie = UCharacterProperty.getInstance().m_trie_;
trie = UCharacterProperty.INSTANCE.m_trie_;
} catch (Exception e) {
warnln("Error creating ucharacter trie");
return;