scuffed-code/tools/unicodetools/com/ibm/text/UCD/UnicodeProperty.java

167 lines
5.8 KiB
Java
Raw Normal View History

package com.ibm.text.UCD;
import com.ibm.text.UnicodeSet;
import com.ibm.text.utility.*;
public abstract class UnicodeProperty implements UCD_Types {
2001-12-05 02:41:23 +00:00
protected UCD ucd;
protected boolean isStandard = true;
2001-12-06 00:05:53 +00:00
protected byte type = NOT_DERIVED;
private byte valueType = BINARY;
2001-12-05 02:41:23 +00:00
protected boolean hasUnassigned = false;
protected boolean isBinary = true;
2001-12-05 02:41:23 +00:00
protected byte defaultValueStyle = SHORT;
protected byte defaultPropertyStyle = LONG;
2001-12-06 00:05:53 +00:00
protected String valueName;
protected String numberValueName;
protected String shortValueName;
2001-12-05 02:41:23 +00:00
protected String header;
protected String subheader;
protected String name;
protected String shortName;
2001-12-06 00:05:53 +00:00
protected String numberName;
2001-12-05 02:41:23 +00:00
/**
* Return the UCD in use
*/
public UCD getUCD() { return ucd; }
/**
* Is it part of the standard, or just for my testing?
*/
public boolean isStandard() { return isStandard; }
2001-12-05 02:41:23 +00:00
public void setStandard(boolean in) { isStandard = in; }
2001-12-06 00:05:53 +00:00
/**
* What type is it? DERIVED..
2001-12-06 00:05:53 +00:00
*/
public byte getType() { return type; }
public void setType(byte in) { type = in; }
/**
* Does getProperty vary in contents? ENUMERATED,...
*/
public byte getValueType() { return valueType; }
public void setValueType(byte in) { valueType = in; }
/**
2001-12-05 02:41:23 +00:00
* Does it apply to any unassigned characters?
*/
2001-12-05 02:41:23 +00:00
public boolean hasUnassigned() { return hasUnassigned; }
public void setHasUnassigned(boolean in) { hasUnassigned = in; }
/** Header used in DerivedXXX files
*/
public String getHeader() { return header; }
2001-12-05 02:41:23 +00:00
public void setHeader(String in) { header = in; }
/** Header used in DerivedXXX files
*/
public String getSubHeader() { return subheader; }
public void setSubHeader(String in) { subheader = in; }
/**
* Get the full name. Style is SHORT, NORMAL, LONG
*/
public String getFullName(byte style) {
return getProperty(style) + "=" + getValue(style);
}
2001-12-05 02:41:23 +00:00
public String getFullName() {
return getFullName(NORMAL);
}
/**
2001-12-05 02:41:23 +00:00
* Get the property name. Style is SHORT, NORMAL, LONG
*/
public String getProperty(byte style) {
2001-12-06 00:05:53 +00:00
if (style == NORMAL) style = defaultPropertyStyle;
switch (style) {
case LONG: return Utility.getUnskeleton(name.toString(), false);
2001-12-06 00:05:53 +00:00
case SHORT: return shortName.toString();
case NUMBER: return numberName.toString();
default: throw new IllegalArgumentException("Bad property: " + style);
}
2001-12-05 02:41:23 +00:00
}
public String getProperty() { return getProperty(NORMAL); }
public void setProperty(byte style, String in) {
2001-12-06 00:05:53 +00:00
if (style == NORMAL) style = defaultPropertyStyle;
2001-12-05 02:41:23 +00:00
switch (style) {
case LONG: name = Utility.getUnskeleton(in, false); break;
2001-12-05 02:41:23 +00:00
case SHORT: shortName = in; break;
2001-12-06 00:05:53 +00:00
case NUMBER: numberName = in; break;
2001-12-05 02:41:23 +00:00
default: throw new IllegalArgumentException("Bad property: " + style);
}
}
/**
* Get the value name. Style is SHORT, NORMAL, LONG
* "" if hasValue is false
* MUST OVERRIDE getValue(cp...) if valueVaries
*/
2001-12-05 02:41:23 +00:00
public String getValue(int cp, byte style) {
if (!hasValue(cp)) return "";
return getValue(style);
}
public String getValue(int cp) { return getValue(cp, NORMAL); }
public void setValue(byte style, String in) {
if (getValueType() != BINARY) throw new IllegalArgumentException("Can't set varying value: " + style);
2001-12-06 00:05:53 +00:00
if (style == NORMAL) style = defaultValueStyle;
2001-12-05 02:41:23 +00:00
switch (style) {
case LONG: valueName = Utility.getUnskeleton(in, false); break;
2001-12-05 02:41:23 +00:00
case SHORT: shortValueName = in; break;
2001-12-06 00:05:53 +00:00
case NUMBER: numberValueName = in; break;
2001-12-05 02:41:23 +00:00
default: throw new IllegalArgumentException("Bad value: " + style);
}
}
public String getValue(byte style) {
if (getValueType() != BINARY) throw new IllegalArgumentException(
2001-12-06 00:05:53 +00:00
"Value varies in " + getName(LONG) + "; call getValue(cp)");
try {
if (style == NORMAL) style = defaultValueStyle;
switch (style) {
case LONG: return Utility.getUnskeleton(valueName.toString(), false);
2001-12-06 00:05:53 +00:00
case SHORT: return shortValueName.toString();
case NUMBER: return numberValueName.toString();
default: throw new IllegalArgumentException("Bad property: " + style);
}
} catch (RuntimeException e) {
throw new com.ibm.text.utility.ChainException("Unset value string in " + getName(LONG), null, e);
}
2001-12-05 02:41:23 +00:00
}
/**
* Does it have the propertyValue?
*/
abstract boolean hasValue(int cp);
/**
* Get the set of characters it contains
*/
private UnicodeSet cache = null;
public UnicodeSet getSet() {
if (cache == null) {
cache = new UnicodeSet();
for (int cp = 0; cp <= 0x10FFFF; ++cp) {
if (hasValue(cp)) cache.add(cp);
}
}
return (UnicodeSet) cache.clone();
}
2001-12-05 02:41:23 +00:00
///////////////////////////////////////////
// Old Name for compatibility
boolean isTest() { return isStandard(); }
String getName(byte style) { return getProperty(style); }
String getName() { return getProperty(); }
}