Example usage for com.google.common.collect Ordering max

List of usage examples for com.google.common.collect Ordering max

Introduction

In this page you can find the example usage for com.google.common.collect Ordering max.

Prototype

public <E extends T> E max(Iterable<E> iterable) 

Source Link

Document

Returns the greatest of the specified values according to this ordering.

Usage

From source file:org.apache.cassandra.db.commitlog.ReplayPosition.java

/**
 * Convenience method to compute the replay position for a group of SSTables.
 * @param sstables//from ww w  . j a va 2 s .co m
 * @return the most recent (highest) replay position
 */
public static ReplayPosition getReplayPosition(Iterable<? extends SSTable> sstables) {
    if (Iterables.isEmpty(sstables))
        return NONE;

    Function<SSTable, ReplayPosition> f = new Function<SSTable, ReplayPosition>() {
        public ReplayPosition apply(SSTable sstable) {
            return sstable.replayPosition;
        }
    };
    Ordering<ReplayPosition> ordering = Ordering.from(ReplayPosition.comparator);
    return ordering.max(Iterables.transform(sstables, f));
}

From source file:task3.Task3.java

static Book getMaxPrice(List<Book> books) {
    Ordering<Book> o = new Ordering<Book>() {
        @Override//from  w  w  w.  j  a va  2s .  c o m
        public int compare(Book left, Book right) {
            return Floats.compare(left.getPrice(), right.getPrice());
        }
    };
    return o.max(books);
}

From source file:garmintools.util.SizeUtil.java

public static <T> int getLargest(List<T> list, final Function<T, Integer> sizeOf) {
    Ordering<T> sizeOrdering = new Ordering<T>() {
        @Override//from  w ww  . j a v a2s  .  c o m
        public int compare(T left, T right) {
            return Ints.compare(sizeOf.apply(left), sizeOf.apply(right));
        }
    };
    return sizeOf.apply(sizeOrdering.max(list));
}

From source file:org.jpmml.evaluator.Classification.java

static public Map.Entry<String, Double> getWinner(Type type, Collection<Map.Entry<String, Double>> entries) {
    Ordering<Map.Entry<String, Double>> ordering = createOrdering(type);

    try {/* w  w w . j  a  va2 s . co m*/
        return ordering.max(entries);
    } catch (NoSuchElementException nsee) {
        return null;
    }
}

From source file:com.my.batch.controller.JobOperationsController.java

@RequestMapping(value = "job/{jobName}", method = RequestMethod.DELETE)
public JsonResponse stop(@PathVariable String jobName)
        throws NoSuchJobExecutionException, JobExecutionNotRunningException, NoSuchJobException {
    Set<Long> executions = jobOperator.getRunningExecutions(jobName);
    Ordering<Long> orders = Ordering.natural();
    //      List<Long> executionLists = orders.greatestOf(executions,10);
    jobOperator.stop(orders.max(executions));
    return JsonResponse.createSuccess();
}

From source file:com.my.batch.controller.JobOperationsController.java

@RequestMapping(value = "job/{jobName}", method = RequestMethod.PUT)
public JsonResponse reStart(@PathVariable String jobName)
        throws NoSuchJobExecutionException, JobExecutionNotRunningException, NoSuchJobException,
        JobRestartException, JobParametersInvalidException, JobInstanceAlreadyCompleteException {
    Set<Long> executions = jobOperator.getRunningExecutions(jobName);
    Ordering<Long> orders = Ordering.natural();
    //      List<Long> executionLists = orders.greatestOf(executions,10);
    jobOperator.restart(orders.max(executions));
    return JsonResponse.createSuccess();
}

From source file:com.google.gerrit.server.account.VersionedAuthorizedKeys.java

/**
 * Sets new SSH keys./*from  w w  w  . java2 s.  c o m*/
 *
 * <p>The existing SSH keys are overwritten.
 *
 * @param newKeys the new public SSH keys
 */
public void setKeys(Collection<AccountSshKey> newKeys) {
    Ordering<AccountSshKey> o = Ordering.from(comparing(k -> k.getKey().get()));
    keys = new ArrayList<>(Collections.nCopies(o.max(newKeys).getKey().get(), Optional.empty()));
    for (AccountSshKey key : newKeys) {
        keys.set(key.getKey().get() - 1, Optional.of(key));
    }
}

From source file:uk.ac.open.kmi.iserve.discovery.disco.impl.OperationDataflowMatcher.java

/**
 * Perform a match between two URIs (from {@code origin} to {@code destination})
 * and returns the result./*from  ww w . java2  s.  co  m*/
 *
 * @param origin      URI of the element to match
 * @param destination URI of the element to match against
 * @return {@link uk.ac.open.kmi.iserve.discovery.api.MatchResult} with the result of the matching.
 */
@Override
public MatchResult match(URI origin, URI destination) {

    Set<URI> originOutputs = this.serviceManager.listOutputs(origin);
    Set<URI> destinationInputs = this.serviceManager.listInputs(destination);

    // Obtain all combinations of matches
    Table<URI, URI, MatchResult> matches = this.conceptMatcher.match(originOutputs, destinationInputs);
    // Collect the best match results for each of the destination's inputs
    // We should try and maximise the fulfillment of destination's inputs rather than be guided by the origin outputs
    ImmutableSet.Builder<MatchResult> builder = ImmutableSet.builder();

    for (Map.Entry<URI, Map<URI, MatchResult>> entry : matches.columnMap().entrySet()) {
        Map<URI, MatchResult> matchesMap = entry.getValue();
        Ordering<URI> valueComparator = Ordering.from(MatchResultComparators.BY_TYPE)
                .onResultOf(Functions.forMap(matchesMap)) // Order by value
                .compound(Ordering.natural()); // Order by URI eventually

        URI bestMatchUri = valueComparator.max(matchesMap.keySet());
        log.info("The best match for {} is {}, with a Match Result of {}", entry.getKey(), bestMatchUri,
                matchesMap.get(bestMatchUri).getMatchType());

        builder.add(matchesMap.get(bestMatchUri));
    }

    MatchResult result = INTERSECTION.apply(builder.build());
    log.info("Combined match result - {}", result);
    return result;
}

From source file:com.nirima.jenkins.SelectionTypeProject.java

private int getPromotedBuildNumber(final String project, final String promoted) {
    BuildableItemWithBuildWrappers item = getProject(project);

    Iterable<AbstractBuild> promotedItems = Iterables.filter(item.asProject().getBuilds(), new Predicate() {
        public boolean apply(Object o) {
            AbstractBuild abstractBuild = (AbstractBuild) o;

            PromotedBuildAction pba = abstractBuild.getAction(PromotedBuildAction.class);
            return (pba != null && pba.getPromotion(promoted) != null);

        }/*from ww w.  j a v a2  s.  co m*/
    });

    Ordering<AbstractBuild> ordering = new Ordering<AbstractBuild>() {
        @Override
        public int compare(AbstractBuild l, AbstractBuild r) {
            return r.getNumber() - l.getNumber();
        }
    };

    try {
        return ordering.max(promotedItems).getNumber();
    } catch (Exception ex) {
        throw new RuntimeException("No promotion of type " + promoted + " in project " + project);
    }
}

From source file:com.google.gerrit.server.schema.Schema_124.java

private Collection<AccountSshKey> fixInvalidSequenceNumbers(Collection<AccountSshKey> keys) {
    Ordering<AccountSshKey> o = Ordering.from(comparing(k -> k.getKey().get()));
    List<AccountSshKey> fixedKeys = new ArrayList<>(keys);
    AccountSshKey minKey = o.min(keys);/*  w  w w.j av a  2 s  .  c o m*/
    while (minKey.getKey().get() <= 0) {
        AccountSshKey fixedKey = new AccountSshKey(new AccountSshKey.Id(minKey.getKey().getParentKey(),
                Math.max(o.max(keys).getKey().get() + 1, 1)), minKey.getSshPublicKey());
        Collections.replaceAll(fixedKeys, minKey, fixedKey);
        minKey = o.min(fixedKeys);
    }
    return fixedKeys;
}