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.inputs.amqp.AMQPQueueConfiguration.java

public static Set<AMQPQueueConfiguration> fetchAll(Core server) {
    Set<AMQPQueueConfiguration> configs = Sets.newHashSet();

    DBCollection coll = server.getMongoConnection().getDatabase().getCollection("amqp_configurations");
    DBCursor cur = coll.find(new BasicDBObject());

    while (cur.hasNext()) {
        try {// ww w  . j  a  v  a  2 s.  c o m
            DBObject config = cur.next();

            configs.add(
                    new AMQPQueueConfiguration((ObjectId) config.get("_id"), (String) config.get("exchange"),
                            (String) config.get("routing_key"), (Integer) config.get("ttl"),
                            inputTypeFromString((String) config.get("input_type")), server.getServerId()));
        } catch (Exception e) {
            LOG.warn("Can't fetch AMQP queue config. Skipping. " + e.getMessage(), e);
        }
    }

    return configs;
}

From source file:org.chiefly.nautilus.concurrent.LatchedRunnable.java

/**
 * @param runnables The {@link Runnable}s to wrap.
 * @return A {@link Set} of {@link Runnable}s wrapped by
 *         {@link LatchedRunnable}s./*from  w  w w.  j  ava  2  s.co m*/
 */
public static <V> Set<Runnable> wrapAll(final Set<Runnable> runnables) {

    /* Create a latch */
    final CountDownLatch latch = new CountDownLatch(runnables.size());

    /* Do the wrapping */
    final Set<Runnable> wrapped = Sets.newHashSet();
    for (final Runnable runnable : runnables) {
        wrapped.add(new LatchedRunnable(runnable, latch));
    }

    return wrapped;
}

From source file:org.carrot2.text.linguistic.LexicalResources.java

static LexicalResources merge(Collection<LexicalResources> values) {
    final Set<MutableCharArray> mergedStopwords = Sets.newHashSet();
    final List<Pattern> mergedStoplabels = Lists.newArrayList();

    for (LexicalResources lexicalResources : values) {
        mergedStopwords.addAll(lexicalResources.stopwords);
        mergedStoplabels.addAll(lexicalResources.stoplabels);
    }//from   w  ww.j  ava  2  s .  c o  m

    return new LexicalResources(mergedStoplabels, mergedStopwords);
}

From source file:org.jetbrains.jet.lang.resolve.java.scope.ScopeUtils.java

@NotNull
public static Collection<DeclarationDescriptor> computeAllPackageDeclarations(PsiPackage psiPackage,
        JavaSemanticServices javaSemanticServices, FqName packageFqName) {
    Collection<DeclarationDescriptor> result = Sets.newHashSet();
    boolean isKotlinNamespace = packageFqName != null
            && javaSemanticServices.getKotlinNamespaceDescriptor(packageFqName) != null;
    final JavaDescriptorResolver descriptorResolver = javaSemanticServices.getDescriptorResolver();

    for (PsiPackage psiSubPackage : psiPackage.getSubPackages()) {
        NamespaceDescriptor childNs = descriptorResolver.resolveNamespace(
                new FqName(psiSubPackage.getQualifiedName()), DescriptorSearchRule.IGNORE_IF_FOUND_IN_KOTLIN);
        if (childNs != null) {
            result.add(childNs);//from   www  . j a va  2s .  com
        }
    }

    for (PsiClass psiClass : psiPackage.getClasses()) {
        if (isKotlinNamespace && JvmAbi.PACKAGE_CLASS.equals(psiClass.getName())) {
            continue;
        }

        if (psiClass instanceof JetJavaMirrorMarker) {
            continue;
        }

        // TODO: Temp hack for collection function descriptors from java
        if (JvmAbi.PACKAGE_CLASS.equals(psiClass.getName())) {
            continue;
        }

        if (psiClass.hasModifierProperty(PsiModifier.PUBLIC)) {
            ProgressIndicatorProvider.checkCanceled();
            ClassDescriptor classDescriptor = descriptorResolver.resolveClass(
                    new FqName(psiClass.getQualifiedName()), DescriptorSearchRule.IGNORE_IF_FOUND_IN_KOTLIN);
            if (classDescriptor != null) {
                result.add(classDescriptor);
            }
        }
    }
    return result;
}

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

/**
 * This method returns the intersection of the two provided sets.
 * @param <T> The type of the objects contained in the input sets.
 * @param setA An input set./*w  w  w  .ja  va  2 s . co  m*/
 * @param setB An input set.
 * @return The intersection of setA and setB.
 */
public static <T> Set<T> intersectSet(Set<T> setA, Set<T> setB) {
    Set<T> unionSetTemp = Sets.newHashSet();

    unionSetTemp.addAll(setA);
    unionSetTemp.removeAll(setB);

    Set<T> unionSet = Sets.newHashSet();
    unionSet.addAll(setA);
    unionSet.removeAll(unionSetTemp);

    return unionSet;
}

From source file:com.topekalabs.pg4j.parse.PGTypeParamsH.java

private void validate(Node node) {
    Preconditions.checkNotNull(node);/*w ww  .  ja  va 2 s.c om*/

    Set<String> names = Sets.newHashSet();

    for (PGTypeParamH pgTypeParamH : pgTypeParamHs) {
        if (!names.add(pgTypeParamH.getName())) {
            throw new PG4jException(node, "Dublicate type name: " + pgTypeParamH.getName());
        }
    }
}

From source file:com.enonic.cms.store.blob.DbUsedBlobKeyFinder.java

public Set<BlobKey> findKeys() throws Exception {
    final HashSet<BlobKey> keys = Sets.newHashSet();

    findFromVirtualFile(keys);//  www.  j a  va  2 s.  c om
    findFromBinaryData(keys);

    return keys;
}

From source file:ro.cosu.vampires.server.values.jobs.metrics.Trace.java

public static Trace empty() {
    return builder().cpuSet(Sets.newHashSet()).start(emptyTime).stop(emptyTime).totalCpuCount(0)
            .executorMetrics(Metrics.empty()).executor("unknown").build();
}

From source file:org.chiefly.nautilus.concurrent.LatchedCallable.java

/**
 * @param callables The {@link Callable}s to wrap.
 * @return A {@link Set} of {@link Callable}s wrapped by
 *         {@link LatchedCallable}s./*from   w  ww.j  a v  a  2 s.co  m*/
 */
public static <V> Set<Callable<V>> wrapAll(final Set<Callable<V>> callables) {

    /* Create a latch */
    final CountDownLatch latch = new CountDownLatch(callables.size());

    /* Do the wrapping */
    final Set<Callable<V>> wrapped = Sets.newHashSet();
    for (final Callable<V> callable : callables) {
        wrapped.add(new LatchedCallable<V>(callable, latch));
    }

    return wrapped;
}

From source file:org.opendaylight.controller.yang.parser.util.TopologicalSort.java

private static Set<Node> getDependentNodes(Set<Node> nodes) {
    Set<Node> S = Sets.newHashSet();
    for (Node n : nodes) {
        if (n.getOutEdges().size() == 0) {
            S.add(n);//from   ww w  .  j  a va 2  s . com
        }
    }
    return S;
}