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

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

Introduction

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

Prototype

@GwtCompatible(serializable = true)
@SuppressWarnings("unchecked") 
public static <C extends Comparable> Ordering<C> natural() 

Source Link

Document

Returns a serializable ordering that uses the natural order of the values.

Usage

From source file:net.sourceforge.fenixedu.domain.Site.java

public List<Section> getOrderedAssociatedSections() {
    return Ordering.natural().sortedCopy(getAssociatedSectionSet());
}

From source file:org.apache.ctakes.temporal.ae.baselines.RecallBaselineEventTimeRelationAnnotator.java

@Override
protected List<IdentifiedAnnotationPair> getCandidateRelationArgumentPairs(JCas jCas, Annotation sentence) {
    List<EventMention> events = JCasUtil.selectCovered(jCas, EventMention.class, sentence);
    List<TimeMention> times = JCasUtil.selectCovered(jCas, TimeMention.class, sentence);

    if (times.size() < 1 || events.size() < 1) {
        return Lists.newArrayList();
    }/*from   w ww .  j  a v  a2 s . co m*/

    // compute token distance for each time-event pair
    HashMap<IdentifiedAnnotationPair, Integer> distanceLookup = new HashMap<IdentifiedAnnotationPair, Integer>();
    for (EventMention event : events) {
        // ignore subclasses like Procedure and Disease/Disorder
        if (event.getClass().equals(EventMention.class)) {
            for (TimeMention time : times) {
                IdentifiedAnnotationPair pair = new IdentifiedAnnotationPair(time, event);
                List<BaseToken> baseTokens = JCasUtil.selectBetween(jCas, BaseToken.class, pair.getArg1(),
                        pair.getArg2());
                int distance = baseTokens.size();
                distanceLookup.put(pair, distance);
            }
        }
    }

    // find the pair where the distance between entities is the smallest and return it
    List<IdentifiedAnnotationPair> rankedPairs = new ArrayList<IdentifiedAnnotationPair>(
            distanceLookup.keySet());
    Function<IdentifiedAnnotationPair, Integer> getValue = Functions.forMap(distanceLookup);
    Collections.sort(rankedPairs, Ordering.natural().onResultOf(getValue));

    List<IdentifiedAnnotationPair> results = new ArrayList<IdentifiedAnnotationPair>();
    Set<EventMention> relTimes = new HashSet<EventMention>();
    for (IdentifiedAnnotationPair result : rankedPairs) {
        if (!relTimes.contains(result.getArg2())) {
            relTimes.add((EventMention) result.getArg2());
            results.add(result);
        }
    }
    return results;
}

From source file:org.apache.ctakes.temporal.ae.baselines.PrecisionBaselineEventTimeRelationAnnotator.java

@Override
public List<IdentifiedAnnotationPair> getCandidateRelationArgumentPairs(JCas jCas, Annotation sentence) {

    List<EventMention> events = JCasUtil.selectCovered(jCas, EventMention.class, sentence);
    List<TimeMention> times = JCasUtil.selectCovered(jCas, TimeMention.class, sentence);

    if (times.size() < 1 || events.size() < 1) {
        return Lists.newArrayList();
    }// w w  w.j  a  va2s  .c o  m

    // compute token distance for each time-event pair
    HashMap<IdentifiedAnnotationPair, Integer> distanceLookup = new HashMap<IdentifiedAnnotationPair, Integer>();
    for (EventMention event : events) {
        // ignore subclasses like Procedure and Disease/Disorder
        if (event.getClass().equals(EventMention.class)) {
            for (TimeMention time : times) {
                IdentifiedAnnotationPair pair = new IdentifiedAnnotationPair(time, event);
                List<BaseToken> baseTokens = JCasUtil.selectBetween(jCas, BaseToken.class, pair.getArg1(),
                        pair.getArg2());
                int distance = baseTokens.size();
                distanceLookup.put(pair, distance);
            }
        }
    }

    // find the pair where the distance between entities is the smallest and return it
    List<IdentifiedAnnotationPair> rankedPairs = new ArrayList<IdentifiedAnnotationPair>(
            distanceLookup.keySet());
    Function<IdentifiedAnnotationPair, Integer> getValue = Functions.forMap(distanceLookup);
    Collections.sort(rankedPairs, Ordering.natural().onResultOf(getValue));

    List<IdentifiedAnnotationPair> results = new ArrayList<IdentifiedAnnotationPair>();

    Set<TimeMention> relTimes = new HashSet<TimeMention>();
    for (IdentifiedAnnotationPair result : rankedPairs) {
        if (!relTimes.contains(result.getArg1())) {
            relTimes.add((TimeMention) result.getArg1());
            results.add(result);
        }
    }

    return results;
}

From source file:com.facebook.buck.android.ExopackageDeviceDirectoryLister.java

@Override
public ImmutableList<? extends Step> getBuildSteps(BuildContext buildContext,
        BuildableContext buildableContext) {
    return ImmutableList.of(new AbstractExecutionStep("listing_exo_contents") {
        @Override/*ww  w.j  a  v  a  2s . c  om*/
        public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException {
            trigger.verify(context);
            ConcurrentHashMap<String, SortedSet<String>> contents = new ConcurrentHashMap<>();
            context.getAndroidDevicesHelper().get().adbCallOrThrow("listing_exo_contents_for_device",
                    (device) -> {
                        device.mkDirP(ExopackageInstaller.EXOPACKAGE_INSTALL_ROOT.toString());
                        contents.put(device.getSerialNumber(),
                                device.listDirRecursive(ExopackageInstaller.EXOPACKAGE_INSTALL_ROOT).stream()
                                        .map(Path::toString)
                                        .collect(ImmutableSortedSet.toImmutableSortedSet(Ordering.natural())));
                        return true;
                    }, true);
            getProjectFilesystem().mkdirs(outputPath.getParent());
            getProjectFilesystem().writeContentsToPath(
                    serializeDirectoryContents(ImmutableSortedMap.copyOf(contents)), outputPath);
            buildableContext.recordArtifact(outputPath);
            return StepExecutionResults.SUCCESS;
        }
    });
}

From source file:net.minecrell.dandelion.ui.MainController.java

private void openFile(Path openedPath) throws IOException {
    closeFile();//from   ww w  .ja v  a 2  s. c o m

    // Create Fernflower context
    this.decompiler = new DandelionDecompiler(openedPath);

    Multimap<ImmutableList<String>, PackageElement> elements = TreeMultimap.create(ListComparator.get(),
            Ordering.natural());

    this.decompiler.getClasses().forEach(path -> {
        if (path.lastIndexOf('$') >= 0) {
            return;
        }

        PackageElement element = PackageElement.fromPath(PackageElement.Type.CLASS, path);
        System.out.println("Found class: " + element.getPath());
        elements.put(element.getPackage(), element);
    });

    for (String path : this.decompiler.getResources()) {
        if (path.endsWith(CLASS_EXTENSION)) {
            continue;
        }

        PackageElement element = PackageElement.fromPath(PackageElement.Type.RESOURCE, path);
        System.out.println("Found resource: " + element.getPath());
        elements.put(element.getPackage(), element);
    }

    elements.asMap().forEach((pack, packageElements) -> {
        TreeItem<PackageElement> root = new TreeItem<>(new PackageElement(PackageElement.Type.PACKAGE, pack));
        for (PackageElement element : packageElements) {
            root.getChildren().add(new TreeItem<>(element));
        }
        this.packageRoot.getChildren().add(root);
    });
}

From source file:org.linagora.linshare.core.facade.webservice.admin.impl.FunctionalityFacadeImpl.java

@Override
public List<FunctionalityAdminDto> findAll(String domainId, String parentId, boolean tree,
        boolean withSubFunctionalities) throws BusinessException {
    User actor = checkAuthentication(Role.ADMIN);
    Validate.notEmpty(domainId, "domain identifier must be set.");
    Iterable<Functionality> entities = service.findAll(actor, domainId, parentId, tree, withSubFunctionalities);
    Iterable<FunctionalityAdminDto> transform = Iterables.transform(entities, FunctionalityAdminDto.toDto());
    // Copy is made because the transaction is closed at the end of every method in facade classes.
    return Ordering.natural().immutableSortedCopy(transform);
}

From source file:org.apache.ctakes.relationextractor.ae.baselines.Baseline2DegreeOfRelationExtractorAnnotator.java

@Override
public List<IdentifiedAnnotationPair> getCandidateRelationArgumentPairs(JCas identifiedAnnotationView,
        Annotation sentence) {/* www  . j a  va  2 s. co m*/

    List<EntityMention> entities = JCasUtil.selectCovered(identifiedAnnotationView, EntityMention.class,
            sentence);
    List<Modifier> modifiers = JCasUtil.selectCovered(identifiedAnnotationView, Modifier.class, sentence);

    // look for sentences with multiple modifiers/arg2s and a single entity/arg1
    if (!(modifiers.size() >= 1 && entities.size() == 1)) {
        return new ArrayList<IdentifiedAnnotationPair>();
    }

    List<IdentifiedAnnotationPair> pairs = new ArrayList<IdentifiedAnnotationPair>();
    for (EntityMention entity : entities) {
        for (Modifier modifier : modifiers) {
            pairs.add(new IdentifiedAnnotationPair(entity, modifier));
        }
    }

    // compute distance between entities for the pairs where entity types are correct
    HashMap<IdentifiedAnnotationPair, Integer> distanceLookup = new HashMap<IdentifiedAnnotationPair, Integer>();
    for (IdentifiedAnnotationPair pair : pairs) {
        if (Utils.validateDegreeOfArgumentTypes(pair)) {
            try {
                int distance = Utils.getDistance(identifiedAnnotationView.getView(CAS.NAME_DEFAULT_SOFA), pair);
                distanceLookup.put(pair, distance);
            } catch (CASException e) {
                System.out.println("couldn't get default sofa");
                break;
            }
        }
    }
    if (distanceLookup.isEmpty()) {
        return new ArrayList<IdentifiedAnnotationPair>(); // no pairs with suitable argument types
    }

    // find the pair where the distance between entities is the smallest and return it
    List<IdentifiedAnnotationPair> rankedPairs = new ArrayList<IdentifiedAnnotationPair>(
            distanceLookup.keySet());
    Function<IdentifiedAnnotationPair, Integer> getValue = Functions.forMap(distanceLookup);
    Collections.sort(rankedPairs, Ordering.natural().onResultOf(getValue));

    List<IdentifiedAnnotationPair> result = new ArrayList<IdentifiedAnnotationPair>();
    result.add(rankedPairs.get(0));

    System.out.println(sentence.getCoveredText());
    System.out.println("arg1: " + result.get(0).getArg1().getCoveredText());
    System.out.println("arg2: " + result.get(0).getArg2().getCoveredText());
    System.out.println();

    return result;
}

From source file:org.sonar.javascript.checks.verifier.JavaScriptCheckVerifier.java

private static Iterator<Issue> getActualIssues(JavaScriptCheck check, JavaScriptVisitorContext context) {
    List<Issue> issues = check.scanFile(context);
    List<Issue> sortedIssues = Ordering.natural().onResultOf(new IssueToLine()).sortedCopy(issues);
    return sortedIssues.iterator();
}

From source file:me.j360.dubbo.modules.util.collection.CollectionUtil.java

/**
 * ?N, guava./*from ww w.j ava 2s . c  o  m*/
 */
public static <T extends Comparable> List<T> bottomN(Iterable<T> coll, int n) {
    return Ordering.natural().leastOf(coll, n);
}

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();
}