From 51301f3a00189754e58b4042364ec55618cf57e2 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Mon, 26 Apr 2010 19:40:08 +0200 Subject: Reuse constant strings for UnicodeCharacter labels and whatnots. --- .../android/unicodeMap/UnicodeCharacter.java | 32 +++++++++++++++------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'src/org/madore') diff --git a/src/org/madore/android/unicodeMap/UnicodeCharacter.java b/src/org/madore/android/unicodeMap/UnicodeCharacter.java index 8fb64f7..34bab47 100644 --- a/src/org/madore/android/unicodeMap/UnicodeCharacter.java +++ b/src/org/madore/android/unicodeMap/UnicodeCharacter.java @@ -270,33 +270,45 @@ public class UnicodeCharacter implements UnicodeDisplayable { protected final int codePoint; protected final String name; protected final Category category; + protected final String charStr; + protected final String label; + + protected String makeCharStr() { + return new String(Character.toChars(codePoint)); + } + + protected String makeLabel() { + StringBuilder s = new StringBuilder(); + Formatter fmt = new Formatter(s); + if ( codePoint < 0x10000 ) + fmt.format("U+%04X %s", codePoint, name); + else + fmt.format("U+%X %s", codePoint, name); + return new String(s); + } public UnicodeCharacter(int codePoint, String name, Category category) { this.codePoint = codePoint; this.name = name; this.category = category; + this.charStr = makeCharStr(); + this.label = makeLabel(); } public int getCodePoint() { - return codePoint; + return this.codePoint; } public String getName() { - return name; + return this.name; } public String getChar() { - return new String(Character.toChars(codePoint)); + return this.charStr; } public String getLabel() { - StringBuilder s = new StringBuilder(); - Formatter fmt = new Formatter(s); - if ( codePoint < 0x10000 ) - fmt.format("U+%04X %s", codePoint, name); - else - fmt.format("U+%X %s", codePoint, name); - return new String(s); + return this.label; } public boolean isPrintable() { -- cgit v1.2.3