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.opengamma.strata.function.calculation.swap.SwapCalculationFunction.java

@Override
public FunctionRequirements requirements(SwapTrade trade, Set<Measure> measures) {
    Swap product = trade.getProduct();/*  w  w w . ja  va2 s. co m*/

    // no market data for leg initial notional
    if (measures.equals(ImmutableSet.of(Measures.LEG_INITIAL_NOTIONAL))) {
        return FunctionRequirements.builder().outputCurrencies(
                product.getLegs().stream().map(SwapLeg::getCurrency).collect(toImmutableSet())).build();
    }

    // market data needed
    Set<Index> indices = product.allIndices();
    Set<ObservableKey> indexRateKeys = indices.stream().map(IndexRateKey::of).collect(toImmutableSet());
    Set<MarketDataKey<?>> indexCurveKeys = indices.stream().map(MarketDataKeys::indexCurve)
            .collect(toImmutableSet());
    Set<DiscountCurveKey> discountCurveKeys = product.getLegs().stream().map(SwapLeg::getCurrency)
            .map(DiscountCurveKey::of).collect(toImmutableSet());

    return FunctionRequirements.builder().singleValueRequirements(Sets.union(indexCurveKeys, discountCurveKeys))
            .timeSeriesRequirements(indexRateKeys)
            .outputCurrencies(product.getLegs().stream().map(SwapLeg::getCurrency).collect(toImmutableSet()))
            .build();
}

From source file:org.fenixedu.treasury.domain.document.CreditEntry.java

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

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

@Override
public ReasonerQuery conjunction(ReasonerQuery q) {
    return new ReasonerQueryImpl(Sets.union(getAtoms(), q.getAtoms()), this.tx());
}

From source file:org.apache.beam.runners.fnexecution.wire.LengthPrefixUnknownCoders.java

private static MessageWithComponents createLengthPrefixByteArrayCoder(String coderId,
        RunnerApi.Components components) {
    MessageWithComponents.Builder rvalBuilder = MessageWithComponents.newBuilder();

    String byteArrayCoderId = generateUniqueId(coderId + "-byte_array", Sets
            .union(components.getCodersMap().keySet(), rvalBuilder.getComponents().getCodersMap().keySet()));
    Coder.Builder byteArrayCoder = Coder.newBuilder();
    byteArrayCoder.getSpecBuilder().getSpecBuilder().setUrn(ModelCoders.BYTES_CODER_URN);
    rvalBuilder.getComponentsBuilder().putCoders(byteArrayCoderId, byteArrayCoder.build());
    rvalBuilder.getCoderBuilder().addComponentCoderIds(byteArrayCoderId).getSpecBuilder().getSpecBuilder()
            .setUrn(ModelCoders.LENGTH_PREFIX_CODER_URN);

    return rvalBuilder.build();
}

From source file:fr.aliacom.obm.common.calendar.EventNotificationServiceImpl.java

@Override
public void notifyDeletedEvent(Event event, AccessToken token) {
    if (eventDeletionInvolveNotification(event)) {
        ObmUser user = userService.getUserFromAccessToken(token);
        Ical4jUser buildIcal4jUser = calendarFactory.createIcal4jUserFromObmUser(user);
        String ics = ical4jHelper.buildIcsInvitationCancel(buildIcal4jUser, event, token);

        Attendee owner = event.findOwner();

        Collection<Attendee> attendees = filterAttendees(event, ensureAttendeeUnicity(event.getAttendees()));
        Map<Participation, Set<Attendee>> attendeeGroups = computeParticipationGroups(attendees);
        Set<Attendee> notify = Sets.union(attendeeGroups.get(Participation.needsAction()),
                attendeeGroups.get(Participation.accepted()));

        UserSettings settings = settingsService.getSettings(user);
        if (!notify.isEmpty()) {
            eventChangeMailer.notifyRemovedUsers(user, notify, event, settings.locale(), settings.timezone(),
                    ics, token);//w w  w . j av a  2  s  . c o  m
        }
        if (owner != null && !isUserEventOwner(user, event)) {
            eventChangeMailer.notifyOwnerRemovedEvent(user, owner, event, settings.locale(),
                    settings.timezone(), token);
        }
    }
}

From source file:org.caleydo.view.crossword.api.model.TypedSet.java

private static TypedSet union(BitSetSet a, TypedSet b) {
    if (b.wrappee instanceof BitSetSet) {
        BitSet clone = (BitSet) a.getBitSet().clone();
        clone.or(((BitSetSet) b.wrappee).getBitSet());
        return new TypedSet(new BitSetSet(clone), b.idType);
    }/*  w  w w  . j  a v a 2 s  . c  o m*/
    return new TypedSet(ImmutableSet.copyOf(Sets.union(b, a)), b.idType); // as the predicate is: in the second
    // argument
}

From source file:org.jclouds.digitalocean.compute.strategy.CreateKeyPairsThenCreateNodes.java

@Override
public Map<?, ListenableFuture<Void>> execute(String group, int count, Template template,
        Set<NodeMetadata> goodNodes, Map<NodeMetadata, Exception> badNodes,
        Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {

    DigitalOceanTemplateOptions options = template.getOptions().as(DigitalOceanTemplateOptions.class);
    Set<Integer> generatedSshKeyIds = Sets.newHashSet();

    // If no key has been configured and the auto-create option is set, then generate a key pair
    if (options.getSshKeyIds().isEmpty() && options.getAutoCreateKeyPair()
            && Strings.isNullOrEmpty(options.getPublicKey())) {
        generateKeyPairAndAddKeyToSet(options, generatedSshKeyIds);
    }/*from   w ww .j  a va2  s.  c  o m*/

    // If there is a script to run in the node, make sure a pivate key has been configured so jclouds will be able to
    // access the node
    if (options.getRunScript() != null && Strings.isNullOrEmpty(options.getLoginPrivateKey())) {
        logger.warn(">> A runScript has been configured but no SSH key has been provided."
                + " Authentication will delegate to the ssh-agent");
    }

    // If there is a key configured, then make sure there is a key pair for it
    if (!Strings.isNullOrEmpty(options.getPublicKey())) {
        createKeyPairForPublicKeyInOptionsAndAddToSet(options, generatedSshKeyIds);
    }

    // Set all keys (the provided and the auto-generated) in the options object so the
    // DigitalOceanComputeServiceAdapter adds them all
    options.sshKeyIds(Sets.union(generatedSshKeyIds, options.getSshKeyIds()));

    Map<?, ListenableFuture<Void>> responses = super.execute(group, count, template, goodNodes, badNodes,
            customizationResponses);

    // Key pairs in DigitalOcean are only required to create the Droplets. They aren't used anymore so it is better
    // to delete the auto-generated key pairs at this point where we know exactly which ones have been
    // auto-generated by jclouds.
    registerAutoGeneratedKeyPairCleanupCallbacks(responses, generatedSshKeyIds);

    return responses;
}

From source file:org.onosproject.net.link.impl.LinkManager.java

@Override
public Set<Link> getLinks(ConnectPoint connectPoint) {
    checkPermission(LINK_READ);//  w ww .j a  v a  2 s  . c o  m
    checkNotNull(connectPoint, CONNECT_POINT_NULL);
    return Sets.union(store.getEgressLinks(connectPoint), store.getIngressLinks(connectPoint));
}

From source file:com.wrmsr.wava.analyze.ValueTypeAnalysis.java

private static ImMap<Name, Set<Type>> mergeBreakValueTypes(Iterator<ImMap<Name, Set<Type>>> it) {
    ImMap<Name, Set<Type>> ret = EMPTY_BREAK_VALUE_TYPES;
    while (it.hasNext()) {
        ImMap<Name, Set<Type>> cur = it.next();
        for (Map.Entry<Name, Set<Type>> entry : cur.entrySet()) {
            ret = ret.assoc(entry.getKey(), immutableEnumSet(
                    Sets.union(cur.getOrElse(entry.getKey(), ImmutableSet.of()), entry.getValue())));
        }//from w  w w .j  a  va2  s.c om
    }
    return ret;
}

From source file:io.prestosql.verifier.VerifyCommand.java

public void run() {
    if (configFilename != null) {
        // Read//from   w ww  .  j  av  a  2s. com
        System.setProperty("config", configFilename);
    }

    ImmutableList.Builder<Module> builder = ImmutableList.<Module>builder().add(new PrestoVerifierModule())
            .addAll(getAdditionalModules());

    Bootstrap app = new Bootstrap(builder.build());
    Injector injector;
    try {
        injector = app.strictConfig().initialize();
    } catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }

    try {
        VerifierConfig config = injector.getInstance(VerifierConfig.class);
        injector.injectMembers(this);
        Set<String> supportedEventClients = injector.getInstance(Key.get(new TypeLiteral<Set<String>>() {
        }, SupportedEventClients.class));
        for (String clientType : config.getEventClients()) {
            checkArgument(supportedEventClients.contains(clientType), "Unsupported event client: %s",
                    clientType);
        }
        Set<EventClient> eventClients = injector.getInstance(Key.get(new TypeLiteral<Set<EventClient>>() {
        }));

        VerifierDao dao = Jdbi.create(getQueryDatabase(injector)).installPlugin(new SqlObjectPlugin())
                .onDemand(VerifierDao.class);

        ImmutableList.Builder<QueryPair> queriesBuilder = ImmutableList.builder();
        for (String suite : config.getSuites()) {
            queriesBuilder.addAll(dao.getQueriesBySuite(suite, config.getMaxQueries()));
        }

        List<QueryPair> queries = queriesBuilder.build();
        queries = applyOverrides(config, queries);
        queries = filterQueryTypes(new SqlParser(getParserOptions()), config, queries);
        queries = filterQueries(queries);
        if (config.getShadowWrites()) {
            Sets.SetView<QueryType> allowedTypes = Sets.union(config.getTestQueryTypes(),
                    config.getControlQueryTypes());
            checkArgument(!Sets.intersection(allowedTypes, ImmutableSet.of(CREATE, MODIFY)).isEmpty(),
                    "CREATE or MODIFY queries must be allowed in test or control to use write shadowing");
            queries = rewriteQueries(new SqlParser(getParserOptions()), config, queries);
        }

        // Load jdbc drivers if needed
        if (config.getAdditionalJdbcDriverPath() != null) {
            List<URL> urlList = getUrls(config.getAdditionalJdbcDriverPath());
            URL[] urls = new URL[urlList.size()];
            urlList.toArray(urls);
            if (config.getTestJdbcDriverName() != null) {
                loadJdbcDriver(urls, config.getTestJdbcDriverName());
            }
            if (config.getControlJdbcDriverName() != null) {
                loadJdbcDriver(urls, config.getControlJdbcDriverName());
            }
        }

        // TODO: construct this with Guice
        int numFailedQueries = new Verifier(System.out, config, eventClients).run(queries);
        System.exit((numFailedQueries > 0) ? 1 : 0);
    } catch (InterruptedException | MalformedURLException e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    } finally {
        try {
            injector.getInstance(LifeCycleManager.class).stop();
        } catch (Exception e) {
            throwIfUnchecked(e);
            throw new RuntimeException(e);
        }
    }
}