Java8在我的JPA EclipseLink 2.5.2环境中继续做一些奇怪的事情.我不得不删除问题/sf/ask/1876432841/ 昨天,因为在这种情况下的排序受到奇怪的JPA行为的影响 - 我通过强迫在进行最终排序之前的第一个排序步骤.
仍然在Java 8中使用JPA Eclipselink 2.5.2,以下代码有时不会在我的环境中排序(Linux,MacOSX,两者都使用build 1.8.0_25-b17).它在JDK 1.7环境中按预期工作.
public List<Document> getDocumentsByModificationDate() {
List<Document> docs=this.getDocuments();
LOGGER.log(Level.INFO,"sorting "+docs.size()+" by modification date");
Comparator<Document> comparator=new ByModificationComparator();
Collections.sort(docs,comparator);
return docs;
}
Run Code Online (Sandbox Code Playgroud)
从JUnit测试调用时,上述函数正常工作.在生产环境中进行debbuging时,我会得到一个日志条目:
INFORMATION: sorting 34 by modification date
Run Code Online (Sandbox Code Playgroud)
但是在TimSort中,nRemaining <2的返回语句被命中 - 因此不会发生排序.JPA提供的IndirectList(请参阅jpa返回的集合?)被认为是空的.
static <T> void sort(T[] a, int lo, int hi, Comparator<? super T> c,
T[] work, int workBase, int workLen) {
assert c != null && a != null && lo >= 0 && lo <= hi …Run Code Online (Sandbox Code Playgroud) 我想过滤signedOn 字段为空的所有传输。当我运行第一段代码时,很清楚哪些是空的,哪些不是,并且它们被正确记录,但是当我运行流过滤器时,它返回一个空列表,我似乎无法找到问题所在它... signedOn 是一个日期字段。
这有效并记录所有条目是否为空:
for (Transfer transfer : route.getTransferCollection()) {
if (transfer.getSignedOn() == null) {
logInfo("This transfer is null");
} else if (transfer.getSignedOn() != null) {
logInfo("This transfer is not null");
}
}
Run Code Online (Sandbox Code Playgroud)
这将返回一个空列表:
return route.getTransferCollection()
.stream()
.filter(transfer -> transfer.getSignedOn() == null)
.collect(Collectors.toList());
}
Run Code Online (Sandbox Code Playgroud)