use of java.text.Collator in project j2objc by google.
the class CollatorTest method test_equalsLjava_lang_StringLjava_lang_String.
/**
* @tests java.text.Collator#equals(java.lang.String, java.lang.String)
*/
public void test_equalsLjava_lang_StringLjava_lang_String() {
Collator c = Collator.getInstance(Locale.FRENCH);
c.setStrength(Collator.IDENTICAL);
assertTrue("a) Failed on primary difference", !c.equals("E", "F"));
assertTrue("a) Failed on secondary difference", !c.equals("e", "é"));
assertTrue("a) Failed on tertiary difference", !c.equals("e", "E"));
assertTrue("a) Failed on equivalence", c.equals("e", "e"));
c.setStrength(Collator.TERTIARY);
assertTrue("b) Failed on primary difference", !c.equals("E", "F"));
assertTrue("b) Failed on secondary difference", !c.equals("e", "é"));
assertTrue("b) Failed on tertiary difference", !c.equals("e", "E"));
assertTrue("b) Failed on identical", c.equals("", ""));
assertTrue("b) Failed on equivalence", c.equals("e", "e"));
c.setStrength(Collator.SECONDARY);
assertTrue("c) Failed on primary difference", !c.equals("E", "F"));
assertTrue("c) Failed on secondary difference", !c.equals("e", "é"));
assertTrue("c) Failed on tertiary difference", c.equals("e", "E"));
assertTrue("c) Failed on identical", c.equals("", ""));
assertTrue("c) Failed on equivalence", c.equals("e", "e"));
c.setStrength(Collator.PRIMARY);
assertTrue("d) Failed on primary difference", !c.equals("E", "F"));
assertTrue("d) Failed on secondary difference", c.equals("e", "é"));
assertTrue("d) Failed on tertiary difference", c.equals("e", "E"));
assertTrue("d) Failed on identical", c.equals("", ""));
assertTrue("d) Failed on equivalence", c.equals("e", "e"));
}
use of java.text.Collator in project translationstudio8 by heartsome.
the class ProjectConfiger method getAttrMap.
/**
* 获取配置文件中的项目属性字段信息
* @return
* @throws XPathParseException
* @throws XPathEvalException
* @throws NavException ;
*/
private LinkedHashMap<String, Object[]> getAttrMap() throws XPathParseException, XPathEvalException, NavException {
AutoPilot ap = new AutoPilot(vu.getVTDNav());
Map<String, Object[]> mapAttr = new HashMap<String, Object[]>();
ap.selectXPath("/projectDescription/hs//attributeList/attribute");
AutoPilot ap2 = new AutoPilot(vu.getVTDNav());
final Collator collatorChinese = Collator.getInstance(java.util.Locale.CHINA);
while (ap.evalXPath() != -1) {
String attrName = TextUtil.stringToXML(vu.getCurrentElementAttribut("name", ""));
String attrSelVal = TextUtil.stringToXML(vu.getCurrentElementAttribut("selection", ""));
vu.getVTDNav().push();
ap2.selectXPath("./item");
ArrayList<String> lstAttrVal = new ArrayList<String>();
while (ap2.evalXPath() != -1) {
lstAttrVal.add(vu.getElementContent());
}
vu.getVTDNav().pop();
Collections.sort(lstAttrVal, collatorChinese);
mapAttr.put(attrName, new Object[] { attrSelVal, lstAttrVal });
}
List<Entry<String, Object[]>> lstAttr = new ArrayList<Entry<String, Object[]>>(mapAttr.entrySet());
Collections.sort(lstAttr, new Comparator<Entry<String, Object[]>>() {
public int compare(Entry<String, Object[]> arg0, Entry<String, Object[]> arg1) {
return collatorChinese.compare(arg0.getKey(), arg1.getKey());
}
});
LinkedHashMap<String, Object[]> linkedMapAttr = new LinkedHashMap<String, Object[]>();
for (Entry<String, Object[]> entry : lstAttr) {
linkedMapAttr.put(entry.getKey(), entry.getValue());
}
return linkedMapAttr;
}
use of java.text.Collator in project translationstudio8 by heartsome.
the class ProjectConfiger method getFieldMap.
/**
* 获取配置文件中的项目文本字段信息
* @return
* @throws XPathParseException
* @throws XPathEvalException
* @throws NavException ;
*/
private LinkedHashMap<String, String> getFieldMap() throws XPathParseException, XPathEvalException, NavException {
AutoPilot ap = new AutoPilot(vu.getVTDNav());
Map<String, String> mapField = new HashMap<String, String>();
ap.selectXPath("/projectDescription/hs//fieldList/field");
while (ap.evalXPath() != -1) {
String fieldName = TextUtil.stringToXML(vu.getCurrentElementAttribut("name", ""));
String fieldValue = vu.getElementContent();
mapField.put(fieldName, fieldValue);
}
List<Entry<String, String>> lstAttr = new ArrayList<Entry<String, String>>(mapField.entrySet());
final Collator collatorChinese = Collator.getInstance(java.util.Locale.CHINA);
Collections.sort(lstAttr, new Comparator<Entry<String, String>>() {
public int compare(Entry<String, String> arg0, Entry<String, String> arg1) {
return collatorChinese.compare(arg0.getKey(), arg1.getKey());
}
});
LinkedHashMap<String, String> linkedMapAttr = new LinkedHashMap<String, String>();
for (Entry<String, String> entry : lstAttr) {
linkedMapAttr.put(entry.getKey(), entry.getValue());
}
return linkedMapAttr;
}
use of java.text.Collator in project translationstudio8 by heartsome.
the class PreferenceUtil method getProjectAttributeMap.
/**
* 获取项目属性的属性字段
* @return key 为属性名称,value 为属性值集合
*/
public static LinkedHashMap<String, ArrayList<String>> getProjectAttributeMap() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
HashMap<String, ArrayList<String>> mapAttr = new HashMap<String, ArrayList<String>>();
int attrNameCount = store.getInt("net.heartsome.cat.ts.ui.preferencepage.ProjectPropertiesPreferencePage.attrNameCount");
// 对中文按拼音排序
final Collator collatorChinese = Collator.getInstance(java.util.Locale.CHINA);
LinkedHashMap<String, ArrayList<String>> linkedMapAttr = new LinkedHashMap<String, ArrayList<String>>();
if (attrNameCount > 0) {
for (int i = 0; i < attrNameCount; i++) {
String strAttrName = store.getString("net.heartsome.cat.ts.ui.preferencepage.ProjectPropertiesPreferencePage.attrName" + i);
int attrValCount = store.getInt("net.heartsome.cat.ts.ui.preferencepage.ProjectPropertiesPreferencePage.attrName" + i + ".count");
ArrayList<String> lstAttrVal = new ArrayList<String>();
if (attrValCount > 0) {
for (int j = 0; j < attrValCount; j++) {
lstAttrVal.add(store.getString("net.heartsome.cat.ts.ui.preferencepage.ProjectPropertiesPreferencePage.attrName" + i + ".attrVal" + j));
}
}
Collections.sort(lstAttrVal, collatorChinese);
mapAttr.put(strAttrName, lstAttrVal);
}
List<Entry<String, ArrayList<String>>> lstAttr = new ArrayList<Entry<String, ArrayList<String>>>(mapAttr.entrySet());
Collections.sort(lstAttr, new Comparator<Entry<String, ArrayList<String>>>() {
public int compare(Entry<String, ArrayList<String>> arg0, Entry<String, ArrayList<String>> arg1) {
return collatorChinese.compare(arg0.getKey(), arg1.getKey());
}
});
for (Entry<String, ArrayList<String>> entry : lstAttr) {
linkedMapAttr.put(entry.getKey(), entry.getValue());
}
}
return linkedMapAttr;
}
use of java.text.Collator in project translationstudio8 by heartsome.
the class PreferenceUtil method getProjectFieldList.
/**
* 获取项目属性的文本字段
* @return ;
*/
public static ArrayList<String> getProjectFieldList() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
ArrayList<String> lstField = new ArrayList<String>();
int fieldCount = store.getInt("net.heartsome.cat.ts.ui.preferencepage.ProjectPropertiesPreferencePage.fieldCount");
if (fieldCount > 0) {
for (int i = 0; i < fieldCount; i++) {
lstField.add(store.getString("net.heartsome.cat.ts.ui.preferencepage.ProjectPropertiesPreferencePage.field" + i));
}
}
// 对中文按拼音排序
Collator collatorChinese = Collator.getInstance(java.util.Locale.CHINA);
Collections.sort(lstField, collatorChinese);
return lstField;
}
Aggregations