本文整理汇总了Java中java.util.Comparator.comparingLong方法的典型用法代码示例。如果您正苦于以下问题:Java Comparator.comparingLong方法的具体用法?Java Comparator.comparingLong怎么用?Java Comparator.comparingLong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Comparator
的用法示例。
在下文中一共展示了Comparator.comparingLong方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRevisions
import java.util.Comparator; //导入方法依赖的package包/类
public List<Revision> getRevisions(String id, Params params) {
AuditReader reader = getAuditReader();
List<Number> revisionNumbers = reader.getRevisions(type, id);
Map<Number, Revision> revisionMap = reader.findRevisions(Revision.class, asSet(revisionNumbers));
Collection<Revision> revisions = revisionMap.values();
Comparator<Revision> timestampComparator = Comparator.comparingLong(Revision::getTimestamp);
Comparator<Revision> authorComparator = Comparator.comparing(Revision::getAuthor);
Comparator<Revision> comparator;
if (AUTHOR.equals(params.getSort())) {
comparator = authorComparator;
} else {
comparator = timestampComparator;
}
if (params.getOrder() == Order.DESC) {
comparator = comparator.reversed();
}
return Ordering.from(comparator)
.sortedCopy(revisions);
}
示例2: getGroupDTOWithMessages
import java.util.Comparator; //导入方法依赖的package包/类
private GroupDTO getGroupDTOWithMessages(Group group)
{
GroupDTO groupDTO = getGroupResponse(group);
group.getMessages().stream().forEach(message ->
{
groupDTO.addMessage(
new MessageDTO(message.getId(),
group.getId(),
message.getUser().getId(),
message.getBody(),
MessageDTO.MessageType.MESSAGE,
message.getTimestamp()));
});
if(!Util.isCollectionEmpty(groupDTO.getMessages())) {
Comparator<MessageDTO> comp = Comparator.comparingLong(MessageDTO::getMessageId);
MessageDTO lastMessage = groupDTO.getMessages().stream().max(comp).get();
groupDTO.setLastMessage(lastMessage);
}
groupDTO.setDisplayName(getDisplayNameForGroup(group));
groupDTO.setAvatarUrl(getAvatarForGroup(group));
return groupDTO;
}
示例3: testLongComparator
import java.util.Comparator; //导入方法依赖的package包/类
public void testLongComparator() {
Thing[] things = new Thing[longValues.length];
for (int i=0; i<longValues.length; i++)
things[i] = new Thing(0, longValues[i], 0.0, null);
Comparator<Thing> comp = Comparator.comparingLong(new ToLongFunction<Thing>() {
@Override
public long applyAsLong(Thing thing) {
return thing.getLongField();
}
});
assertComparisons(things, comp, comparisons);
}