Example usage for com.google.common.collect Sets newTreeSet

List of usage examples for com.google.common.collect Sets newTreeSet

Introduction

In this page you can find the example usage for com.google.common.collect Sets newTreeSet.

Prototype

public static <E> TreeSet<E> newTreeSet(Comparator<? super E> comparator) 

Source Link

Document

Creates a mutable, empty TreeSet instance with the given comparator.

Usage

From source file:hub.backends.users.GroupReader.java

private Thing<Group> wrapGroup(Group g) {
    Thing t = new Thing();
    //        Integer id = um.getProjectId(g.getGroupName());
    //        if ( id != null ) {
    //            t.setId("projectId:"+id.toString());
    //        }//from   w w w  .j  a v a  2 s.  com
    t.setId(g.getGroupName());
    t.setKey(g.getGroupName());
    t.setValue(g);
    t.setValueIsPopulated(true);
    t.setThingType(tr.getType(Group.class));
    t.setParents(Sets.newTreeSet(g.getMembers().values()));

    return t;
}

From source file:com.continuuity.loom.layout.NodeLayout.java

/**
 * Create a new NodeLayout by adding a set of services to the given NodeLayout.
 *
 * @param nodeLayout NodeLayout to add the services to.
 * @param services Services to add.// w ww. j  a v a 2s  .  co  m
 * @return New layout obtained by adding the services to the given layout.
 */
public static NodeLayout addServicesToNodeLayout(NodeLayout nodeLayout, Set<String> services) {
    Set<String> expandedServices = Sets.newTreeSet(nodeLayout.getServiceNames());
    expandedServices.addAll(services);
    return new NodeLayout(nodeLayout.hardwareType, nodeLayout.imageType, expandedServices);
}

From source file:com.github.fge.jsonpatch.diff.JsonDiff.java

private static void generateObjectDiffs(final DiffProcessor processor, final JsonPointer pointer,
        final ObjectNode source, final ObjectNode target) {
    final Set<String> firstFields = Sets.newTreeSet(Sets.newHashSet(source.fieldNames()));
    final Set<String> secondFields = Sets.newTreeSet(Sets.newHashSet(target.fieldNames()));

    for (final String field : Sets.difference(firstFields, secondFields))
        processor.valueRemoved(pointer.append(field), source.get(field));

    for (final String field : Sets.difference(secondFields, firstFields))
        processor.valueAdded(pointer.append(field), target.get(field));

    for (final String field : Sets.intersection(firstFields, secondFields))
        generateDiffs(processor, pointer.append(field), source.get(field), target.get(field));
}

From source file:org.apache.beam.sdk.util.IOChannelUtils.java

private static void registerIOFactoriesInternal(PipelineOptions options, boolean override) {
    Set<IOChannelFactoryRegistrar> registrars = Sets.newTreeSet(ReflectHelpers.ObjectsClassComparator.INSTANCE);
    registrars.addAll(Lists.newArrayList(ServiceLoader.load(IOChannelFactoryRegistrar.class, CLASS_LOADER)));

    checkDuplicateScheme(registrars);//  w  w w . java  2  s  .c o  m

    for (IOChannelFactoryRegistrar registrar : registrars) {
        setIOFactoryInternal(registrar.getScheme(), registrar.fromOptions(options), override);
    }
}

From source file:org.carrot2.core.test.assertions.ClusterListAssertion.java

private void tabularizedReport(List<String> l1, List<String> l2) {
    Logger logger = LoggerFactory.getLogger(ClusterListAssertion.class);

    int maxL1Width = 0;
    for (String s : l1)
        maxL1Width = Math.max(maxL1Width, s.length());

    final StringBuilder sb = new StringBuilder();
    final Set<String> l1s = Sets.newTreeSet(l1);
    final Set<String> l2s = Sets.newTreeSet(l2);

    if (l1s.equals(l2s)) {
        sb.append("PROBLEM: Same sets different order or hierarchy.\n");

        sb.append("Clusters side-by-side (same-line order changes marked):\n");
        for (int i = 0; i < Math.max(l1.size(), l2.size()); i++) {
            String lbl = l1.get(i);
            sb.append(l2.get(i).equals(lbl) ? "  " : "* ");
            sb.append(Strings.padEnd(lbl, maxL1Width, ' '));
            sb.append(" | ");

            lbl = l2.get(i);// w  ww  .j av a2s  .c  o  m
            sb.append(l1.get(i).equals(lbl) ? "  " : "* ");
            sb.append(lbl);
            sb.append("\n");
        }
    } else {
        Set<String> common = Sets.newTreeSet(l1s);
        common.retainAll(l2s);
        l1s.removeAll(common);
        l2s.removeAll(common);

        sb.append("Clusters in the previous set only:\n");
        for (String s : l1s)
            sb.append("  '" + s + "'\n");
        sb.append("Clusters in the actual set only:\n");
        for (String s : l2s)
            sb.append("  '" + s + "'\n");

        sb.append("Clusters side-by-side (order changes not shown):\n");
        for (int i = 0; i < Math.max(l1.size(), l2.size()); i++) {
            String lbl = (i < l1.size() ? l1.get(i) : "--");
            sb.append(l1s.contains(lbl) ? "* " : "  ");
            sb.append(Strings.padEnd(lbl, maxL1Width, ' '));
            sb.append(" | ");

            lbl = (i < l2.size() ? l2.get(i) : "--");
            sb.append(l2s.contains(lbl) ? "* " : "  ");
            sb.append(lbl);
            sb.append("\n");
        }
    }

    logger.error("Failed cluster list comparison (previous | now):\n" + sb.toString());
}

From source file:edu.harvard.med.screensaver.ui.attachedFiles.AttachedFileSearchResults.java

public void initialize(DataTableModel<Tuple<Integer>> model) {
    _allAttachedFileTypes = Sets.newTreeSet(_dao.findAllEntitiesOfType(AttachedFileType.class));
    super.initialize(model);
}

From source file:org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency.java

@Override
public Configuration findProjectConfiguration(Map<String, String> clientAttributes) {
    Configuration selectedConfiguration = null;
    ConfigurationContainer dependencyConfigurations = getDependencyProject().getConfigurations();
    String declaredConfiguration = getTargetConfiguration();
    if (declaredConfiguration == null && !clientAttributes.isEmpty()) {
        List<Configuration> candidateConfigurations = new ArrayList<Configuration>(1);
        for (Configuration dependencyConfiguration : dependencyConfigurations) {
            if (dependencyConfiguration.hasAttributes()) {
                Map<String, String> attributes = dependencyConfiguration.getAttributes();
                if (attributes.entrySet().containsAll(clientAttributes.entrySet())) {
                    candidateConfigurations.add(dependencyConfiguration);
                }/* ww  w  .j av a  2s. co  m*/
            }
        }
        if (candidateConfigurations.size() == 1) {
            selectedConfiguration = candidateConfigurations.get(0);
        } else if (!candidateConfigurations.isEmpty()) {
            throw new IllegalArgumentException("Cannot choose between the following configurations: "
                    + Sets.newTreeSet(Lists.transform(candidateConfigurations, CONFIG_NAME))
                    + ". All of then match the client attributes " + clientAttributes);
        }
    }
    if (selectedConfiguration == null) {
        selectedConfiguration = dependencyConfigurations
                .getByName(GUtil.elvis(declaredConfiguration, Dependency.DEFAULT_CONFIGURATION));
    }
    return selectedConfiguration;
}

From source file:nl.socrates.dom.communicationchannel.CommunicationChannels.java

@Programmatic
public SortedSet<CommunicationChannel> findOtherByOwnerAndType(final CommunicationChannelOwner owner,
        CommunicationChannelType type, CommunicationChannel exclude) {
    return Sets.newTreeSet(
            allMatches("findOtherByOwnerAndType", "owner", owner, "type", type, "exclude", exclude));
}

From source file:net.oneandone.maven.plugins.cycles.analyzer.ComponentAnalyzer.java

private void printDependencies(DirectedGraph<String, WeightedEdge> component, StringBuilder builder) {
    builder.append("\n= Dependencies\n");
    TreeSet<WeightedEdge> sortedEdges = Sets.newTreeSet(new WeightedEdgeComparator(component));
    sortedEdges.addAll(component.getEdges());
    for (WeightedEdge dependency : sortedEdges) {
        builder.append(GraphStringUtils.edgeToString(dependency, component, shorten));
        builder.append("\n");
        if (showClassDeps) {
            printClassDependencies(builder, dependency);
        }/*w w w .  j  a  va2s .com*/
    }
}

From source file:org.apache.brooklyn.rest.transform.TypeTransformer.java

protected static <T extends TypeSummary> void embellishEntity(T result, RegisteredType item,
        BrooklynRestResourceUtils b) {//from  w w  w .ja v a 2  s. com
    try {
        Set<ConfigSummary> config = Sets.newLinkedHashSet();
        Set<SensorSummary> sensors = Sets.newTreeSet(SummaryComparators.nameComparator());
        Set<EffectorSummary> effectors = Sets.newTreeSet(SummaryComparators.nameComparator());

        EntitySpec<?> spec = b.getTypeRegistry().createSpec(item, null, EntitySpec.class);
        EntityDynamicType typeMap = BrooklynTypes.getDefinedEntityType(spec.getType());
        EntityType type = typeMap.getSnapshot();

        AtomicInteger priority = new AtomicInteger();
        for (SpecParameter<?> input : spec.getParameters())
            config.add(ConfigTransformer.of(input).uiIncrementAndSetPriorityIfPinned(priority).transform());
        for (Sensor<?> x : type.getSensors())
            sensors.add(SensorTransformer.sensorSummaryForCatalog(x));
        for (Effector<?> x : type.getEffectors())
            effectors.add(EffectorTransformer.effectorSummaryForCatalog(x));

        result.setExtraField("config", config);
        result.setExtraField("sensors", sensors);
        result.setExtraField("effectors", effectors);

    } catch (Exception e) {
        Exceptions.propagateIfFatal(e);

        // templates with multiple entities can't have spec created in the manner above; just ignore
        if (item.getSuperTypes().contains(Entity.class)) {
            log.warn("Unable to create spec for " + item + ": " + e, e);
        }
        if (log.isTraceEnabled()) {
            log.trace("Unable to create spec for " + item + ": " + e, e);
        }
    }
}