X-Git-Url: http://git.osdn.net/view?p=mikutoga%2FTogaGem.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fjp%2Fsourceforge%2Fmikutoga%2Fcorelib%2FI18nText.java;h=001fa45ff60f301d79777b9387af2e1703c609bd;hp=50e2fb7487bd84b64fbf994d4ef52cfecdb91ee1;hb=d68ba6e44800ba2c2f0da1f4b5d6be588b30079f;hpb=f605ea9a49f65d6eeae8b3fbdfba12a3549855fb
diff --git a/src/main/java/jp/sourceforge/mikutoga/corelib/I18nText.java b/src/main/java/jp/sourceforge/mikutoga/corelib/I18nText.java
index 50e2fb7..001fa45 100644
--- a/src/main/java/jp/sourceforge/mikutoga/corelib/I18nText.java
+++ b/src/main/java/jp/sourceforge/mikutoga/corelib/I18nText.java
@@ -1,311 +1,311 @@
-/*
- * international text
- *
- * License : The MIT License
- * Copyright(c) 2010 MikuToga Partners
- */
-
-package jp.sourceforge.mikutoga.corelib;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * å¤è¨èªã®ããªã¢ã³ããæã¤æååæ
å ±ã
- *
- * - ãã©ã¤ããªï¼èå¥åã«ã¯ãã¡ãã使ããåºæ¬ã¯æ¥æ¬èªã
- *
- ã°ãã¼ãã«ï¼åºæ¬ã¯è±èªãUCS Basic-Latinãªã³ãªã¼ã®è²§å¼±ãªè¨èªç°å¢ã§ã
- * èªããæååãæã¾ããã
- *
- ãã®ä»ï¼å¿
è¦ã«å¿ãã¦å¥½ããªè¨èªãã
- *
- */
-public class I18nText implements CharSequence {
-
- /** ãã©ã¤ããªè¨èªã®ãã±ã¼ã«ã */
- public static final Locale LOCALE_PRIMARY = Locale.JAPANESE;
- /** ãã©ã¤ããªè¨èªã®è¨èªã³ã¼ãã */
- public static final String CODE639_PRIMARY = LOCALE_PRIMARY.getLanguage();
-
- /** ã°ãã¼ãã«è¨èªã®ãã±ã¼ã«ã */
- public static final Locale LOCALE_GLOBAL = Locale.ENGLISH;
- /** ã°ãã¼ãã«è¨èªã®è¨èªã³ã¼ãã */
- public static final String CODE639_GLOBAL = LOCALE_GLOBAL.getLanguage();
-
- static{
- assert CODE639_PRIMARY.equals("ja");
- assert CODE639_GLOBAL .equals("en");
- }
-
- private final Map nameMap = new HashMap();
-
- /**
- * ã³ã³ã¹ãã©ã¯ã¿ã
- */
- public I18nText(){
- super();
- return;
- }
-
- /**
- * ãã©ã¤ããªæååã®ç»é²ã
- * @param seq ãã©ã¤ããªæååãnullã®å ´åã¯åé¤åä½
- */
- public void setPrimaryText(CharSequence seq){
- setText(CODE639_PRIMARY, seq);
- return;
- }
-
- /**
- * ã°ãã¼ãã«æååã®ç»é²ã
- * @param seq ã°ãã¼ãã«æååãnullã®å ´åã¯åé¤åä½
- */
- public void setGlobalText(CharSequence seq){
- setText(CODE639_GLOBAL, seq);
- return;
- }
-
- /**
- * ä»»æã®ãã±ã¼ã«ã«é¢é£ä»ããããæååã®ç»é²ã
- * @param locale ãã±ã¼ã«
- * @param seq æååãnullã®å ´åã¯åé¤åä½
- * @throws NullPointerException ãã±ã¼ã«å¼æ°ãnull
- */
- public void setText(Locale locale, CharSequence seq)
- throws NullPointerException{
- String code639 = locale.getLanguage();
- setText(code639, seq);
- return;
- }
-
- /**
- * ä»»æã®è¨èªã³ã¼ãã«é¢é£ä»ããããæååã®ç»é²ã
- * @param code639 ISO639è¨èªã³ã¼ã
- * @param seq æååãnullã®å ´åã¯åé¤åä½
- * @throws NullPointerException è¨èªã³ã¼ããnull
- */
- public void setText(String code639, CharSequence seq)
- throws NullPointerException{
- if(code639 == null) throw new NullPointerException();
-
- if(seq != null){
- String text = seq.toString();
- this.nameMap.put(code639, text);
- }else{
- this.nameMap.remove(code639);
- }
-
- return;
- }
-
- /**
- * è¨èªã³ã¼ãã«å¿ããæååãè¿ãã
- * @param code639 ISO639è¨èªã³ã¼ã
- * @return æååãè¦ã¤ãããªããã°nullãè¿ãã
- * @throws NullPointerException å¼æ°ãnull
- */
- public String getText(String code639) throws NullPointerException{
- if(code639 == null) throw new NullPointerException();
- String result = this.nameMap.get(code639);
- return result;
- }
-
- /**
- * ãã±ã¼ã«ã«å¿ããæååãè¿ãã
- * @param locale ãã±ã¼ã«
- * @return æååãè¦ã¤ãããªããã°nullãè¿ãã
- * @throws NullPointerException å¼æ°ãnull
- */
- public String getText(Locale locale) throws NullPointerException{
- String code639 = locale.getLanguage();
- String result = getText(code639);
- return result;
- }
-
- /**
- * ãã©ã¤ããªæååãè¿ãã
- * @return æååãè¦ã¤ãããªããã°nullãè¿ãã
- */
- public String getPrimaryText(){
- String result = getText(CODE639_PRIMARY);
- return result;
- }
-
- /**
- * ã°ãã¼ãã«æååãè¿ãã
- * @return æååãè¦ã¤ãããªããã°nullãè¿ãã
- */
- public String getGlobalText(){
- String result = getText(CODE639_GLOBAL);
- return result;
- }
-
- /**
- * ãã©ã¤ããªæååãè¿ãã
- * è¦ã¤ãããªããã°ã°ãã¼ãã«æååãè¿ãã
- * ããã§ãè¦ã¤ãããªããã°ç©ºæååãè¿ãã
- * @return æåå
- */
- public String getText(){
- String result;
-
- result = getPrimaryText();
-
- if(result == null){
- result = getGlobalText();
- }
-
- if(result == null){
- result = "";
- }
-
- return result;
- }
-
- /**
- * å®è¡ç°å¢ã®ããã©ã«ããã±ã¼ã«ã«å¿ããæååãè¿ãã
- * è¦ã¤ãããªããã°ã°ãã¼ãã«æååããã©ã¤ããªæååã®é ã«è¿ãã
- * ããã§ãè¦ã¤ãããªããã°é©å½ãªè¨èªã³ã¼ãã®æååãè¿ãã
- * ããã§ãè¦ã¤ãããªããã°ç©ºæååãè¿ãã
- * ããã©ã«ããã±ã¼ã«ã®ç¢ºèªã¯ãã®é½åº¦è¡ãããã
- * @return æåå
- */
- public String getLocalizedText(){
- Locale locale = Locale.getDefault();
- String langCode = locale.getLanguage();
-
- String result;
-
- result = this.nameMap.get(langCode);
-
- if(result == null){
- result = this.nameMap.get(CODE639_GLOBAL);
- }
-
- if(result == null){
- result = this.nameMap.get(CODE639_PRIMARY);
- }
-
- if(result == null){
- Set langSet = this.nameMap.keySet();
- Iterator it = langSet.iterator();
- while(it.hasNext()){
- String lang = it.next();
- result = this.nameMap.get(lang);
- if(result != null) break;
- }
- }
-
- if(result == null){
- result = "";
- }
-
- return result;
- }
-
- /**
- * å
¨è¨èªã®æååãåé¤ããã
- */
- public void removeAllText(){
- this.nameMap.clear();
- return;
- }
-
- /**
- * ç»é²æ¸ã¿ã®å
¨ISO639è¨èªã³ã¼ããªã¹ããè¿ãã
- * åªå
度ã¯ãã©ã¤ããªãã°ãã¼ãã«ããã®ä»ã®é ã
- * @return å
¨ISO639è¨èªã³ã¼ã
- */
- public List lang639CodeList(){
- Set set = this.nameMap.keySet();
- List result = new ArrayList(set.size());
-
- for(String lang : set){
- if(lang.equals(CODE639_PRIMARY)) result.add(lang);
- }
-
- for(String lang : set){
- if(lang.equals(CODE639_GLOBAL)) result.add(lang);
- }
-
- for(String lang : set){
- if(lang.equals(CODE639_PRIMARY)) continue;
- if(lang.equals(CODE639_GLOBAL)) continue;
- result.add(lang);
- }
-
- return result;
- }
-
- /**
- * ãã©ã¤ããªæååãç»é²ããã¦ãããå¤å®ããã
- * @return ç»é²ããã¦ããã°true
- */
- public boolean hasPrimaryText(){
- boolean result = this.nameMap.containsKey(CODE639_PRIMARY);
- return result;
- }
-
- /**
- * ã°ãã¼ãã«æååãç»é²ããã¦ãããå¤å®ããã
- * @return ç»é²ããã¦ããã°true
- */
- public boolean hasGlobalText(){
- boolean result = this.nameMap.containsKey(CODE639_GLOBAL);
- return result;
- }
-
- /**
- * {@inheritDoc}
- * {@link #getText()}ã«æºããã
- * @param index {@inheritDoc}
- * @return {@inheritDoc}
- */
- @Override
- public char charAt(int index){
- String text = getText();
- char result = text.charAt(index);
- return result;
- }
-
- /**
- * {@inheritDoc}
- * {@link #getText()}ã«æºããã
- * @return {@inheritDoc}
- */
- @Override
- public int length(){
- String text = getText();
- int result = text.length();
- return result;
- }
-
- /**
- * {@inheritDoc}
- * {@link #getText()}ã«æºããã
- * @param start {@inheritDoc}
- * @param end {@inheritDoc}
- * @return {@inheritDoc}
- */
- @Override
- public CharSequence subSequence(int start, int end){
- String text = getText();
- CharSequence result = text.subSequence(start, end);
- return result;
- }
-
- /**
- * {@inheritDoc}
- * {@link #getText()}ã«æºããã
- * @return {@inheritDoc}
- */
- @Override
- public String toString(){
- return getText();
- }
-
-}
+/*
+ * international text
+ *
+ * License : The MIT License
+ * Copyright(c) 2010 MikuToga Partners
+ */
+
+package jp.sourceforge.mikutoga.corelib;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * å¤è¨èªã®ããªã¢ã³ããæã¤æååæ
å ±ã
+ *
+ * - ãã©ã¤ããªï¼èå¥åã«ã¯ãã¡ãã使ããåºæ¬ã¯æ¥æ¬èªã
+ *
- ã°ãã¼ãã«ï¼åºæ¬ã¯è±èªãUCS Basic-Latinãªã³ãªã¼ã®è²§å¼±ãªè¨èªç°å¢ã§ã
+ * èªããæååãæã¾ããã
+ *
- ãã®ä»ï¼å¿
è¦ã«å¿ãã¦å¥½ããªè¨èªãã
+ *
+ */
+public class I18nText implements CharSequence {
+
+ /** ãã©ã¤ããªè¨èªã®ãã±ã¼ã«ã */
+ public static final Locale LOCALE_PRIMARY = Locale.JAPANESE;
+ /** ãã©ã¤ããªè¨èªã®è¨èªã³ã¼ãã */
+ public static final String CODE639_PRIMARY = LOCALE_PRIMARY.getLanguage();
+
+ /** ã°ãã¼ãã«è¨èªã®ãã±ã¼ã«ã */
+ public static final Locale LOCALE_GLOBAL = Locale.ENGLISH;
+ /** ã°ãã¼ãã«è¨èªã®è¨èªã³ã¼ãã */
+ public static final String CODE639_GLOBAL = LOCALE_GLOBAL.getLanguage();
+
+ static{
+ assert CODE639_PRIMARY.equals("ja");
+ assert CODE639_GLOBAL .equals("en");
+ }
+
+ private final Map nameMap = new HashMap();
+
+ /**
+ * ã³ã³ã¹ãã©ã¯ã¿ã
+ */
+ public I18nText(){
+ super();
+ return;
+ }
+
+ /**
+ * ãã©ã¤ããªæååã®ç»é²ã
+ * @param seq ãã©ã¤ããªæååãnullã®å ´åã¯åé¤åä½
+ */
+ public void setPrimaryText(CharSequence seq){
+ setText(CODE639_PRIMARY, seq);
+ return;
+ }
+
+ /**
+ * ã°ãã¼ãã«æååã®ç»é²ã
+ * @param seq ã°ãã¼ãã«æååãnullã®å ´åã¯åé¤åä½
+ */
+ public void setGlobalText(CharSequence seq){
+ setText(CODE639_GLOBAL, seq);
+ return;
+ }
+
+ /**
+ * ä»»æã®ãã±ã¼ã«ã«é¢é£ä»ããããæååã®ç»é²ã
+ * @param locale ãã±ã¼ã«
+ * @param seq æååãnullã®å ´åã¯åé¤åä½
+ * @throws NullPointerException ãã±ã¼ã«å¼æ°ãnull
+ */
+ public void setText(Locale locale, CharSequence seq)
+ throws NullPointerException{
+ String code639 = locale.getLanguage();
+ setText(code639, seq);
+ return;
+ }
+
+ /**
+ * ä»»æã®è¨èªã³ã¼ãã«é¢é£ä»ããããæååã®ç»é²ã
+ * @param code639 ISO639è¨èªã³ã¼ã
+ * @param seq æååãnullã®å ´åã¯åé¤åä½
+ * @throws NullPointerException è¨èªã³ã¼ããnull
+ */
+ public void setText(String code639, CharSequence seq)
+ throws NullPointerException{
+ if(code639 == null) throw new NullPointerException();
+
+ if(seq != null){
+ String text = seq.toString();
+ this.nameMap.put(code639, text);
+ }else{
+ this.nameMap.remove(code639);
+ }
+
+ return;
+ }
+
+ /**
+ * è¨èªã³ã¼ãã«å¿ããæååãè¿ãã
+ * @param code639 ISO639è¨èªã³ã¼ã
+ * @return æååãè¦ã¤ãããªããã°nullãè¿ãã
+ * @throws NullPointerException å¼æ°ãnull
+ */
+ public String getText(String code639) throws NullPointerException{
+ if(code639 == null) throw new NullPointerException();
+ String result = this.nameMap.get(code639);
+ return result;
+ }
+
+ /**
+ * ãã±ã¼ã«ã«å¿ããæååãè¿ãã
+ * @param locale ãã±ã¼ã«
+ * @return æååãè¦ã¤ãããªããã°nullãè¿ãã
+ * @throws NullPointerException å¼æ°ãnull
+ */
+ public String getText(Locale locale) throws NullPointerException{
+ String code639 = locale.getLanguage();
+ String result = getText(code639);
+ return result;
+ }
+
+ /**
+ * ãã©ã¤ããªæååãè¿ãã
+ * @return æååãè¦ã¤ãããªããã°nullãè¿ãã
+ */
+ public String getPrimaryText(){
+ String result = getText(CODE639_PRIMARY);
+ return result;
+ }
+
+ /**
+ * ã°ãã¼ãã«æååãè¿ãã
+ * @return æååãè¦ã¤ãããªããã°nullãè¿ãã
+ */
+ public String getGlobalText(){
+ String result = getText(CODE639_GLOBAL);
+ return result;
+ }
+
+ /**
+ * ãã©ã¤ããªæååãè¿ãã
+ * è¦ã¤ãããªããã°ã°ãã¼ãã«æååãè¿ãã
+ * ããã§ãè¦ã¤ãããªããã°ç©ºæååãè¿ãã
+ * @return æåå
+ */
+ public String getText(){
+ String result;
+
+ result = getPrimaryText();
+
+ if(result == null){
+ result = getGlobalText();
+ }
+
+ if(result == null){
+ result = "";
+ }
+
+ return result;
+ }
+
+ /**
+ * å®è¡ç°å¢ã®ããã©ã«ããã±ã¼ã«ã«å¿ããæååãè¿ãã
+ * è¦ã¤ãããªããã°ã°ãã¼ãã«æååããã©ã¤ããªæååã®é ã«è¿ãã
+ * ããã§ãè¦ã¤ãããªããã°é©å½ãªè¨èªã³ã¼ãã®æååãè¿ãã
+ * ããã§ãè¦ã¤ãããªããã°ç©ºæååãè¿ãã
+ * ããã©ã«ããã±ã¼ã«ã®ç¢ºèªã¯ãã®é½åº¦è¡ãããã
+ * @return æåå
+ */
+ public String getLocalizedText(){
+ Locale locale = Locale.getDefault();
+ String langCode = locale.getLanguage();
+
+ String result;
+
+ result = this.nameMap.get(langCode);
+
+ if(result == null){
+ result = this.nameMap.get(CODE639_GLOBAL);
+ }
+
+ if(result == null){
+ result = this.nameMap.get(CODE639_PRIMARY);
+ }
+
+ if(result == null){
+ Set langSet = this.nameMap.keySet();
+ Iterator it = langSet.iterator();
+ while(it.hasNext()){
+ String lang = it.next();
+ result = this.nameMap.get(lang);
+ if(result != null) break;
+ }
+ }
+
+ if(result == null){
+ result = "";
+ }
+
+ return result;
+ }
+
+ /**
+ * å
¨è¨èªã®æååãåé¤ããã
+ */
+ public void removeAllText(){
+ this.nameMap.clear();
+ return;
+ }
+
+ /**
+ * ç»é²æ¸ã¿ã®å
¨ISO639è¨èªã³ã¼ããªã¹ããè¿ãã
+ * åªå
度ã¯ãã©ã¤ããªãã°ãã¼ãã«ããã®ä»ã®é ã
+ * @return å
¨ISO639è¨èªã³ã¼ã
+ */
+ public List lang639CodeList(){
+ Set set = this.nameMap.keySet();
+ List result = new ArrayList(set.size());
+
+ for(String lang : set){
+ if(lang.equals(CODE639_PRIMARY)) result.add(lang);
+ }
+
+ for(String lang : set){
+ if(lang.equals(CODE639_GLOBAL)) result.add(lang);
+ }
+
+ for(String lang : set){
+ if(lang.equals(CODE639_PRIMARY)) continue;
+ if(lang.equals(CODE639_GLOBAL)) continue;
+ result.add(lang);
+ }
+
+ return result;
+ }
+
+ /**
+ * ãã©ã¤ããªæååãç»é²ããã¦ãããå¤å®ããã
+ * @return ç»é²ããã¦ããã°true
+ */
+ public boolean hasPrimaryText(){
+ boolean result = this.nameMap.containsKey(CODE639_PRIMARY);
+ return result;
+ }
+
+ /**
+ * ã°ãã¼ãã«æååãç»é²ããã¦ãããå¤å®ããã
+ * @return ç»é²ããã¦ããã°true
+ */
+ public boolean hasGlobalText(){
+ boolean result = this.nameMap.containsKey(CODE639_GLOBAL);
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ * {@link #getText()}ã«æºããã
+ * @param index {@inheritDoc}
+ * @return {@inheritDoc}
+ */
+ @Override
+ public char charAt(int index){
+ String text = getText();
+ char result = text.charAt(index);
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ * {@link #getText()}ã«æºããã
+ * @return {@inheritDoc}
+ */
+ @Override
+ public int length(){
+ String text = getText();
+ int result = text.length();
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ * {@link #getText()}ã«æºããã
+ * @param start {@inheritDoc}
+ * @param end {@inheritDoc}
+ * @return {@inheritDoc}
+ */
+ @Override
+ public CharSequence subSequence(int start, int end){
+ String text = getText();
+ CharSequence result = text.subSequence(start, end);
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ * {@link #getText()}ã«æºããã
+ * @return {@inheritDoc}
+ */
+ @Override
+ public String toString(){
+ return getText();
+ }
+
+}