当前位置:  开发笔记 > 编程语言 > 正文

用于UTF8字母的JAVA比较器

如何解决《用于UTF8字母的JAVA比较器》经验,为你挑选了0个好方法。

我查了几篇关于比较器的帖子,但我坚持了一点.

我正在使用的比较器:

@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 getProperties() {
        Map properties = new HashMap();
        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

推荐阅读
重庆制造漫画社
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有