Example usage for com.google.common.collect ImmutableSortedSet orderedBy

List of usage examples for com.google.common.collect ImmutableSortedSet orderedBy

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSortedSet orderedBy.

Prototype

public static <E> Builder<E> orderedBy(Comparator<E> comparator) 

Source Link

Usage

From source file:com.google.caliper.runner.instrument.InstrumentModule.java

private static ImmutableSortedSet<MethodModel> findAllBenchmarkMethods(BenchmarkClassModel benchmarkClass,
        Instrument instrument) throws InvalidBenchmarkException {
    ImmutableSortedSet.Builder<MethodModel> result = ImmutableSortedSet
            .orderedBy(Ordering.natural().onResultOf(new Function<MethodModel, String>() {
                @Override/*from   w  w  w  . j  a va2  s  .c  o  m*/
                public String apply(MethodModel method) {
                    return method.name();
                }
            }));
    Set<String> benchmarkMethodNames = new HashSet<String>();
    Set<String> overloadedMethodNames = new TreeSet<String>();
    for (MethodModel method : benchmarkClass.methods()) {
        if (instrument.isBenchmarkMethod(method)) {
            result.add(method);
            if (!benchmarkMethodNames.add(method.name())) {
                overloadedMethodNames.add(method.name());
            }
        }
    }
    if (!overloadedMethodNames.isEmpty()) {
        throw new InvalidBenchmarkException(
                "Overloads are disallowed for benchmark methods, found overloads of %s in benchmark %s",
                overloadedMethodNames, benchmarkClass.simpleName());
    }
    return result.build();
}

From source file:org.projectbuendia.client.models.LocationTree.java

/**
 * Returns the sorted descendants of the specified location at the specified depth relative to
 * that location./*  w w w  .j  a va2 s .  c om*/
 */
public ImmutableSortedSet<Location> getDescendantsAtDepth(Location location, int relativeDepth) {
    if (location == null) {
        return ImmutableSortedSet.of();
    }

    if (relativeDepth == 0) {
        ImmutableSortedSet.Builder<Location> thisLocationSet = ImmutableSortedSet
                .orderedBy(new LocationComparator(this));
        thisLocationSet.add(location);
        return thisLocationSet.build();
    }

    ImmutableSortedSet.Builder<Location> descendants = ImmutableSortedSet
            .orderedBy(new LocationComparator(this));
    for (Location child : getChildren(location)) {
        descendants.addAll(getDescendantsAtDepth(child, relativeDepth - 1));
    }

    return descendants.build();
}

From source file:com.gradleware.tooling.toolingmodel.repository.internal.DefaultOmniBuildInvocationsContainerBuilder.java

@SuppressWarnings("StringEquality")
private static ImmutableMultimap<Path, OmniTaskSelector> buildTaskSelectorsRecursively(GradleProject project,
        Multimap<Path, OmniTaskSelector> taskSelectorsPerProject, boolean enforceAllTasksPublic) {
    // add task selectors of the current project
    TreeBasedTable<String, Path, String> aggregatedTasksWithDescription = TreeBasedTable
            .create(Ordering.usingToString(), Path.Comparator.INSTANCE);
    Set<String> publicTasks = Sets.newLinkedHashSet();
    collectAllTasksRecursively(project, aggregatedTasksWithDescription, publicTasks, enforceAllTasksPublic);
    for (String selectorName : aggregatedTasksWithDescription.rowKeySet()) {
        SortedMap<Path, String> pathsAndDescriptions = aggregatedTasksWithDescription.row(selectorName);
        String description = pathsAndDescriptions.get(pathsAndDescriptions.firstKey()); // description from project task with smallest path
        SortedSet<Path> fqnTaskNames = ImmutableSortedSet.orderedBy(Path.Comparator.INSTANCE)
                .addAll(pathsAndDescriptions.keySet()).build();

        OmniTaskSelector taskSelector = DefaultOmniTaskSelector.from(selectorName,
                description != NULL_STRING ? description : null, Path.from(project.getPath()),
                publicTasks.contains(selectorName), fqnTaskNames);

        taskSelectorsPerProject.put(Path.from(project.getPath()), taskSelector);
    }/*from   ww w  . jav  a  2  s .  c om*/

    // recurse into child projects and add their task selectors
    DomainObjectSet<? extends GradleProject> childProjects = project.getChildren();
    for (GradleProject childProject : childProjects) {
        buildTaskSelectorsRecursively(childProject, taskSelectorsPerProject, enforceAllTasksPublic);
    }

    // return the task selectors grouped by project path
    return ImmutableMultimap.copyOf(taskSelectorsPerProject);
}

From source file:org.opendaylight.mdsal.binding.javav2.java.api.generator.renderers.BuilderRenderer.java

/**
 * Returns set of method signature instances which contains all the methods of the <code>genType</code>
 * and all the methods of the implemented interfaces.
 *
 * @returns set of method signature instances
 *//*from w ww. j a va  2s. c  om*/
private Set<MethodSignature> createMethods() {
    final Set<MethodSignature> methods = new LinkedHashSet<>();
    methods.addAll(getType().getMethodDefinitions());
    collectImplementedMethods(methods, getType().getImplements());
    final Set<MethodSignature> sortedMethods = ImmutableSortedSet
            .orderedBy(new AlphabeticallyTypeMemberComparator<MethodSignature>()).addAll(methods).build();
    return sortedMethods;
}

From source file:org.gradle.model.internal.typeregistration.BaseInstanceFactory.java

@Override
public Set<ModelType<? extends PUBLIC>> getSupportedTypes() {
    ImmutableSortedSet.Builder<ModelType<? extends PUBLIC>> supportedTypes = ImmutableSortedSet
            .orderedBy(ModelTypes.<PUBLIC>displayOrder());
    for (TypeRegistration<?> registration : registrations.values()) {
        if (registration.isConstructible()) {
            supportedTypes.add(registration.publicType);
        }/* w w  w.j  av a  2  s  .com*/
    }
    return supportedTypes.build();
}

From source file:com.android.tools.idea.npw.assetstudio.wizard.ConfirmGenerateIconsStep.java

@Override
protected void onEntering() {
    myListeners.release(mySelectedSourceSet); // Just in case we're entering this step a second time
    myListeners.receiveAndFire(mySelectedSourceSet, sourceSet -> {
        AndroidIconGenerator iconGenerator = getModel().getIconGenerator();
        File resDir = sourceSet.getPaths().getResDirectory();
        if (iconGenerator == null || resDir == null || resDir.getParentFile() == null) {
            return;
        }//from   ww w.j  a  v a  2s  .c om

        final Map<File, BufferedImage> pathIconMap = iconGenerator.generateIntoFileMap(sourceSet.getPaths());
        myFilesAlreadyExist.set(false);

        int minHeight = Integer.MAX_VALUE;
        int maxHeight = Integer.MIN_VALUE;
        for (BufferedImage image : pathIconMap.values()) {
            minHeight = Math.min(minHeight, image.getHeight());
            maxHeight = Math.max(maxHeight, image.getHeight());
        }

        ImmutableSortedSet.Builder<File> sortedPaths = ImmutableSortedSet.orderedBy(new Comparator<File>() {
            @Override
            public int compare(File file1, File file2) {
                String path1 = file1.getAbsolutePath();
                String path2 = file2.getAbsolutePath();
                Density density1 = CategoryIconMap.pathToDensity(path1);
                Density density2 = CategoryIconMap.pathToDensity(path2);

                if (density1 != null && density2 != null && density1 != density2) {
                    // Sort least dense to most dense
                    return Ints.compare(density2.ordinal(), density1.ordinal());
                } else {
                    BufferedImage image1 = pathIconMap.get(file1);
                    BufferedImage image2 = pathIconMap.get(file2);
                    int compareValue = Ints.compare(image2.getHeight(), image1.getHeight());
                    // If heights are the same, use path as a tie breaker
                    return (compareValue != 0) ? compareValue : path2.compareTo(path1);
                }

            }
        });
        sortedPaths.addAll(pathIconMap.keySet());

        FileTreeModel treeModel = new FileTreeModel(resDir.getParentFile(), true);

        for (File path : sortedPaths.build()) {
            Image image = pathIconMap.get(path);

            if (path.exists()) {
                myFilesAlreadyExist.set(true);
            }

            // By default, icons grow exponentially, and if presented at scale, may take up way too
            // much real estate. Instead, let's scale down all icons proportionally so the largest
            // one fits in our maximum allowed space.
            if (maxHeight > MAX_TREE_ROW_HEIGHT) {
                int hCurr = image.getHeight(null);
                int wCurr = image.getWidth(null);

                double hScale;
                if (maxHeight != minHeight) {
                    // From hMin <= hCurr <= hMax, interpolate to hMin <= hFinal <= MAX_TREE_ROW_HEIGHT
                    double hCurrPercent = (double) (hCurr - minHeight) / (double) (maxHeight - minHeight);
                    double scaledDeltaH = hCurrPercent * (MAX_TREE_ROW_HEIGHT - minHeight);
                    double hCurrScaled = minHeight + scaledDeltaH;
                    hScale = hCurrScaled / hCurr;
                } else {
                    // This happens if there's only one entry in the list and it's larger than
                    // MAX_TREE_ROW_HEIGHT
                    hScale = MAX_TREE_ROW_HEIGHT / (double) hCurr;
                }

                int hFinal = (int) (hCurr * hScale);
                int wFinal = (int) (wCurr * hScale);
                image = image.getScaledInstance(wFinal, hFinal, Image.SCALE_SMOOTH);
            }

            treeModel.forceAddFile(path, new ImageIcon(image));
        }

        myOutputPreviewTree.setModel(treeModel);

        // The tree should be totally expanded by default
        for (int i = 0; i < myOutputPreviewTree.getRowCount(); ++i) {
            myOutputPreviewTree.expandRow(i);
        }
    });
}

From source file:org.sleuthkit.autopsy.timeline.datamodel.EventCluster.java

@Override
public SortedSet<EventCluster> getClusters() {
    return ImmutableSortedSet.orderedBy(Comparator.comparing(EventCluster::getStartMillis)).add(this).build();
}

From source file:controllers.ArtifactsController.java

public static Result component(String name, String tyype) {
    try {//from   www.  j a v a 2  s  . co  m
        Artifact artifact = PetalsAdmin.getArtifactAdministration(getCurrentNode()).getArtifactInfo(tyype, name,
                null);

        if (artifact != null) {
            final Component c = (Component) artifact;

            Set<Property> properties = ImmutableSortedSet.orderedBy(new Comparator<Property>() {
                public int compare(Property r1, Property r2) {
                    return r1.name.compareToIgnoreCase(r2.name);
                }
            }).addAll(Collections2.transform(c.getParameters().stringPropertyNames(),
                    new Function<String, Property>() {
                        public Property apply(String key) {
                            return new Property(key, c.getParameters().getProperty(key));
                        }
                    })).build();

            List<Subscription> subscriptions = Subscription.subscriptions(name, tyype, getCurrentNode());
            return ok(component.render(c, properties, subscriptions));
        } else {
            flash("error", "No such component");
            return index();
        }
    } catch (Exception e) {
        flash("error", String.format("Error while getting component information : %s", e.getMessage()));
        return index();
    }
}

From source file:com.google.caliper.runner.ExperimentingRunnerModule.java

private static ImmutableSortedSet<Method> findAllBenchmarkMethods(Class<?> benchmarkClass,
        Instrument instrument) throws InvalidBenchmarkException {
    ImmutableSortedSet.Builder<Method> result = ImmutableSortedSet
            .orderedBy(Ordering.natural().onResultOf(new Function<Method, String>() {
                @Override//from   w  w w  .j ava2  s .  c  o m
                public String apply(Method method) {
                    return method.getName();
                }
            }));
    Set<String> benchmarkMethodNames = new HashSet<String>();
    Set<String> overloadedMethodNames = new TreeSet<String>();
    for (Method method : benchmarkClass.getDeclaredMethods()) {
        if (instrument.isBenchmarkMethod(method)) {
            method.setAccessible(true);
            result.add(method);
            if (!benchmarkMethodNames.add(method.getName())) {
                overloadedMethodNames.add(method.getName());
            }
        }
    }
    if (!overloadedMethodNames.isEmpty()) {
        throw new InvalidBenchmarkException(
                "Overloads are disallowed for benchmark methods, found overloads of %s in benchmark %s",
                overloadedMethodNames, benchmarkClass);
    }
    return result.build();
}

From source file:org.projectbuendia.client.data.app.AppLocationTree.java

/**
 * Returns the sorted descendants of the specified location at the specified depth relative to
 * that location.//from www .  j a  v a  2  s .  co m
 */
public ImmutableSortedSet<AppLocation> getDescendantsAtDepth(AppLocation location, int relativeDepth) {
    if (location == null) {
        return ImmutableSortedSet.of();
    }

    if (relativeDepth == 0) {
        ImmutableSortedSet.Builder<AppLocation> thisLocationSet = ImmutableSortedSet
                .orderedBy(new AppLocationComparator(this));
        thisLocationSet.add(location);
        return thisLocationSet.build();
    }

    ImmutableSortedSet.Builder<AppLocation> descendants = ImmutableSortedSet
            .orderedBy(new AppLocationComparator(this));
    for (AppLocation child : getChildren(location)) {
        descendants.addAll(getDescendantsAtDepth(child, relativeDepth - 1));
    }

    return descendants.build();
}