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(Iterator<? extends E> elements) 

Source Link

Document

Creates a mutable HashSet instance containing the given elements.

Usage

From source file:com.flaptor.indextank.IndexTankTestCase.java

public static void assertSameSets(Iterable<?> a, Iterable<?> b) {
    assertTrue(Sets.newHashSet(a).equals(Sets.newHashSet(b)));
}

From source file:ai.grakn.test.graql.query.QueryUtil.java

public static void assertResultsMatch(Iterable<Map<String, Concept>> query, String var, String type,
        List<ResourceType> resourceTypes, String... expectedResources) {
    Set<String> expectedSet = Sets.newHashSet(expectedResources);
    Set<String> unfoundSet = Sets.newHashSet(expectedResources);

    query.forEach(results -> {// ww w  . jav  a2s .c  o m
        Concept result = results.get(var);
        assertNotNull(result);

        String resourceValue = result.getId();

        if (result.isType())
            resourceValue = result.asType().getName();

        for (ResourceType resourceType : resourceTypes) {
            if (result.isInstance()) {
                Collection<Resource<?>> foundResources = result.asInstance().resources(resourceType);
                if (!foundResources.isEmpty()) {
                    resourceValue = foundResources.iterator().next().getValue().toString();
                    break;
                }
            }
        }

        assertTrue("Unexpected value: " + resourceValue, expectedSet.contains(resourceValue));
        unfoundSet.remove(resourceValue);
        if (type != null)
            assertEquals(type, result.type().getName());
    });

    assertTrue("expected values not found: " + unfoundSet, unfoundSet.isEmpty());
}

From source file:com.opengamma.livedata.normalization.RequiredFieldFilter.java

/**
 * Creates a filter with a set of required field names.
 * //from   ww  w  .  ja  va  2s .  c  o  m
 * @param requiredFieldNames  the field names, not null
 */
public RequiredFieldFilter(String... requiredFieldNames) {
    this(Sets.newHashSet(requiredFieldNames));
}

From source file:com.cloudera.nav.sdk.model.custom.CustomProperty.java

public static CustomProperty newProperty(String namespace, String name, CustomPropertyType propertyType,
        boolean multiValued, String[] values) {
    CustomProperty prop = new CustomProperty();
    prop.setNamespace(namespace);/*from  w ww  .  j  a  v a 2  s.  c o m*/
    prop.setName(name);
    prop.setPropertyType(propertyType);
    prop.setMultiValued(multiValued);
    if (propertyType == CustomPropertyType.ENUM) {
        Preconditions.checkNotNull(values);
        Preconditions.checkArgument(values.length > 0);
        prop.setEnumValues(Sets.newHashSet(values));
    }
    return prop;
}

From source file:cc.kave.commons.utils.ToStringUtils.java

public static String toString(Object o) {
    try {//w  ww.j a v  a 2 s .c  o  m
        StringBuilder sb = new StringBuilder();
        toString(0, sb, o, Sets.newHashSet(o));
        return sb.toString();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.opendaylight.controller.config.yang.store.impl.YangParserWrapper.java

static SchemaContext getSchemaContextFromModules(YangModelParser parser,
        Map<InputStream, Module> allYangModules) {
    return parser.resolveSchemaContext(Sets.newHashSet(allYangModules.values()));
}

From source file:com.ebay.pulsar.analytics.datasource.PulsarTableDimension.java

public void setAlias(String alias) {
    this.alias = alias;
    super.columnNames.addAll(Sets.newHashSet(Splitter.on(',').trimResults().split(alias)));
}

From source file:ai.grakn.graql.internal.gremlin.spanningtree.Arborescence.java

public static <T> Arborescence<T> of(ImmutableMap<T, T> parents) {
    if (parents != null && !parents.isEmpty()) {
        HashSet<T> allParents = Sets.newHashSet(parents.values());
        allParents.removeAll(parents.keySet());
        if (allParents.size() == 1) {
            return new Arborescence<>(parents, allParents.iterator().next());
        }//from   w ww  .  j a va2  s. c o  m
    }
    return new Arborescence<>(parents, null);
}

From source file:org.cinchapi.concourse.util.TSets.java

/**
 * Return a Set that contains only the elements that are in both {@code a}
 * and {@code b}./*from   ww w  . j a  v  a 2 s .  c  o m*/
 * 
 * @param a
 * @param b
 * @return the intersection of the Sets
 */
public static <T> Set<T> intersection(Set<T> a, Set<T> b) {
    Set<T> intersection = Sets.newLinkedHashSet();
    Set<T> smaller = a.size() <= b.size() ? a : b;
    Set<T> larger = Sets.newHashSet(a.size() > b.size() ? a : b);
    for (T element : smaller) {
        if (larger.contains(element)) {
            intersection.add(element);
        }
    }
    return intersection;
}

From source file:cn.sunxyz.config.SwaggerConfiguration.java

@Bean
public Docket configSpringfoxDocket_all(ApiInfo apiInfo) {
    return new Docket(DocumentationType.SWAGGER_2).produces(Sets.newHashSet("application/json"))
            .consumes(Sets.newHashSet("application/json")).protocols(Sets.newHashSet("http", "https"))
            .apiInfo(apiInfo).forCodeGeneration(true).select().paths(regex("/api.*")).build();
}