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:com.flaptor.indextank.suggest.Automaton.java

@SuppressWarnings("unchecked")
public static Set<String> intersectPaths(Automaton small, Automaton big) {
    class Element {
        String path;//from  w  w w.j  a  va  2s .com
        State smallState;
        State bigState;

        public Element(String path, State smallState, State bigState) {
            this.path = path;
            this.smallState = smallState;
            this.bigState = bigState;
        }
    }

    Set<String> results = Sets.newHashSet();
    Stack<Element> stack = new Stack<Element>();
    stack.push(new Element("", small.getStartState(), big.getStartState()));

    while (!stack.isEmpty()) {
        Element element = stack.pop();

        Iterable<Transition> transitions = element.smallState.getTransitions();

        for (Transition smallTransition : transitions) {
            char symbol = smallTransition.getSymbol();
            State smallState = smallTransition.getState();
            State bigState = element.bigState.step(symbol);

            if (bigState != null) {
                String path = element.path + symbol;
                stack.push(new Element(path, smallState, bigState));

                if (smallState.isAccept() && bigState.isAccept()) {
                    results.add(path);
                }
            }

        }
    }

    return results;
}

From source file:com.enonic.cms.core.search.facet.FacetBuilderFactory.java

public Set<FacetBuilder> buildFacetBuilder(ContentIndexQuery query) {
    Set<FacetBuilder> facetBuilders = Sets.newHashSet();

    String xml = query.getFacets();

    if (Strings.isNullOrEmpty(xml)) {
        return facetBuilders;
    }/*from  w  w  w .j a  v a2  s  .  co m*/

    final FacetsModel facetsModel = facetsModelFactory.buildFromXml(xml);

    return facetModelEsFacetBuilder.build(facetsModel);
}

From source file:com.clarkparsia.pelletserver.client.utils.ReflectionUtils.java

/**
 * Get all non-abstract implementations of class {@code cl} annotated with {@code annotation}
 * /*from   w  ww.  ja  va 2s.  c  o  m*/
 * @param <T> the class type
 * @param cl
 *            The class
 * @param annotation
 *            The annotation class
 * @return the classes which implement the interface and have the given annotation
 */
public static <T> Set<Class<? extends T>> getImplementations(Class<T> cl,
        Class<? extends Annotation> annotation) {

    Set<Class<? extends T>> implementations = Sets.newHashSet();
    Set<Class<? extends T>> subTypes = REFLECTIONS.getSubTypesOf(cl);

    for (Class<? extends T> subtype : subTypes) {
        if (!Modifier.isAbstract(subtype.getModifiers()) && subtype.isAnnotationPresent(annotation)) {
            implementations.add(subtype);
        }
    }

    return implementations;
}

From source file:edu.cmu.lti.oaqa.framework.persistence.DefaultAsyncConfiguration.java

@Override
public Set<String> getPublishedTopics(String experiment) {
    return Sets.newHashSet();
}

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

/**
 * /*from www  .j a  v a 2s .co  m*/
 * Transforms a list of sets into a set of element pairs,
 * which is the union of all cartesian products of
 * all pairs of sets.
 * 
 * Example: 
 * 
 * A = {a,b,c}
 * B = {d}
 * C = {e, f}
 * 
 * returns AxB U AxC U BxC = {
 *    {a,d}, {b,d}, {c,d}, 
 *  {a,e}, {a,f}, {b,e}, {b,f}, {c,e}, {c,f},
 *  {d,e}, {d,f}
 * }
 * 
 * 
 * @param iterable
 * @return
 */
@SuppressWarnings("unchecked")
public static <T extends Comparable<? super T>> Set<Pair<T>> combineAndProduct(
        List<? extends Set<? extends T>> sets) {
    Set<Pair<T>> results = Sets.newHashSet();
    for (int i = 0; i < sets.size(); i++) {
        for (int j = i + 1; j < sets.size(); j++)
            for (List<T> l : Sets.cartesianProduct(sets.get(i), sets.get(j)))
                results.add(new Pair<T>(l.get(0), l.get(1)));
    }
    return results;
}

From source file:org.eclipse.recommenders.codesearch.rcp.index.termvector.FilteredJavaMethodProvider.java

@Override
public void load(final ITermVectorConsumable consumable, final Map<Integer, Object> argumentsMap) {
    String prefix = (String) argumentsMap.get(0);
    prefix = prefix.toLowerCase();/*from   w w  w.  j  a va  2 s  .  co  m*/

    final Set<String> result = Sets.newHashSet();
    final Set<String> allItems = consumable.getTermVector(getFields());

    for (String type : allItems) {
        if (type.startsWith(prefix)) {
            result.add(type);
        } else {
            String pattern = prefix.replaceAll("\\.", "\\\\.").replaceAll("\\*", ".\\*") + ".*";

            if (type.matches(pattern))
                result.add(type);
        }
    }

    setTermVector(Lists.newArrayList(result));
    setDone(true);
}

From source file:org.sonar.core.issue.workflow.State.java

private static void checkDuplications(Transition[] transitions, String stateKey) {
    Set<String> keys = Sets.newHashSet();
    for (Transition transition : transitions) {
        if (keys.contains(transition.key())) {
            throw new IllegalArgumentException("Transition '" + transition.key()
                    + "' is declared several times from the originating state '" + stateKey + "'");
        }/*from   w ww .  j  a v a 2s  .c  o m*/
        keys.add(transition.key());
    }
}

From source file:ratpack.file.internal.ActivationBackedMimeTypes.java

private static Set<String> extractKnownMimeTypes() {
    try {/*  w ww  .  j  a  va 2 s. co  m*/
        Function<Object, String> getMimeTypeFunction = new GetMimeTypeFunction();
        Field typeHashField = makeFieldAccessible(Class.forName("com.sun.activation.registries.MimeTypeFile"),
                "type_hash");
        Field mimeTypeFilesField = makeFieldAccessible(MimetypesFileTypeMap.class, "DB");
        Object mimeTypeFiles = mimeTypeFilesField.get(MIME_TYPES_MAP);
        Set<String> mimeTypes = Sets.newHashSet();
        for (int i = 0; i < Array.getLength(mimeTypeFiles); i++) {
            Object mimeTypeFile = Array.get(mimeTypeFiles, i);
            if (mimeTypeFile != null) {
                Map<?, ?> typeHash = (Map) typeHashField.get(mimeTypeFile);
                Iterables.addAll(mimeTypes, Iterables.transform(typeHash.values(), getMimeTypeFunction));
            }
        }
        return ImmutableSet.copyOf(mimeTypes);
    } catch (ReflectiveOperationException | NullPointerException ex) {
        return ImmutableSet.of();
    }
}

From source file:com.b2international.snowowl.snomed.importer.rf2.util.RF2ReleaseRefSetFileCollector.java

public static Set<URL> collectUrlFromRelease(final ImportConfiguration configuration) {

    final ReleaseFileSet releaseFileSet = configuration.getReleaseFileSet();

    if (releaseFileSet == null) {
        return Collections.<URL>emptySet();
    }/*  w  w  w  . j av  a 2s.  c o m*/

    final Set<URL> collectedUrlSet = Sets.newHashSet();

    if (configuration.getSourceKind().equals(ImportSourceKind.ARCHIVE)) {

        final List<String> refSetsRelativePaths = releaseFileSet.getRefSetPaths();
        final String relativeRoot = releaseFileSet.getRelativeRoot();

        for (final String refSetPath : refSetsRelativePaths) {
            Set<URL> urlsFromZip = parseZip(configuration.getArchiveFile(), relativeRoot, refSetPath);
            collectedUrlSet.addAll(urlsFromZip.stream()
                    .filter(url -> !refSetPath.equals("Terminology") || url.getFile().contains("sct2_sRefset"))
                    .collect(Collectors.toSet()));
        }

    }

    return collectedUrlSet;
}

From source file:org.cinchapi.concourse.server.concurrent.RangeTokens.java

/**
 * Convert the {@code rangeToken} to the analogous {@link Range} object.
 * //from  w w  w.  j  a va 2  s .  c o m
 * @param rangeToken
 * @return the Range
 */
public static Set<Range<Value>> convertToRange(RangeToken rangeToken) {
    Set<Range<Value>> ranges = Sets.newHashSet();
    if (rangeToken.getOperator() == Operator.EQUALS || rangeToken.getOperator() == Operator.REGEX
            || rangeToken.getOperator() == null) { // null operator means
                                                                                                                                                 // the range token is for
                                                                                                                                                 // writing
        ranges.add(Range.point(rangeToken.getValues()[0]));
    } else if (rangeToken.getOperator() == Operator.NOT_EQUALS
            || rangeToken.getOperator() == Operator.NOT_REGEX) {
        ranges.add(Range.exclusive(Value.NEGATIVE_INFINITY, rangeToken.getValues()[0]));
        ranges.add(Range.exclusive(rangeToken.getValues()[0], Value.POSITIVE_INFINITY));
    } else if (rangeToken.getOperator() == Operator.GREATER_THAN) {
        ranges.add(Range.exclusive(rangeToken.getValues()[0], Value.POSITIVE_INFINITY));
    } else if (rangeToken.getOperator() == Operator.GREATER_THAN_OR_EQUALS) {
        ranges.add(Range.inclusiveExclusive(rangeToken.getValues()[0], Value.POSITIVE_INFINITY));
    } else if (rangeToken.getOperator() == Operator.LESS_THAN) {
        ranges.add(Range.exclusive(Value.NEGATIVE_INFINITY, rangeToken.getValues()[0]));
    } else if (rangeToken.getOperator() == Operator.LESS_THAN_OR_EQUALS) {
        ranges.add(Range.exclusiveInclusive(Value.NEGATIVE_INFINITY, rangeToken.getValues()[0]));
    } else if (rangeToken.getOperator() == Operator.BETWEEN) {
        ranges.add(Range.inclusiveExclusive(rangeToken.getValues()[0], rangeToken.getValues()[1]));
    } else {
        throw new UnsupportedOperationException();
    }
    return ranges;
}