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

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

Introduction

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

Prototype

@GwtCompatible(serializable = true)
@Deprecated
public static <T> Ordering<T> from(Ordering<T> ordering) 

Source Link

Document

Simply returns its argument.

Usage

From source file:com.cloudera.oryx.ml.serving.als.MostSurprising.java

@GET
@Path("{userID}")
@Produces({ CSVMessageBodyWriter.TEXT_CSV, MediaType.APPLICATION_JSON })
public List<IDValue> get(@PathParam("userID") String userID,
        @DefaultValue("10") @QueryParam("howMany") int howMany,
        @DefaultValue("0") @QueryParam("offset") int offset) throws OryxServingException {

    check(howMany > 0, "howMany must be positive");
    check(offset >= 0, "offset must be nonnegative");

    ALSServingModel model = getALSServingModel();
    float[] userVector = model.getUserVector(userID);
    checkExists(userVector != null, userID);
    List<Pair<String, float[]>> knownItemVectors = model.getKnownItemVectorsForUser(userID);
    checkExists(knownItemVectors != null, userID);

    Iterable<Pair<String, Double>> idDots = Iterables.transform(knownItemVectors, new DotsFunction(userVector));

    Ordering<Pair<?, Double>> ordering = Ordering.from(PairComparators.<Double>bySecond());
    return toIDValueResponse(ordering.leastOf(idDots, howMany + offset), howMany, offset);
}

From source file:com.cloudera.oryx.app.serving.als.MostSurprising.java

@GET
@Path("{userID}")
@Produces({ MediaType.TEXT_PLAIN, CSVMessageBodyWriter.TEXT_CSV, MediaType.APPLICATION_JSON })
public List<IDValue> get(@PathParam("userID") String userID,
        @DefaultValue("10") @QueryParam("howMany") int howMany,
        @DefaultValue("0") @QueryParam("offset") int offset) throws OryxServingException {

    check(howMany > 0, "howMany must be positive");
    check(offset >= 0, "offset must be nonnegative");

    ALSServingModel model = getALSServingModel();
    float[] userVector = model.getUserVector(userID);
    checkExists(userVector != null, userID);
    List<Pair<String, float[]>> knownItemVectors = model.getKnownItemVectorsForUser(userID);
    checkExists(knownItemVectors != null, userID);

    Iterable<Pair<String, Double>> idDots = Iterables.transform(knownItemVectors, new DotsFunction(userVector));

    Ordering<Pair<?, Double>> ordering = Ordering.from(PairComparators.<Double>bySecond());
    return toIDValueResponse(ordering.leastOf(idDots, howMany + offset), howMany, offset);
}

From source file:org.eclipse.mylyn.internal.tasks.ui.OptionsProposalProvider.java

@Override
public IContentProposal[] getProposals(String contents, int position) {
    Set<String> filteredProposals = new HashSet<>(proposals);
    filteredProposals.remove(""); //$NON-NLS-1$
    String lastValue = ""; //$NON-NLS-1$
    // If the attribute is of type multi-select, filter the past values from the proposals
    if (isMultiSelect) {
        String[] contentsArray = contents.split(VALUE_SEPARATOR, -1);
        if (contentsArray.length > 0) {
            List<String> trimmedContents = LabelsAttributeEditor.getTrimmedValues(contentsArray);
            filteredProposals.removeAll(trimmedContents);
            lastValue = contentsArray[contentsArray.length - 1].trim();
        }/*from ww w .  j a va2  s  .co  m*/
    } else {
        lastValue = contents;
    }

    // If there is a last value, then filter the remaining the proposals to contain it
    if (!lastValue.isEmpty()) {
        for (Iterator<String> iterator = filteredProposals.iterator(); iterator.hasNext();) {
            String proposal = iterator.next();
            if (!proposal.toLowerCase().contains(lastValue.toLowerCase())) {
                iterator.remove();
            }

        }
    }
    // Since the contents of the editor is replaced, we need to include the existing values in the replacement
    final String existingValues = contents.substring(0, contents.length() - lastValue.length());
    ImmutableList<String> sortedProposals = FluentIterable.from(filteredProposals)
            .toSortedList(Ordering.from(String.CASE_INSENSITIVE_ORDER));
    return FluentIterable.from(sortedProposals).transform(new Function<String, IContentProposal>() {
        public IContentProposal apply(String proposal) {
            return new ContentProposal(existingValues + proposal, proposal, null);
        }
    }).toArray(IContentProposal.class);
}

From source file:org.obm.push.mail.BodyPreferencePolicy.java

public FetchInstruction selectBetterFit(List<FetchInstruction> fetchInstructions,
        List<BodyPreference> bodyPreferences) {
    if (fetchInstructions.isEmpty()) {
        return null;
    }//from  w w w. j a  v  a2s. c o m
    return Ordering.from(betterFitComparator(bodyPreferences)).min(fetchInstructions);
}

From source file:org.fenixedu.parking.ui.Action.externalServices.ExportParkingData.java

private ParkingDataReportFile getLastParkingDataReportJob() {
    Set<QueueJob> parkingJobs = new HashSet<QueueJob>();
    for (QueueJob queueJob : Bennu.getInstance().getQueueJobSet()) {
        if (queueJob instanceof ParkingDataReportFile && queueJob.getDone()) {
            parkingJobs.add(queueJob);//from  w w  w.ja  v  a 2s  .  c  o  m
        }
    }

    return parkingJobs.size() > 0
            ? (ParkingDataReportFile) Ordering.from(new BeanComparator("requestDate")).max(parkingJobs)
            : null;
}

From source file:io.druid.query.select.SelectQueryQueryToolChest.java

@Override
public QueryRunner<Result<SelectResultValue>> mergeResults(QueryRunner<Result<SelectResultValue>> queryRunner) {
    return new ResultMergeQueryRunner<Result<SelectResultValue>>(queryRunner) {
        @Override//from w  ww .j a  v a  2 s.co m
        protected Ordering<Result<SelectResultValue>> makeOrdering(Query<Result<SelectResultValue>> query) {
            return Ordering.from(new ResultGranularTimestampComparator<SelectResultValue>(
                    ((SelectQuery) query).getGranularity()));
        }

        @Override
        protected BinaryFn<Result<SelectResultValue>, Result<SelectResultValue>, Result<SelectResultValue>> createMergeFn(
                Query<Result<SelectResultValue>> input) {
            SelectQuery query = (SelectQuery) input;
            return new SelectBinaryFn(query.getGranularity(), query.getPagingSpec());
        }
    };
}

From source file:io.druid.query.timeseries.TimeseriesQueryQueryToolChest.java

@Override
public QueryRunner<Result<TimeseriesResultValue>> mergeResults(
        QueryRunner<Result<TimeseriesResultValue>> queryRunner) {
    return new ResultMergeQueryRunner<Result<TimeseriesResultValue>>(queryRunner) {
        @Override// ww w. ja v a2  s  .  c  o m
        protected Ordering<Result<TimeseriesResultValue>> makeOrdering(
                Query<Result<TimeseriesResultValue>> query) {
            return Ordering.from(new ResultGranularTimestampComparator<TimeseriesResultValue>(
                    ((TimeseriesQuery) query).getGranularity()));
        }

        @Override
        protected BinaryFn<Result<TimeseriesResultValue>, Result<TimeseriesResultValue>, Result<TimeseriesResultValue>> createMergeFn(
                Query<Result<TimeseriesResultValue>> input) {
            TimeseriesQuery query = (TimeseriesQuery) input;
            return new TimeseriesBinaryFn(query.getGranularity(), query.getAggregatorSpecs());
        }
    };
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.teacher.ShowProfessorshipsDA.java

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    final String executionPeriodIDString = request.getParameter("executionPeriodID");

    final ExecutionSemester selectedExecutionPeriod;
    if (executionPeriodIDString == null) {
        selectedExecutionPeriod = ExecutionSemester.readActualExecutionSemester();
    } else if (executionPeriodIDString.isEmpty()) {
        selectedExecutionPeriod = null;//  w  w  w . j  a  va  2s.c o  m
    } else {
        selectedExecutionPeriod = FenixFramework.getDomainObject(executionPeriodIDString);
    }
    request.setAttribute("executionPeriod", selectedExecutionPeriod);

    final List<ExecutionCourse> executionCourses = new ArrayList<ExecutionCourse>();
    request.setAttribute("executionCourses", executionCourses);

    final Person person = AccessControl.getPerson();
    final SortedSet<ExecutionSemester> executionSemesters = new TreeSet<ExecutionSemester>(
            Ordering.from(ExecutionSemester.COMPARATOR_BY_SEMESTER_AND_YEAR).reverse());
    if (person != null) {
        for (final Professorship professorship : person.getProfessorshipsSet()) {
            final ExecutionCourse executionCourse = professorship.getExecutionCourse();
            final ExecutionSemester executionSemester = executionCourse.getExecutionPeriod();

            executionSemesters.add(executionSemester);
            if (selectedExecutionPeriod == null || selectedExecutionPeriod == executionSemester) {
                executionCourses.add(executionCourse);
            }
        }
    }
    executionSemesters.add(ExecutionSemester.readActualExecutionSemester());

    request.setAttribute("semesters", executionSemesters);

    return mapping.findForward("list");
}

From source file:ai.grakn.graql.internal.gremlin.spanningtree.datastructure.FibonacciHeap.java

private FibonacciHeap(Comparator<? super P> comparator) {
    // we'll use nulls to force a node to the top when we delete it
    this.comparator = Ordering.from(comparator).nullsFirst();
}

From source file:hu.bme.mit.trainbenchmark.ttc.benchmark.benchmarkcases.AbstractBenchmarkCase.java

public void benchmarkModify() throws IOException {
    final long nElementsToModify = Util.calcModify(br);
    br.addModifiedElementsSize(nElementsToModify);

    // create a sorted copy of the matches
    // we do not measure this in the benchmark results
    final Ordering<Object> ordering = Ordering.from(comparator);
    final List<Object> sortedMatches = ordering.sortedCopy(matches);
    final List<Object> elementsToModify = TransformationUtil.pickRandom(nElementsToModify, sortedMatches);

    // we measure the transformation
    br.restartClock();/*from  w ww . ja va2 s  .co  m*/
    modify(elementsToModify);
    br.addTransformationTime();

    br.addTransformationMemory(getMemoryUsage());
}