比较器如果遇到null则不进行排序

时间:2015-11-24 18:54:38

标签: java eclipse calendar comparator jcr

我正在尝试执行自定义类型的日历对象(从Node类中提取),并在排序时将遇到的任何空值推送到最后。

这是我的代码:

Collections.sort(listofnodes, new CustomComparatorPubDate());

我对上述课程的打电话:

javax.jcr.PathNotFoundException

我有一个测试数组,其中一个object属性被故意留空以进行测试,但这会失败。如果我填充该属性似乎工作正常。

知道出了什么问题以及如何解决这个问题?

P.S:Eclipse不允许我在没有try / catch块的情况下编写它。

编辑:在日志中,我看到它会抛出import time import random def DisplayBands: print("Guess the name of the band out of:") print("One Dimension") print("Take What?") print("Austin Eabier") print("Front Street Lads") now = time.time() return now

1 个答案:

答案 0 :(得分:0)

看起来你有一个小错误,如果d1为null,你在d2之前对它进行排序,即使d2不是空的。

if (d1 == null) return 1;

因此,如果您将此更改为返回-1,则应按照您要查找的方式进行排序。