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:com.google.enterprise.adaptor.Acl.java

/**
 * Returns immutable set of permitted users and groups.
 */
public Set<Principal> getPermits() {
    return Sets.union(permitUsers, permitGroups);
}

From source file:org.cloudbees.literate.api.v1.ExecutionEnvironment.java

/**
 * Returns the components (labels, variables) that define the environment.
 * //from  w w  w. j  a  v a 2 s.c  o  m
 * @return the components (labels, variables) that define the environment.
 */
public Set<String> getComponents() {
    return Sets.union(labels, getVariablesAsSet());
}

From source file:com.facebook.buck.jvm.java.JavaInMemoryFileManager.java

public ImmutableSet<String> getEntries() {
    return ImmutableSet.copyOf(Sets.union(directoryPaths, javaFileForOutputPaths));
}

From source file:com.opengamma.strata.function.calculation.credit.CdsCalculationFunction.java

@Override
public FunctionRequirements requirements(CdsTrade trade, Set<Measure> measures) {
    Cds cds = trade.getProduct();// ww w . j a v a2  s  .com

    Currency notionalCurrency = cds.getFeeLeg().getPeriodicPayments().getNotional().getCurrency();
    Currency feeCurrency = cds.getFeeLeg().getUpfrontFee().getCurrency();

    Set<MarketDataKey<?>> rateCurveKeys = ImmutableSet.of(IsdaYieldCurveInputsKey.of(notionalCurrency),
            IsdaYieldCurveInputsKey.of(feeCurrency));

    Set<Currency> currencies = ImmutableSet.of(notionalCurrency, feeCurrency);
    ReferenceInformation refInfo = cds.getReferenceInformation();
    if (refInfo instanceof SingleNameReferenceInformation) {
        SingleNameReferenceInformation singleNameRefInfo = (SingleNameReferenceInformation) refInfo;
        Set<MarketDataKey<?>> keys = ImmutableSet.of(IsdaSingleNameCreditCurveInputsKey.of(singleNameRefInfo),
                IsdaSingleNameRecoveryRateKey.of(singleNameRefInfo));
        return FunctionRequirements.builder().singleValueRequirements(Sets.union(rateCurveKeys, keys))
                .outputCurrencies(currencies).build();

    } else if (refInfo instanceof IndexReferenceInformation) {
        IndexReferenceInformation indexRefInfo = (IndexReferenceInformation) refInfo;
        Set<MarketDataKey<?>> keys = ImmutableSet.of(IsdaIndexCreditCurveInputsKey.of(indexRefInfo),
                IsdaIndexRecoveryRateKey.of(indexRefInfo));
        return FunctionRequirements.builder().singleValueRequirements(Sets.union(rateCurveKeys, keys))
                .outputCurrencies(currencies).build();

    } else {
        throw new IllegalStateException("Unknown reference information type: " + refInfo.getType());
    }
}

From source file:org.diqube.executionenv.FlattenedTableInstanceManager.java

@PostConstruct
public void initialize() {
    // Use a CountCleanupStrategy that cleans up everything that was already evicted from the cache: If something was
    // evicted from the cache, we definitely
    // won't offer it again, since we will not use that same versionId again. Therefore we can free up the count memory
    // of those./*from w  ww . j  a  v a  2 s . com*/
    // Additionally we remove the counts of every version that is in #countCleanupCacheEntries. These are old versions.
    // If anybody still needs those versions, they must have flagged those elements in the cache, otherwise their
    // entries will have count 0 and that will most probably lead to them being evicted from the cache on the next run.
    CountCleanupStrategy<Pair<String, String>, UUID> cacheCountCleanupStrategy = (countsForCleanup,
            allCounts) -> {
        Set<Pair<Pair<String, String>, UUID>> curCountCleanupCacheEntries = new HashSet<>();
        while (!countCleanupCacheEntries.isEmpty()) {
            try {
                curCountCleanupCacheEntries.add(countCleanupCacheEntries.pop());
            } catch (NoSuchElementException e) {
                // swallow -> two thread concurrently traversed countCleanupCacheEntries and our thread did not get another
                // element. Thats fine. (Although this will not happen currently, since CountingCache synchronizes).
            }
        }

        Set<Pair<Pair<String, String>, UUID>> res = Sets.union(countsForCleanup,
                Sets.intersection(allCounts, curCountCleanupCacheEntries));
        logger.trace("Evicting old usage counts (limit): {}", Iterables.limit(res, 100));
        return res;
    };

    MemoryConsumptionProvider<FlattenedTableInfo> cacheMemoryConsumptionProvider = info -> info
            .getFlattenedTable().calculateApproximateSizeInBytes();

    cache = new CountingCache<>(flattenedTableCacheSizeMb * 1024L * 1024L, cacheMemoryConsumptionProvider,
            cacheCountCleanupStrategy);
}

From source file:org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.SourceMapper.java

private void createRemoteTunnels(OfWriter ofWriter, NodeId nodeId, Endpoint ep,
        EndpointFwdCtxOrdinals epFwdCtxOrds) throws Exception {
    Set<EgKey> epgs = new HashSet<>();

    // Get EPGs and add to Set to remove duplicates
    // TODO alagalah Li: test EndpointManager.getEgKeys
    if (ep.getEndpointGroup() != null) {
        epgs.add(new EgKey(ep.getTenant(), ep.getEndpointGroup()));
    }//from   ww  w.j a v  a2  s.c om
    if (ep.getEndpointGroups() != null) {
        for (EndpointGroupId epgId : ep.getEndpointGroups()) {
            epgs.add(new EgKey(ep.getTenant(), epgId));
        }
    }

    // Create tunnels on remote Nodes that may talk to us.
    for (EgKey epg : epgs) {
        Set<EgKey> peers = Sets.union(Collections.singleton(epg), ctx.getCurrentPolicy().getPeers(epg));
        for (EgKey peer : peers) {
            for (NodeId remoteNodeId : ctx.getEndpointManager().getNodesForGroup(peer)) {

                // Please do not check for remote v local nodeID, we need local to local tunnels
                // in the case of chaining - The Great Dr Sunal.
                NodeConnectorId tunPort = ctx.getSwitchManager().getTunnelPort(remoteNodeId,
                        TunnelTypeVxlan.class);
                if (tunPort == null) {
                    LOG.trace("No tunnel port for tunnel in SourceMapper between local:{} and remote:{}",
                            nodeId.getValue(), remoteNodeId.getValue());
                    continue;
                }
                ofWriter.writeFlow(remoteNodeId, TABLE_ID, createTunnelFlow(tunPort, epFwdCtxOrds));
                ofWriter.writeFlow(remoteNodeId, TABLE_ID, createBroadcastFlow(tunPort, epFwdCtxOrds));
            }
        }
    }
}

From source file:com.eucalyptus.autoscaling.common.internal.groups.PersistenceAutoScalingGroups.java

@Override
public void markScalingRequiredForZones(final Set<String> availabilityZones)
        throws AutoScalingMetadataException {
    if (!availabilityZones.isEmpty()) {
        persistenceSupport.transactionWithRetry(AutoScalingGroup.class,
                new AbstractOwnedPersistents.WorkCallback<Void>() {
                    @Override//from  w ww.  ja  v  a2 s.  c  o m
                    public Void doWork() throws AutoScalingMetadataException {
                        final List<AutoScalingGroup> groups = persistenceSupport.listByExample(
                                AutoScalingGroup.withOwner(null), Predicates.alwaysTrue(),
                                Functions.<AutoScalingGroup>identity());
                        for (final AutoScalingGroup group : groups) {
                            if (!Sets.union(Sets.newHashSet(group.getAvailabilityZones()), availabilityZones)
                                    .isEmpty()) {
                                group.setScalingRequired(true);
                            }
                        }
                        return null;
                    }
                });
    }
}

From source file:com.opengamma.strata.measure.rate.DefaultRatesMarketDataLookup.java

@Override
public FunctionRequirements requirements(Set<Currency> currencies, Set<? extends Index> indices) {
    for (Currency currency : currencies) {
        if (!discountCurves.keySet().contains(currency)) {
            throw new IllegalArgumentException(msgCurrencyNotFound(currency));
        }//from  w  ww  .j  a  v  a2  s  .  c  o  m
    }
    for (Index index : indices) {
        if (!forwardCurves.keySet().contains(index)) {
            throw new IllegalArgumentException(msgIndexNotFound(index));
        }
    }

    // keys for time-series
    Set<ObservableId> indexQuoteIds = indices.stream().map(IndexQuoteId::of).collect(toImmutableSet());

    // keys for forward curves
    Set<MarketDataId<?>> indexCurveIds = indices.stream().map(idx -> forwardCurves.get(idx))
            .collect(toImmutableSet());

    // keys for discount factors
    Set<MarketDataId<?>> discountFactorsIds = currencies.stream().map(ccy -> discountCurves.get(ccy))
            .collect(toImmutableSet());

    return FunctionRequirements.builder().valueRequirements(Sets.union(indexCurveIds, discountFactorsIds))
            .timeSeriesRequirements(indexQuoteIds).outputCurrencies(currencies)
            .observableSource(observableSource).build();
}

From source file:grakn.core.graql.reasoner.query.ReasonerQueryImpl.java

@Override
public ReasonerQueryImpl withSubstitution(ConceptMap sub) {
    return new ReasonerQueryImpl(Sets.union(this.getAtoms(), AtomicFactory.answerToPredicates(sub, this)),
            this.tx());
}

From source file:org.onosproject.store.resource.impl.EncodableDiscreteResources.java

@Override
public DiscreteResources add(DiscreteResources other) {
    if (other instanceof EncodableDiscreteResources) {
        EncodableDiscreteResources cast = (EncodableDiscreteResources) other;
        LinkedHashMap<Class<?>, EncodedDiscreteResources> newMap = Stream
                .concat(this.map.entrySet().stream(), cast.map.entrySet().stream())
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, EncodedDiscreteResources::add,
                        LinkedHashMap::new));
        return of(parent, newMap);
    } else if (other instanceof EmptyDiscreteResources) {
        return this;
    }/*from w  ww.  j a  v  a2 s  .c o m*/

    return DiscreteResources.of(Sets.union(this.values(), other.values()));
}