本文整理匯總了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);
}