我检查了几篇关于比较器的帖子,但我坚持一点。用于UTF8字母的JAVA比较器
比较我现在用:
@Override
public int compare(BaseFolder arg0, BaseFolder arg1) {
try {
Object value1 = arg0.getName();
Object value2 = arg1.getName();
Collator lithuanianCollator = Collator.getInstance(new Locale("lt_LT"));
lithuanianCollator.setStrength(Collator.PRIMARY);
int value = lithuanianCollator.compare(value1.toString(), value2.toString());
return SortOrder.ASCENDING.equals(sortOrder) ? value : -1 * value;
}
catch(Exception e) {
throw new RuntimeException();
}
}
它做排序,但它并不立陶宛字母正常工作,而且我不知道为什么。
编辑:似乎排序依赖于字符串长度,出于某种原因。
例如。
编辑:
public class BaseFolder {
private String id;
private String name;
private String description;
private String lastModifiedBy;
private String lastModificationDate;
private String createdBy;
private String creationDate;
private String parentId;
public BaseFolder() {
}
public BaseFolder(CmisObject obj) {
this.id = obj.getId();
this.name = obj.getName();
this.description = obj.getDescription();
this.lastModificationDate = DateFormatUtils.format(obj.getLastModificationDate().getTime(), "yyyy-MM-dd");
this.lastModifiedBy = obj.getLastModifiedBy();
this.createdBy = obj.getCreatedBy();
this.creationDate = DateFormatUtils.format(obj.getCreationDate().getTime(), "yyyy-MM-dd");
}
public BaseFolder(String id, String name, String description, String parentId) {
super();
this.id = id;
this.name = name;
this.description = description;
this.parentId = parentId;
}
public Map<String, Object> getProperties() {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.PARENT_ID, "cmis:parentId");
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
properties.put(PropertyIds.NAME, getName());
properties.put(PropertyIds.DESCRIPTION, getDescription());
return properties;
}
用java 8,Primefaces,JSF
我想和'VA lue2'类型为Object toString()返回对象的字符串表示形式。你能分享'BaseFolder'的代码吗? – sinclair
排序有什么问题? – reos
编辑:basefolder类。 关于排序。 第一个应该来一个,则A,或我来了,我以前 – iJava