Java Code Examples for java.util.Comparator.comparingLong()

The following are Jave code examples for showing how to use comparingLong() of the java.util.Comparator class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ARCLib   File: HistoricStore.java   View Source Code Vote up 6 votes
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);
    }
 
Example 2
Project: SECP   File: GroupController.java   View Source Code Vote up 6 votes
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;
}
 
Example 3
Project: openjdk-jdk10   File: BasicTest.java   View Source Code Vote up 6 votes
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);
}
 
Example 4
Project: jdk8u-jdk   File: BasicTest.java   View Source Code Vote up 5 votes
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);
}