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

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

Introduction

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

Prototype

public static <E> HashSet<E> newHashSet() 

Source Link

Document

Creates a mutable, initially empty HashSet instance.

Usage

From source file:org.graylog2.plugins.PluginRegistry.java

public static void setActiveTransports(Core server, List<Transport> transports) {
    Set<Map<String, Object>> r = Sets.newHashSet();

    for (Transport transport : transports) {
        Map<String, Object> entry = buildStandardInformation(transport.getClass().getCanonicalName(),
                transport.getName(), transport.getRequestedConfiguration());

        entry.put("user_field_name", transport.getUserFieldName());

        r.add(entry);//  www.j a v a 2 s  .c om
    }

    server.getMongoBridge().writePluginInformation(r, "transports");
}

From source file:org.jetbrains.jet.plugin.stubindex.PackageIndexUtil.java

@NotNull
public static Collection<FqName> getSubPackageFqNames(@NotNull FqName packageFqName,
        @NotNull GlobalSearchScope scope, @NotNull Project project) {
    Collection<JetFile> files = JetAllPackagesIndex.getInstance().get(packageFqName.asString(), project, scope);

    Set<FqName> result = Sets.newHashSet();
    for (JetFile file : files) {
        FqName fqName = file.getPackageFqName();

        assert NamePackage.isSubpackageOf(fqName,
                packageFqName) : "Registered package is not a subpackage of actually declared package:\n"
                        + "in index: " + packageFqName + "\n" + "declared: " + fqName;
        FqName subpackage = NamePackage.plusOneSegment(packageFqName, fqName);
        if (subpackage != null) {
            result.add(subpackage);// w  ww  . j ava2s . c  om
        }
    }

    return result;
}

From source file:org.ros.internal.node.topic.PublisherIdentifier.java

public static Collection<PublisherIdentifier> newCollectionFromUris(Collection<URI> publisherUris,
        TopicDeclaration topicDeclaration) {
    Set<PublisherIdentifier> publishers = Sets.newHashSet();
    for (URI uri : publisherUris) {
        NodeIdentifier nodeIdentifier = new NodeIdentifier(null, uri);
        publishers.add(new PublisherIdentifier(nodeIdentifier, topicDeclaration.getIdentifier()));
    }/*from  w w w  . j  a v  a 2  s . com*/
    return publishers;
}

From source file:com.cognifide.aet.executor.xmlparser.xml.models.ModelConverterUtils.java

static List<ExtendedUrl> extendUrlsList(List<Url> urls) throws ParseException, UnsupportedEncodingException {
    List<ExtendedUrl> extendedUrls = Lists.newArrayList();
    List<ExtendedUrl> duplicatedUrls = Lists.newArrayList();
    Set<String> names = Sets.newHashSet();
    for (Url url : urls) {
        String urlName;//ww w  .  j a v  a  2 s .  c  om
        if (StringUtils.isBlank(url.getName())) {
            urlName = url.getHref().trim();
        } else {
            urlName = URLEncoder.encode(url.getName().trim(), StandardCharsets.UTF_8.displayName());
        }
        ExtendedUrl extendedUrl = new ExtendedUrl(url.getHref(), urlName, url.getDescription());
        if (!names.add(urlName)) {
            duplicatedUrls.add(extendedUrl);
        } else {
            extendedUrls.add(extendedUrl);
        }
    }
    if (!duplicatedUrls.isEmpty()) {
        StringBuilder builder = new StringBuilder("Duplicated urls:");
        for (ExtendedUrl url : duplicatedUrls) {
            builder.append(String.format("%n%s with name %s", url.getUrl(), url.getName()));
        }
        throw new ParseException(builder.toString());
    }
    return extendedUrls;
}

From source file:com.netflix.genie.web.util.MetricsUtils.java

/**
 * Convenience method that creates a tag set pre-populated with success status.
 *
 * @return a new set containing success tags
 *//*  w  w w  .ja va 2  s. c om*/
public static Set<Tag> newSuccessTagsSet() {
    final Set<Tag> tags = Sets.newHashSet();
    addSuccessTags(tags);
    return tags;
}

From source file:com.topekalabs.collection.utils.ListUtils.java

public static <T> void listContainsDuplicateReferencesException(List<T> list, String listName) {
    Set<ReferenceWrapper<T>> elementSet = Sets.newHashSet();

    for (T element : list) {
        elementSet.add(new ReferenceWrapper<>(element));
    }//from ww  w.  j a  v a 2s .com

    if (elementSet.size() != list.size()) {
        throw new IllegalArgumentException("The given list " + listName + " contains duplicate references.");
    }
}

From source file:eu.project.ttc.utils.TermIndexUtils.java

public static Set<TermVariation> getVariations(TermIndex termIndex) {
    Set<TermVariation> variations = Sets.newHashSet();
    for (Term t : termIndex.getTerms()) {
        for (TermVariation tv : t.getVariations())
            variations.add(tv);//from  w ww .  ja v  a2s  .  c  o m
        for (TermVariation tv : t.getBases())
            variations.add(tv);
    }
    return variations;
}

From source file:org.eclipse.sirius.tools.internal.ui.RefreshHelper.java

/**
 * Checks whether the changes we are notified changes semantic models (i.e.
 * not just Sirius representations state).
 *
 * @param notifications//w w w.ja v  a2 s  .  co m
 *            the model changes.
 * @return <code>true</code> if the changes impact semantic models.
 */
public static boolean isImpactingNotification(final Collection<Notification> notifications) {
    boolean isImpactingNotification = false;
    Set<EObject> alreadyDoneNotifiers = Sets.newHashSet();
    for (Notification notification : notifications) {
        Object notifier = notification.getNotifier();
        if (notifier instanceof EObject) {
            EObject eObjectNotifier = (EObject) notifier;
            if (!alreadyDoneNotifiers.contains(eObjectNotifier)) {
                alreadyDoneNotifiers.add(eObjectNotifier);
                Resource notifierResource = eObjectNotifier.eResource();
                if (notifierResource != null
                        && !new ResourceQuery(notifierResource).isRepresentationsResource()) {
                    isImpactingNotification = true;
                    break;
                }
            }
        }
    }
    return isImpactingNotification;
}

From source file:it.av.fac.mlengine.test.RandomForest.java

private static Set<Instance> readFromCSV(String datasetPath) {
    Set<Instance> dataset = Sets.newHashSet();

    try (BufferedReader in = new BufferedReader(new FileReader(datasetPath))) {
        String line;/*from  w ww  .ja v  a  2  s.  co  m*/
        String[] header = in.readLine().split("[,]");
        while ((line = in.readLine()) != null) {
            String[] fields = line.split("[,]");
            dataset.add(HashMapAttributes
                    .create(header[0], Double.parseDouble(fields[0]), header[1], Double.parseDouble(fields[1]),
                            header[2], Double.parseDouble(fields[2]), header[3], Double.parseDouble(fields[3]),
                            header[4], Double.parseDouble(fields[4]), header[5], Double.parseDouble(fields[5]))
                    .classification(fields[6].equals("1") ? "good_edit" : "bad_edit"));
        }
    } catch (IOException | NumberFormatException ex) {
        Logger.getLogger(RandomForest.class.getName()).log(Level.SEVERE, null, ex);
    }

    return dataset;
}

From source file:org.prebake.service.DotRenderer.java

static void render(final PlanGraph g, final Set<BoundName> prods, final Appendable out) throws IOException {
    final List<BoundName> roots = Lists.newArrayList(prods);
    // Eliminate any products that are dependencies of others.
    {/* ww  w  .j av  a2  s  .c  o m*/
        final Set<BoundName> notRoots = Sets.newHashSet();
        for (final BoundName prod : prods) {
            if (notRoots.contains(prod)) {
                break;
            }
            g.walker(new Function<BoundName, Void>() {
                public Void apply(BoundName node) {
                    if (!node.equals(prod) && prods.contains(node)) {
                        notRoots.add(node);
                    }
                    return null;
                }
            }).walk(prod);
        }
        roots.removeAll(notRoots);
    }
    out.append("digraph {\n");
    for (BoundName root : roots) {
        try {
            g.walker(new Function<BoundName, Void>() {
                public Void apply(BoundName node) {
                    try {
                        out.append("  ");
                        writeDotId(node.ident);
                        out.append(";\n");
                        for (BoundName dep : g.edges.get(node)) {
                            out.append("  ");
                            writeDotId(dep.ident);
                            out.append(" -> ");
                            writeDotId(node.ident);
                            out.append(";\n");
                        }
                        // TODO: display intersection of inputs and outputs at edge
                        // to help debug
                    } catch (IOException ex) {
                        throw new IOError(ex);
                    }
                    return null;
                }

                private void writeDotId(String id) throws IOException {
                    out.append('"');
                    out.append(id.replaceAll("[\\\\\"]", "\\\\$0"));
                    out.append('"');
                }
            }).walk(root);
        } catch (IOError err) {
            throw (IOException) err.getCause();
        }
    }
    out.append("}\n");
}