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

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

Introduction

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

Prototype

public static <E> SetView<E> union(final Set<? extends E> set1, final Set<? extends E> set2) 

Source Link

Document

Returns an unmodifiable view of the union of two sets.

Usage

From source file:springfox.documentation.spi.service.contexts.OperationContext.java

public Set<MediaType> produces() {
    return Sets.union(requestContext.produces(), toMediaTypes(getDocumentationContext().getProduces()));
}

From source file:org.apache.zeppelin.presto.PrestoInterpreter.java

private SqlCompleter createSqlCompleter(Connection jdbcConnection) {

    SqlCompleter completer = null;//from w ww .  jav  a2  s  . co m
    try {
        Set<String> keywordsCompletions = SqlCompleter.getSqlKeywordsCompletions(jdbcConnection);
        Set<String> dataModelCompletions = SqlCompleter.getDataModelMetadataCompletions(jdbcConnection);
        SetView<String> allCompletions = Sets.union(keywordsCompletions, dataModelCompletions);
        completer = new SqlCompleter(allCompletions, dataModelCompletions);

    } catch (IOException | SQLException e) {
        logger.error("Cannot create SQL completer", e);
    }

    return completer;
}

From source file:org.semanticweb.elk.justifications.BloomSet.java

@Override
public Justification<C, A> addElements(Set<? extends A> added) {
    if (containsAll(added)) {
        return this;
    }/*w ww .j  a  v  a 2  s  . c om*/
    // else
    return new BloomSet<C, A>(conclusion_, Sets.union(this, added));
}

From source file:com.facebook.buck.core.model.impl.AbstractImmutableBuildTarget.java

@Override
public BuildTarget withAppendedFlavors(Set<Flavor> flavors) {
    return withFlavors(Sets.union(getFlavors(), flavors));
}

From source file:de.citec.sc.evaluator.Evaluator.java

public static Map<String, Double> add(Map<String, Double> r1, Map<String, Double> r2) {
    Map<String, Double> result = new LinkedHashMap<>();
    Set<String> keys = Sets.union(r1.keySet(), r2.keySet());
    for (String key : keys) {
        result.put(key, r1.getOrDefault(key, 0.0) + r2.getOrDefault(key, 0.0));
    }/* ww  w  .  j a v a  2s  .  c o m*/
    return result;
}

From source file:org.apache.james.jmap.model.MessageProperties.java

private MessageProperties ensureHeadersMessageProperty() {
    if (headersProperties.isPresent() && !headersProperties.get().isEmpty()) {
        return usingProperties(
                Sets.union(buildOutputMessageProperties(), ImmutableSet.of(MessageProperty.headers)));
    }//from   w w w  .  j a  va  2s . c o m
    return this;
}

From source file:ome.services.blitz.repo.path.FilePathRestrictions.java

/**
 * Combine sets of rules to form a set that satisfies them all.
 * @param rules at least one set of rules
 * @return the intersection of the given rules
 *//*  ww w.  ja  v a 2s .c  om*/
private static FilePathRestrictions combineRules(FilePathRestrictions... rules) {
    if (rules.length == 0) {
        throw new IllegalArgumentException("cannot combine an empty list of rules");
    }

    int index = 0;
    FilePathRestrictions product = rules[index++];

    while (index < rules.length) {
        final FilePathRestrictions toCombine = rules[index++];

        final Set<Character> safeCharacters = Sets.intersection(product.safeCharacters,
                toCombine.safeCharacters);

        if (safeCharacters.isEmpty()) {
            throw new IllegalArgumentException("cannot combine safe characters");
        }

        final Set<Integer> allKeys = Sets.union(product.transformationMatrix.keySet(),
                toCombine.transformationMatrix.keySet());
        final ImmutableMap<Integer, Collection<Integer>> productMatrixMap = product.transformationMatrix
                .asMap();
        final ImmutableMap<Integer, Collection<Integer>> toCombineMatrixMap = toCombine.transformationMatrix
                .asMap();
        final SetMultimap<Integer, Integer> newTransformationMatrix = HashMultimap.create();

        for (final Integer key : allKeys) {
            final Collection<Integer> values;
            if (!productMatrixMap.containsKey(key)) {
                values = toCombineMatrixMap.get(key);
            } else if (!toCombineMatrixMap.containsKey(key)) {
                values = productMatrixMap.get(key);
            } else {
                final Set<Integer> valuesSet = new HashSet<Integer>(productMatrixMap.get(key));
                valuesSet.retainAll(toCombineMatrixMap.get(key));
                if (valuesSet.isEmpty()) {
                    throw new IllegalArgumentException(
                            "cannot combine transformations for Unicode code point " + key);
                }
                values = valuesSet;
            }
            for (final Integer value : values) {
                newTransformationMatrix.put(key, value);
            }
        }

        final SetMultimap<Integer, Integer> entriesRemoved = HashMultimap.create();
        boolean transitiveClosing;
        do {
            transitiveClosing = false;
            for (final Entry<Integer, Integer> transformation : newTransformationMatrix.entries()) {
                final int to = transformation.getValue();
                if (newTransformationMatrix.containsKey(to)) {
                    final int from = transformation.getKey();
                    if (!entriesRemoved.put(from, to)) {
                        throw new IllegalArgumentException(
                                "cyclic transformation involving Unicode code point " + from);
                    }
                    newTransformationMatrix.remove(from, to);
                    newTransformationMatrix.putAll(from, newTransformationMatrix.get(to));
                    transitiveClosing = true;
                    break;
                }
            }
        } while (transitiveClosing);

        product = new FilePathRestrictions(newTransformationMatrix,
                Sets.union(product.unsafePrefixes, toCombine.unsafePrefixes),
                Sets.union(product.unsafeSuffixes, toCombine.unsafeSuffixes),
                Sets.union(product.unsafeNames, toCombine.unsafeNames), safeCharacters);
    }
    return product;
}

From source file:springfox.documentation.spi.service.contexts.OperationContext.java

public Set<MediaType> consumes() {
    return Sets.union(requestContext.consumes(), toMediaTypes(getDocumentationContext().getConsumes()));
}

From source file:org.eclipse.viatra.query.runtime.rete.construction.quasitree.JoinCandidate.java

public boolean isHeath() {
    if (heath == null) {
        Map<Set<PVariable>, Set<PVariable>> dependencies = analyzer.getFunctionalDependencies(
                Sets.union(primary.getAllEnforcedConstraints(), secondary.getAllEnforcedConstraints()), false);
        // does varCommon determine either varPrimary or varSecondary?
        Set<PVariable> varCommonClosure = FunctionalDependencyHelper.closureOf(varCommon, dependencies);

        heath = varCommonClosure.containsAll(varPrimary) || varCommonClosure.containsAll(varSecondary);
    }//from  w  w  w . java2  s  .c  o m
    return heath;
}

From source file:org.splevo.diffing.match.HierarchicalStrategyResourceMatcher.java

/**
 * Create the mappings between two lists of resources. If both lists contain only one resource,
 * they are always matches as assumed this was triggered explicitly.<br>
 * {@inheritDoc}/*  w w  w . ja v a2s  .  co m*/
 */
@Override
public Iterable<MatchResource> createMappings(Iterator<? extends Resource> leftResources,
        Iterator<? extends Resource> rightResources, Iterator<? extends Resource> originResources) {

    final List<MatchResource> mappings = new ArrayList<MatchResource>();

    indexResources(leftResources, filenameResourcesIndexLeft, filenameNormalizationPatterns);
    indexResources(rightResources, filenameResourcesIndexRight, null);

    Set<String> allSegments = Sets.union(filenameResourcesIndexLeft.keySet(),
            filenameResourcesIndexRight.keySet());
    List<String> allSegmentsCopy = Lists.newArrayList(allSegments);

    for (String segment : allSegmentsCopy) {

        List<Resource> leftCandidates = Lists.newArrayList(filenameResourcesIndexLeft.get(segment));
        List<Resource> rightCandidates = Lists.newArrayList(filenameResourcesIndexRight.get(segment));

        if (leftCandidates.size() == 1 && rightCandidates.size() == 1) {
            Resource left = leftCandidates.get(0);
            Resource right = rightCandidates.get(0);
            mappings.add(createMatchResource(left, right, null));
            removeFromIndex(filenameResourcesIndexLeft, left);
            removeFromIndex(filenameResourcesIndexRight, right);

        } else if (leftCandidates.size() != 0 && rightCandidates.size() != 0) {
            matchBestMatches(leftCandidates, rightCandidates, mappings);
        }
    }

    Collection<Resource> remainingLeftResources = Sets.newLinkedHashSet(filenameResourcesIndexLeft.values());
    for (Resource left : remainingLeftResources) {
        mappings.add(createMatchResource(left, null, null));
    }
    Collection<Resource> remainingRightResources = Sets.newLinkedHashSet(filenameResourcesIndexRight.values());
    for (Resource right : remainingRightResources) {
        mappings.add(createMatchResource(null, right, null));
    }

    return mappings;
}