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:org.fenixedu.treasury.domain.document.CreditEntry.java

public static Stream<? extends CreditEntry> findActive(final TreasuryEvent treasuryEvent) {
    return DebitEntry.findActive(treasuryEvent).map(d -> d.getCreditEntriesSet())
            .reduce((a, b) -> Sets.union(a, b)).orElse(Sets.newHashSet()).stream();
}

From source file:io.druid.data.input.impl.DimensionsSpec.java

public DimensionsSpec withDimensionExclusions(Set<String> dimExs) {
    return new DimensionsSpec(dimensions, ImmutableList.copyOf(Sets.union(dimensionExclusions, dimExs)), null);
}

From source file:org.dllearner.algorithms.CELOEWrapper.java

private OWLOntology buildFragment(Set<OWLIndividual> posExamples, Set<OWLIndividual> negExamples) {
    StringBuilder filter = new StringBuilder("VALUES ?s0 {");
    for (OWLIndividual ind : Sets.union(posExamples, negExamples)) {
        filter.append(ind).append(" ");
    }//from  w  ww. j a  v a 2 s.  com
    filter.append("}");

    StringBuilder sb = new StringBuilder("CONSTRUCT {");
    sb.append("?s0 ?p0 ?o0 . ?p0 a ?p_type0 .");
    for (int i = 1; i < maxClassExpressionDepth; i++) {
        sb.append("?o").append(i - 1).append(" ?p").append(i).append(" ?o").append(i).append(" .");
        sb.append("?p").append(i).append(" a ").append(" ?p_type").append(i).append(" .");
    }
    sb.append("} WHERE {");
    sb.append("?s0 ?p0 ?o0 . OPTIONAL{?p0 a ?p_type0 .}");

    for (int i = 1; i < maxClassExpressionDepth; i++) {
        sb.append("OPTIONAL {");
        sb.append("?o").append(i - 1).append(" ?p").append(i).append(" ?o").append(i).append(" .");
        sb.append("OPTIONAL{").append("?p").append(i).append(" a ").append(" ?p_type").append(i).append(" .}");
    }
    for (int i = 1; i < maxClassExpressionDepth; i++) {
        sb.append("}");
    }
    sb.append(filter);
    sb.append("}");

    QueryExecutionFactoryPaginated qef = new QueryExecutionFactoryPaginated(super.qef, 10000);
    QueryExecution qe = qef.createQueryExecution(sb.toString());
    Model sample = qe.execConstruct();
    qe.close();

    StmtIterator iter = sample.listStatements();
    while (iter.hasNext()) {
        Statement st = iter.next();
        if (st.getObject().isLiteral() && st.getObject().asLiteral().getDatatype() != null) {
            try {
                st.getObject().asLiteral().getValue();
            } catch (Exception e) {
                iter.remove();
            }
        }
    }

    //      org.dllearner.utilities.owl.
    OWLEntityTypeAdder.addEntityTypes(sample);
    return OwlApiJenaUtils.getOWLOntology(sample);
}

From source file:org.apache.brooklyn.util.collections.CollectionMerger.java

private Map<?, ?> mergeMapsImpl(Map<?, ?> val1, Map<?, ?> val2, int depthRemaining, Visited visited) {
    if (depthRemaining < 1) {
        return val1;
    }//from   ww w  . j  ava 2  s. c om
    MutableMap<Object, Object> result = MutableMap.of();
    for (Object key : Sets.union(val1.keySet(), val2.keySet())) {
        Maybe<?> sub1 = val1.containsKey(key) ? Maybe.of(val1.get(key)) : Maybe.absent();
        Maybe<?> sub2 = val2.containsKey(key) ? Maybe.of(val2.get(key)) : Maybe.absent();
        result.put(key, mergeImpl(sub1, sub2, depthRemaining - 1, visited));
    }
    return result;
}

From source file:org.apache.cassandra.cql.CreateColumnFamilyStatement.java

/** Perform validation of parsed params */
private void validate() throws InvalidRequestException {
    // Column family name
    if (!name.matches("\\w+"))
        throw new InvalidRequestException(String.format("\"%s\" is not a valid column family name", name));

    // Catch the case where someone passed a kwarg that is not recognized.
    for (String bogus : Sets.difference(properties.keySet(), Sets.union(keywords, obsoleteKeywords)))
        throw new InvalidRequestException(bogus + " is not a valid keyword argument for CREATE COLUMNFAMILY");
    for (String obsolete : Sets.intersection(properties.keySet(), obsoleteKeywords))
        logger.warn("Ignoring obsolete property {}", obsolete);

    // Validate min/max compaction thresholds
    Integer minCompaction = getPropertyInt(KW_MINCOMPACTIONTHRESHOLD, null);
    Integer maxCompaction = getPropertyInt(KW_MAXCOMPACTIONTHRESHOLD, null);

    if ((minCompaction != null) && (maxCompaction != null)) // Both min and max are set
    {/*from  w  ww  .  j  a  va2  s  .c  o  m*/
        if ((minCompaction > maxCompaction) && (maxCompaction != 0))
            throw new InvalidRequestException(String.format("%s cannot be larger than %s",
                    KW_MINCOMPACTIONTHRESHOLD, KW_MAXCOMPACTIONTHRESHOLD));
    } else if (minCompaction != null) // Only the min threshold is set
    {
        if (minCompaction > CFMetaData.DEFAULT_MAX_COMPACTION_THRESHOLD)
            throw new InvalidRequestException(
                    String.format("%s cannot be larger than %s, (default %s)", KW_MINCOMPACTIONTHRESHOLD,
                            KW_MAXCOMPACTIONTHRESHOLD, CFMetaData.DEFAULT_MAX_COMPACTION_THRESHOLD));
    } else if (maxCompaction != null) // Only the max threshold is set
    {
        if ((maxCompaction < CFMetaData.DEFAULT_MIN_COMPACTION_THRESHOLD) && (maxCompaction != 0))
            throw new InvalidRequestException(
                    String.format("%s cannot be smaller than %s, (default %s)", KW_MAXCOMPACTIONTHRESHOLD,
                            KW_MINCOMPACTIONTHRESHOLD, CFMetaData.DEFAULT_MIN_COMPACTION_THRESHOLD));
    }

    // Ensure that exactly one key has been specified.
    if (keyValidator.size() < 1)
        throw new InvalidRequestException("You must specify a PRIMARY KEY");
    else if (keyValidator.size() > 1)
        throw new InvalidRequestException("You may only specify one PRIMARY KEY");

    AbstractType<?> comparator;

    try {
        comparator = getComparator();
    } catch (ConfigurationException e) {
        throw new InvalidRequestException(e.toString());
    }

    for (Map.Entry<Term, String> column : columns.entrySet()) {
        ByteBuffer name = column.getKey().getByteBuffer(comparator);

        if (keyAlias != null && keyAlias.equals(name))
            throw new InvalidRequestException("Invalid column name: " + column.getKey().getText()
                    + ", because it equals to the key_alias.");

    }
}

From source file:org.apache.metron.stellar.common.utils.ConcatMap.java

/**
 * This is a lazy entry collection of the associated maps.  If there are duplicate keys, they will appear
 * twice here, so be careful./*from   w  ww .ja v  a2s .  c o  m*/
 * @return
 */
@Override
public Set<Entry<String, Object>> entrySet() {
    Set<Entry<String, Object>> ret = null;
    for (Map m : variableMappings) {
        if (ret == null) {
            ret = m.entrySet();
        } else {
            ret = Sets.union(ret, m.entrySet());
        }
    }
    return ret;
}

From source file:fr.aliacom.obm.common.domain.ObmDomain.java

public Set<String> getNames() {
    return Sets.union(ImmutableSet.of(name), aliases);
}

From source file:org.dita.dost.util.FilterUtils.java

@VisibleForTesting
public FilterUtils(boolean isPrintType, Map<FilterKey, Action> filterMap, String foregroundConflictColor,
        String backgroundConflictColor, Set<QName> filterAttributes, Set<QName> flagAttributes) {
    this(isPrintType, filterMap, foregroundConflictColor, backgroundConflictColor);
    this.filterAttributes = Sets.union(this.filterAttributes, filterAttributes);
    this.flagAttributes = Sets.union(this.flagAttributes, flagAttributes);
}

From source file:es.usc.citius.composit.core.composition.search.ForwardServiceDiscoverer.java

public ServiceMatchNetwork<E, T> search(Signature<E> signature) {
    Set<E> availableInputs = new HashSet<E>(signature.getInputs());
    Set<E> newOutputs = new HashSet<E>(signature.getInputs());
    Set<E> unmatchedOutputs = new HashSet<E>(signature.getOutputs());
    Set<Operation<E>> usedServices = new HashSet<Operation<E>>();
    Map<Operation<E>, Set<E>> unmatchedInputMap = new HashMap<Operation<E>, Set<E>>();
    List<Set<Operation<E>>> leveledOps = new LinkedList<Set<Operation<E>>>();

    boolean checkExpectedOutputs = !signature.getOutputs().isEmpty();
    boolean stop;

    Stopwatch timer = Stopwatch.createStarted();
    Stopwatch levelTimer = Stopwatch.createUnstarted();
    int level = 0;
    do {//  w  w  w . jav  a 2 s  .  com
        HashSet<Operation<E>> candidates = new HashSet<Operation<E>>();
        levelTimer.start();
        candidates.addAll(discovery.findOperationsConsumingSome(newOutputs));
        log.info("(Level {}) {} potential candidates selected in {}", level++, candidates.size(),
                levelTimer.toString());
        // Remove services that cannot be invoked with the available inputs
        for (Iterator<Operation<E>> it = candidates.iterator(); it.hasNext();) {
            Operation<E> candidate = it.next();
            // Retrieve the unmatched inputs for this operation
            Set<E> unmatchedInputs = unmatchedInputMap.get(candidate);
            if (unmatchedInputs == null) {
                unmatchedInputs = candidate.getSignature().getInputs();
            }
            // Check if the new concepts match some unmatched inputs
            Set<E> matched = matcher.partialMatch(newOutputs, unmatchedInputs).getTargetElements();

            // Don't check invokability
            if (relaxedMatchCondition) {
                // Remove only if there is no match at all
                if (matched.isEmpty()) {
                    it.remove();
                } else {
                    boolean isNew = usedServices.add(candidate);
                    if (!isNew)
                        it.remove();
                }
            } else {
                // Update the unmatchedInputs
                unmatchedInputs = Sets.newHashSet(Sets.difference(unmatchedInputs, matched));
                unmatchedInputMap.put(candidate, unmatchedInputs);
                // If there are no unmatched inputs, the service is invokable!
                if (!unmatchedInputs.isEmpty()) {
                    it.remove();
                } else {
                    // Invokable operation, check if it was used previously
                    boolean isNew = usedServices.add(candidate);
                    if (!isNew)
                        it.remove();
                }
            }
        }
        log.info("\t + [{}] operations selected for this level in {}", candidates.size(),
                levelTimer.toString());
        log.debug("\t\t Candidates: {}", candidates);

        // Collect the new outputs of the new candidates
        Set<E> nextOutputs = Operations.outputs(candidates);

        // Check unmatched outputs
        Set<E> matchedOutputs = matcher.partialMatch(Sets.union(newOutputs, nextOutputs), unmatchedOutputs)
                .getTargetElements();
        //Set<Resource> matchedOutputs = matcher.matched(newOutputs, unmatchedOutputs);
        // Update the unmatched outputs
        unmatchedOutputs = Sets.newHashSet(Sets.difference(unmatchedOutputs, matchedOutputs));

        // Update for the next iteration
        availableInputs.addAll(newOutputs);
        newOutputs = nextOutputs;

        // Add the discovered ops
        if (!candidates.isEmpty())
            leveledOps.add(candidates);

        log.debug("\t + Available inputs: {}, new outputs: {}", availableInputs.size(), newOutputs.size());
        // Stop condition. Stop if there are no more candidates and/or expected outputs are satisfied.
        stop = (checkExpectedOutputs) ? candidates.isEmpty() || unmatchedOutputs.isEmpty()
                : candidates.isEmpty();
        levelTimer.reset();
    } while (!stop);

    // Add the source and sink operations
    Source<E> sourceOp = new Source<E>(signature.getInputs());
    Sink<E> sinkOp = new Sink<E>(signature.getOutputs());
    leveledOps.add(0, Collections.<Operation<E>>singleton(sourceOp));
    leveledOps.add(leveledOps.size(), Collections.<Operation<E>>singleton(sinkOp));
    Stopwatch networkWatch = Stopwatch.createStarted();
    // Create a service match network with the discovered services
    DirectedAcyclicSMN<E, T> matchNetwork = new DirectedAcyclicSMN<E, T>(new HashLeveledServices<E>(leveledOps),
            this.matcher);
    log.info(" > Service match network computed in {}", networkWatch.stop().toString());
    log.info("Service Match Network created with {} levels (including source and sink) and {} operations.",
            leveledOps.size(), matchNetwork.listOperations().size());
    log.info("Forward Discovery done in {}", timer.toString());
    this.unmatchedInputMap = unmatchedInputMap;
    return matchNetwork;
}

From source file:com.facebook.buck.features.haskell.HaskellLibraryDescription.java

private BuildTarget getBaseBuildTarget(HaskellPlatformsProvider haskellPlatformsProvider, BuildTarget target) {
    return target.withoutFlavors(
            Sets.union(Type.FLAVOR_VALUES, haskellPlatformsProvider.getHaskellPlatforms().getFlavors()));
}