Example usage for java.util StringJoiner add

List of usage examples for java.util StringJoiner add

Introduction

In this page you can find the example usage for java.util StringJoiner add.

Prototype

public StringJoiner add(CharSequence newElement) 

Source Link

Document

Adds a copy of the given CharSequence value as the next element of the StringJoiner value.

Usage

From source file:info.archinnov.achilles.internals.codegen.meta.EntityMetaCodeGen.java

private MethodSpec buildCounterColumns(List<FieldMetaSignature> parsingResults, TypeName rawClassType) {
    StringJoiner joiner = new StringJoiner(",");
    parsingResults.stream().filter(x -> x.context.columnType == COUNTER)
            .map(x -> Tuple2.of(x.context.cqlColumn, x.context.fieldName)).sorted(BY_CQL_NAME_COLUMN_SORTER)
            .map(x -> x._2()).forEach(x -> joiner.add(x));

    return MethodSpec.methodBuilder("getCounterColumns").addAnnotation(Override.class)
            .addModifiers(Modifier.PROTECTED).returns(propertyListType(rawClassType))
            .addStatement("return $T.asList($L)", ARRAYS, joiner.toString()).build();
}

From source file:org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.consent.ConsentMgtPostAuthnHandler.java

private String buildConsentClaimString(List<ClaimMetaData> consentClaimsData) {

    StringJoiner joiner = new StringJoiner(CLAIM_SEPARATOR);
    for (ClaimMetaData claimMetaData : consentClaimsData) {
        joiner.add(claimMetaData.getId() + "_" + claimMetaData.getDisplayName());
    }// w w w .j  av  a2 s .c om
    return joiner.toString();
}

From source file:info.archinnov.achilles.internals.codegen.meta.EntityMetaCodeGen.java

private MethodSpec buildNormalColumns(List<FieldMetaSignature> parsingResults, TypeName rawClassType) {
    StringJoiner joiner = new StringJoiner(",");
    parsingResults.stream().filter(x -> x.context.columnType == ColumnType.NORMAL)
            .map(x -> Tuple2.of(x.context.cqlColumn, x.context.fieldName)).sorted(BY_CQL_NAME_COLUMN_SORTER)
            .map(x -> x._2()).forEach(x -> joiner.add(x));

    return MethodSpec.methodBuilder("getNormalColumns").addAnnotation(Override.class)
            .addModifiers(Modifier.PROTECTED).returns(propertyListType(rawClassType))
            .addStatement("return $T.asList($L)", ARRAYS, joiner.toString()).build();
}

From source file:info.archinnov.achilles.internals.codegen.meta.EntityMetaCodeGen.java

private MethodSpec buildClusteringColumns(List<FieldMetaSignature> parsingResults, TypeName rawClassType) {
    StringJoiner joiner = new StringJoiner(",");
    parsingResults.stream().filter(x -> x.context.columnType == CLUSTERING)
            .map(x -> Tuple2.of(x.context.fieldName, (ClusteringColumnInfo) x.context.columnInfo))
            .sorted(CLUSTERING_COLUMN_SORTER).map(x -> x._1()).forEach(x -> joiner.add(x));

    return MethodSpec.methodBuilder("getClusteringColumns").addAnnotation(Override.class)
            .addModifiers(Modifier.PROTECTED).returns(propertyListType(rawClassType))
            .addStatement("return $T.asList($L)", ARRAYS, joiner.toString()).build();
}

From source file:info.archinnov.achilles.internals.codegen.meta.EntityMetaCodeGen.java

private MethodSpec buildPartitionKeys(List<FieldMetaSignature> parsingResults, TypeName rawClassType) {
    StringJoiner joiner = new StringJoiner(",");
    parsingResults.stream().filter(x -> x.context.columnType == ColumnType.PARTITION)
            .map(x -> Tuple2.of(x.context.fieldName, (PartitionKeyInfo) x.context.columnInfo))
            .sorted(PARTITION_KEY_SORTER).map(x -> x._1()).forEach(x -> joiner.add(x));

    return MethodSpec.methodBuilder("getPartitionKeys").addAnnotation(Override.class)
            .addModifiers(Modifier.PROTECTED).returns(propertyListType(rawClassType))
            .addStatement("return $T.asList($L)", ARRAYS, joiner.toString()).build();
}

From source file:com.sri.ai.praise.model.imports.church.ChurchToModelVisitor.java

protected Expression defineInHOGM(Expression name, List<Expression> params, Expression body) {
    Expression result = null;//from  ww w  .  j  a  v  a  2 s . c  o m

    // Track the known random variable names
    knownRandomVariableNames.add(name);

    // Determine the correct argument names for any of the
    StringBuilder rArgs = new StringBuilder();
    final Map<Expression, Expression> paramVarNames = new HashMap<Expression, Expression>();
    boolean firstArg = true;
    int cnt = 0;
    Expression randomVariable = name;
    List<Expression> rvArgs = new ArrayList<Expression>();
    for (Expression arg : params) {
        if (firstArg) {
            firstArg = false;
            rArgs.append(" ");
        } else {
            rArgs.append(" x ");
        }
        // Ensure name is upper cased
        Expression logicalVariableArg = newLogicalVariable(arg.toString());
        rvArgs.add(logicalVariableArg);
        params.set(cnt, logicalVariableArg);
        paramVarNames.put(arg, params.get(cnt));
        // TODO - anything better?         
        rArgs.append(CHURCH_VALUES_SORT);
        cnt++;
    }
    randoms.add("random " + name + ":" + rArgs + (rArgs.length() > 0 ? " -> " : " ") + "Boolean");
    StringJoiner knownRandomVariablesHLM = new StringJoiner(";\n", "", ";");
    randoms.forEach(r -> knownRandomVariablesHLM.add(r));
    RewritingProcess processForRV = LBPFactory.newLBPProcessWithHighLevelModel(
            "sort " + CHURCH_VALUES_SORT + ";\n\n" + knownRandomVariablesHLM.toString());
    if (rvArgs.size() > 0) {
        randomVariable = Expressions.apply(randomVariable, rvArgs);
        processForRV = LPIUtil
                .extendContextualSymbolsWithFreeVariablesInferringDomainsFromUsageInRandomVariables(
                        randomVariable, processForRV);
    }

    final List<List<Boolean>> flipValues = new ArrayList<List<Boolean>>();
    final List<Boolean> trueFalseValues = new ArrayList<Boolean>();
    final Map<Expression, Integer> flipMarkerToId = new LinkedHashMap<Expression, Integer>();
    final Map<Expression, Integer> flipMarkerToFlipValuesIdx = new LinkedHashMap<Expression, Integer>();
    // Flips <- array of flip applications in body
    trueFalseValues.add(Boolean.FALSE);
    trueFalseValues.add(Boolean.TRUE);

    for (Integer flipId : flipIdToValue.keySet()) {
        Expression flipMarker = newSymbol(FLIP_ID_PREFIX + flipId);
        if (!flipMarkerToId.containsKey(flipMarker) && Expressions.isSubExpressionOf(flipMarker, body)) {
            flipMarkerToId.put(flipMarker, flipId);
            flipMarkerToFlipValuesIdx.put(flipMarker, flipMarkerToFlipValuesIdx.size());
            flipValues.add(trueFalseValues);
        }
    }

    if (flipValues.size() == 0) {
        Expression potentialRule = createPotentialRule(randomVariable,
                deterministicChurch2HOGM(body, paramVarNames, processForRV), Expressions.ONE, Expressions.ZERO);
        result = rNormalize.rewrite(potentialRule, processForRV);
    } else {
        // H <- empty list
        List<Expression> h = new ArrayList<Expression>();
        // for all assignments of FlipsValues to Flips do
        CartesianProductEnumeration<Boolean> cpe = new CartesianProductEnumeration<Boolean>(flipValues);
        while (cpe.hasMoreElements()) {
            final List<Boolean> values = cpe.nextElement();

            // caseC <- subsitute FlipsValues for Flips in body
            Expression caseC = body
                    .replaceAllOccurrences(new AbstractReplacementFunctionWithContextuallyUpdatedProcess() {
                        @Override
                        public Expression apply(Expression expression, RewritingProcess process) {
                            Expression result = expression;
                            if (Expressions.isSymbol(expression)) {
                                Integer idx = flipMarkerToFlipValuesIdx.get(expression);
                                if (idx != null) {
                                    result = values.get(idx) ? Expressions.TRUE : Expressions.FALSE;
                                }
                            }
                            return result;
                        }
                    }, LBPFactory.newLBPProcess());
            // caseH <- deterministicChurch2HOGM(caseC)
            Expression caseH = deterministicChurch2HOGM(caseC, paramVarNames, processForRV);

            // Calculate q
            Rational q = Rational.ONE;
            for (Map.Entry<Expression, Integer> flipMarkerToIdEntry : flipMarkerToId.entrySet()) {
                Rational pi = flipIdToValue.get(flipMarkerToIdEntry.getValue());
                if (!values.get(flipMarkerToFlipValuesIdx.get(flipMarkerToIdEntry.getKey()))) {
                    pi = Rational.ONE.subtract(pi);
                }

                q = q.multiply(pi);
            }

            h.add(createPotentialRule(randomVariable, caseH, Expressions.makeSymbol(q), Expressions.ZERO));
        }
        Expression plusH = Plus.make(h);
        List<Expression> constants = new ArrayList<>(FormulaUtil.getConstants(plusH, processForRV));
        // Ensure we exclude known random variable names
        constants.removeAll(knownRandomVariableNames);
        // And also ensure we remove these known constants as well.
        constants.remove(Expressions.TRUE);
        constants.remove(Expressions.FALSE);
        if (constants.size() > 0) {
            knownConstants.addAll(constants);
            Model model = Model.getRewritingProcessesModel(processForRV);
            Set<Expression> sortDeclarationExpressions = new LinkedHashSet<>();
            sortDeclarationExpressions.add(new SortDeclaration(Expressions.makeSymbol(CHURCH_VALUES_SORT),
                    SortDeclaration.UNKNOWN_SIZE, ExtensionalSet.makeUniSet(constants)).getSortDeclaration());
            Set<Expression> randomVariableDeclarationExpressions = new LinkedHashSet<>();
            model.getRandomVariableDeclarations()
                    .forEach(randomVariableDeclaration -> randomVariableDeclarationExpressions
                            .add(randomVariableDeclaration.getRandomVariableDeclaration()));
            processForRV = Model.setKnownSortsAndRandomVariables(sortDeclarationExpressions,
                    randomVariableDeclarationExpressions, processForRV);
        }

        result = SimplifyWithRelationsAtBottom.simplify(plusH, name, processForRV);
    }

    rules.add(result.toString());

    return result;
}

From source file:info.archinnov.achilles.internals.codegen.meta.EntityMetaCodeGen.java

private MethodSpec buildComputedColumns(List<FieldMetaSignature> parsingResults, TypeName rawClassType) {
    StringJoiner joiner = new StringJoiner(",");
    parsingResults.stream().filter(x -> x.context.columnType == ColumnType.COMPUTED)
            .map(x -> Tuple2.of(((ComputedColumnInfo) x.context.columnInfo).alias, x.context.fieldName))
            .sorted(BY_CQL_NAME_COLUMN_SORTER).map(x -> x._2()).forEach(x -> joiner.add(x));

    return MethodSpec.methodBuilder("getComputedColumns").addAnnotation(Override.class)
            .addModifiers(Modifier.PROTECTED).returns(propertyListType(rawClassType))
            .addStatement("return $T.asList($L)", ARRAYS, joiner.toString()).build();
}

From source file:com.offbynull.voip.kademlia.GraphHelper.java

@SuppressWarnings("unchecked")
private void applyRoutingTreeChanges(Context ctx, RouteTreeChangeSet changeSet) {
    Set<BitString> updatedPrefixes = new HashSet<>();

    // Remove nodes from graph and set
    for (Activity removedNode : changeSet.getKBucketChangeSet().getBucketChangeSet().viewRemoved()) {
        Id id = removedNode.getNode().getId();
        BitString prefix = findPrefixInRouteTreeIds(id);
        routeTreePrefixToIds.get(prefix).remove(id);
        updatedPrefixes.add(prefix);//from  w  w w. j av  a2s.  c  o  m
    }

    // Add nodes to graph and set
    for (Activity addedNode : changeSet.getKBucketChangeSet().getBucketChangeSet().viewAdded()) {
        Id id = addedNode.getNode().getId();
        BitString prefix = findPrefixInRouteTreeIds(id);
        routeTreePrefixToIds.get(prefix).add(id);
        updatedPrefixes.add(prefix);
    }

    for (BitString updatedPrefix : updatedPrefixes) {
        // Concatenate to string and set as label
        StringJoiner joiner = new StringJoiner("\n");

        // Find parent
        int prefixBitLength = updatedPrefix.getBitLength();
        BitString parentPrefix = getParentPrefix(routeTreePrefixToIds.keySet(), updatedPrefix);

        // Calculate number of bits after parent prefix (the bits to display)
        int newBitsOffset = parentPrefix.getBitLength();
        int newBitsLength = prefixBitLength - parentPrefix.getBitLength();
        BitString prefixDisplayBits = updatedPrefix.getBits(newBitsOffset, newBitsLength);

        // Change label to contain all nodes in the bucket
        joiner.add(prefixDisplayBits.toString());
        routeTreePrefixToIds.get(updatedPrefix).forEach(id -> joiner.add(id.getBitString().toString()));
        ctx.addOutgoingMessage(graphAddress, new LabelNode(updatedPrefix.toString(), joiner.toString()));
    }
}

From source file:com.google.gerrit.server.mail.send.OutgoingEmail.java

/**
 * Format and enqueue the message for delivery.
 *
 * @throws EmailException//from   w  w  w. j av a 2s  . com
 */
public void send() throws EmailException {
    if (NotifyHandling.NONE.equals(notify) && accountsToNotify.isEmpty()) {
        return;
    }

    if (!args.emailSender.isEnabled()) {
        // Server has explicitly disabled email sending.
        //
        return;
    }

    init();
    if (useHtml()) {
        appendHtml(soyHtmlTemplate("HeaderHtml"));
    }
    format();
    appendText(textTemplate("Footer"));
    if (useHtml()) {
        appendHtml(soyHtmlTemplate("FooterHtml"));
    }

    Set<Address> smtpRcptToPlaintextOnly = new HashSet<>();
    if (shouldSendMessage()) {
        if (fromId != null) {
            final Account fromUser = args.accountCache.get(fromId).getAccount();
            GeneralPreferencesInfo senderPrefs = fromUser.getGeneralPreferencesInfo();

            if (senderPrefs != null && senderPrefs.getEmailStrategy() == CC_ON_OWN_COMMENTS) {
                // If we are impersonating a user, make sure they receive a CC of
                // this message so they can always review and audit what we sent
                // on their behalf to others.
                //
                add(RecipientType.CC, fromId);
            } else if (!accountsToNotify.containsValue(fromId) && rcptTo.remove(fromId)) {
                // If they don't want a copy, but we queued one up anyway,
                // drop them from the recipient lists.
                //
                removeUser(fromUser);
            }
        }
        // Check the preferences of all recipients. If any user has disabled
        // his email notifications then drop him from recipients' list.
        // In addition, check if users only want to receive plaintext email.
        for (Account.Id id : rcptTo) {
            Account thisUser = args.accountCache.get(id).getAccount();
            GeneralPreferencesInfo prefs = thisUser.getGeneralPreferencesInfo();
            if (prefs == null || prefs.getEmailStrategy() == DISABLED) {
                removeUser(thisUser);
            } else if (useHtml() && prefs.getEmailFormat() == EmailFormat.PLAINTEXT) {
                removeUser(thisUser);
                smtpRcptToPlaintextOnly.add(new Address(thisUser.getFullName(), thisUser.getPreferredEmail()));
            }
            if (smtpRcptTo.isEmpty() && smtpRcptToPlaintextOnly.isEmpty()) {
                return;
            }
        }

        // Set Reply-To only if it hasn't been set by a child class
        // Reply-To will already be populated for the message types where Gerrit supports
        // inbound email replies.
        if (!headers.containsKey("Reply-To")) {
            StringJoiner j = new StringJoiner(", ");
            if (fromId != null) {
                Address address = toAddress(fromId);
                if (address != null) {
                    j.add(address.getEmail());
                }
            }
            smtpRcptTo.stream().forEach(a -> j.add(a.getEmail()));
            smtpRcptToPlaintextOnly.stream().forEach(a -> j.add(a.getEmail()));
            setHeader("Reply-To", j.toString());
        }

        String textPart = textBody.toString();
        OutgoingEmailValidationListener.Args va = new OutgoingEmailValidationListener.Args();
        va.messageClass = messageClass;
        va.smtpFromAddress = smtpFromAddress;
        va.smtpRcptTo = smtpRcptTo;
        va.headers = headers;
        va.body = textPart;

        if (useHtml()) {
            va.htmlBody = htmlBody.toString();
        } else {
            va.htmlBody = null;
        }

        for (OutgoingEmailValidationListener validator : args.outgoingEmailValidationListeners) {
            try {
                validator.validateOutgoingEmail(va);
            } catch (ValidationException e) {
                return;
            }
        }

        if (!smtpRcptTo.isEmpty()) {
            // Send multipart message
            args.emailSender.send(va.smtpFromAddress, va.smtpRcptTo, va.headers, va.body, va.htmlBody);
        }

        if (!smtpRcptToPlaintextOnly.isEmpty()) {
            // Send plaintext message
            Map<String, EmailHeader> shallowCopy = new HashMap<>();
            shallowCopy.putAll(headers);
            // Remove To and Cc
            shallowCopy.remove(HDR_TO);
            shallowCopy.remove(HDR_CC);
            for (Address a : smtpRcptToPlaintextOnly) {
                // Add new To
                EmailHeader.AddressList to = new EmailHeader.AddressList();
                to.add(a);
                shallowCopy.put(HDR_TO, to);
            }
            args.emailSender.send(va.smtpFromAddress, smtpRcptToPlaintextOnly, shallowCopy, va.body);
        }
    }
}

From source file:info.archinnov.achilles.internals.codegen.meta.EntityMetaCodeGen.java

private MethodSpec buildStaticColumns(List<FieldMetaSignature> parsingResults, TypeName rawClassType) {
    StringJoiner joiner = new StringJoiner(",");
    parsingResults.stream()//from ww w  .  j a  va2s . c  o  m
            .filter(x -> (x.context.columnType == ColumnType.STATIC
                    || x.context.columnType == ColumnType.STATIC_COUNTER))
            .map(x -> Tuple2.of(x.context.cqlColumn, x.context.fieldName)).sorted(BY_CQL_NAME_COLUMN_SORTER)
            .map(x -> x._2()).forEach(x -> joiner.add(x));

    return MethodSpec.methodBuilder("getStaticColumns").addAnnotation(Override.class)
            .addModifiers(Modifier.PROTECTED).returns(propertyListType(rawClassType))
            .addStatement("return $T.asList($L)", ARRAYS, joiner.toString()).build();
}