Example usage for org.apache.commons.lang.text StrBuilder StrBuilder

List of usage examples for org.apache.commons.lang.text StrBuilder StrBuilder

Introduction

In this page you can find the example usage for org.apache.commons.lang.text StrBuilder StrBuilder.

Prototype

public StrBuilder() 

Source Link

Document

Constructor that creates an empty builder initial capacity 32 characters.

Usage

From source file:com.ryft.spark.connector.examples.SimplePairRDDExampleJ.java

public static void main(String[] args) {
    final SparkConf sparkConf = new SparkConf().setAppName("SimplePairRDDExampleJ").setMaster("local[2]");

    final SparkContext sc = new SparkContext(sparkConf);
    final SparkContextJavaFunctions javaFunctions = RyftJavaUtil.javaFunctions(sc);
    final byte fuzziness = 0;
    final int surrounding = 10;
    final List queries = toScalaList(RyftQueryUtil.toSimpleQueries("Jones", "Thomas"));

    final RyftPairJavaRDD rdd = javaFunctions.ryftPairJavaRDD(queries,
            RyftQueryOptions.apply("passengers.txt", surrounding, fuzziness), RyftJavaUtil.ryftQueryToEmptyList,
            RyftJavaUtil.stringToEmptySet);

    final Map<String, Long> countByKey = rdd.countByKey();
    final StrBuilder sb = new StrBuilder();
    countByKey.forEach((key, value) -> sb.append(key + " -> " + value + "\n"));
    logger.info("RDD count by key: \n{}", sb.toString());
}

From source file:me.taylorkelly.mywarp.util.CommandUtils.java

/**
 * Joins all warps in the given collection in one string, separated by {@code ", "}.
 *
 * @param warps a collection of warps/* w  w w  . j a v  a 2  s  .c  o  m*/
 * @return a string with all warp-names or {@code -} if the collection was empty
 */
public static String joinWarps(Collection<Warp> warps) {
    if (warps.isEmpty()) {
        return "-";
    }

    StrBuilder ret = new StrBuilder();
    for (Warp warp : warps) {
        ret.appendSeparator(", ");
        ret.append(warp.getName());
    }
    return ret.toString();
}

From source file:com.evolveum.liferay.usercreatehook.password.StringPolicyUtils.java

/**
 * Prepare usable list of strings for generator
 *//*from w  w w .  ja v  a 2 s  . c o m*/

public static String collectCharacterClass(CharacterClassType cc, QName ref) {
    StrBuilder l = new StrBuilder();
    if (null == cc) {
        throw new IllegalArgumentException("Character class cannot be null");
    }

    if (null != cc.getValue() && (null == ref || ref.equals(cc.getName()))) {
        l.append(cc.getValue());
    } else if (null != cc.getCharacterClass() && !cc.getCharacterClass().isEmpty()) {
        // Process all sub lists
        for (CharacterClassType subClass : cc.getCharacterClass()) {
            // If we found requested name or no name defined
            if (null == ref || ref.equals(cc.getName())) {
                l.append(collectCharacterClass(subClass, null));
            } else {
                l.append(collectCharacterClass(subClass, ref));
            }
        }
    }
    // Remove duplicity in return;
    HashSet<String> h = new HashSet<String>();
    for (String s : l.toString().split("")) {
        h.add(s);
    }
    return new StrBuilder().appendAll(h).toString();
}

From source file:me.taylorkelly.mywarp.util.CommandUtils.java

/**
 * Joins all worlds in the given collection in one string, separated by {@code ", "}.
 *
 * @param worlds a collection of worlds//from   w  ww  .  ja v  a  2  s  .  c o  m
 * @return a string with all world-names or {@code -} if the collection was empty
 */
public static String joinWorlds(Collection<LocalWorld> worlds) {
    if (worlds.isEmpty()) {
        return "-";
    }

    StrBuilder ret = new StrBuilder();
    for (LocalWorld world : worlds) {
        ret.appendSeparator(", ");
        ret.append(world.getName());
    }
    return ret.toString();
}

From source file:bboss.org.apache.velocity.runtime.parser.node.NodeUtils.java

/**
 * Collect all the <SPECIAL_TOKEN>s that
 * are carried along with a token. Special
 * tokens do not participate in parsing but
 * can still trigger certain lexical actions.
 * In some cases you may want to retrieve these
 * special tokens, this is simply a way to
 * extract them.//from  w  w  w.j a va  2  s.co m
 * @param t the Token
 * @return StrBuilder with the special tokens.
 */
public static StrBuilder getSpecialText(Token t) {
    StrBuilder sb = new StrBuilder();

    Token tmp_t = t.specialToken;

    while (tmp_t.specialToken != null) {
        tmp_t = tmp_t.specialToken;
    }

    while (tmp_t != null) {
        String st = tmp_t.image;

        for (int i = 0, is = st.length(); i < is; i++) {
            char c = st.charAt(i);

            if (c == '#' || c == '$') {
                sb.append(c);
            }

            /*
             *  more dreaded MORE hack :)
             *
             *  looking for ("\\")*"$" sequences
             */

            if (c == '\\') {
                boolean ok = true;
                boolean term = false;

                int j = i;
                for (ok = true; ok && j < is; j++) {
                    char cc = st.charAt(j);

                    if (cc == '\\') {
                        /*
                         *  if we see a \, keep going
                         */
                        continue;
                    } else if (cc == '$') {
                        /*
                         *  a $ ends it correctly
                         */
                        term = true;
                        ok = false;
                    } else {
                        /*
                         *  nah...
                         */
                        ok = false;
                    }
                }

                if (term) {
                    String foo = st.substring(i, j);
                    sb.append(foo);
                    i = j;
                }
            }
        }

        tmp_t = tmp_t.next;
    }
    return sb;
}

From source file:io.github.mywarp.mywarp.command.parametric.provider.exception.NoSuchWarpException.java

@Override
public String getLocalizedMessage() {
    StrBuilder builder = new StrBuilder();
    builder.append(msg.getString("exception.no-such-warp", getInput()));

    if (!matches.isEmpty()) {
        builder.appendNewLine();/*from   w  w w.jav  a  2  s.  c om*/
        builder.append(msg.getString("exception.no-such-warp.suggestion", matches.get(1).getName()));
    }
    return builder.toString();
}

From source file:com.evolveum.midpoint.model.common.stringpolicy.StringPolicyUtils.java

/**
 * Prepare usable list of strings for generator
 * /*from ww w  .  ja v a  2  s . c  om*/
 */

public static String collectCharacterClass(CharacterClassType cc, QName ref) {
    StrBuilder l = new StrBuilder();
    if (null == cc) {
        throw new IllegalArgumentException("Character class cannot be null");
    }

    if (null != cc.getValue() && (null == ref || ref.equals(cc.getName()))) {
        l.append(cc.getValue());
    } else if (null != cc.getCharacterClass() && !cc.getCharacterClass().isEmpty()) {
        // Process all sub lists
        for (CharacterClassType subClass : cc.getCharacterClass()) {
            // If we found requested name or no name defined
            if (null == ref || ref.equals(cc.getName())) {
                l.append(collectCharacterClass(subClass, null));
            } else {
                l.append(collectCharacterClass(subClass, ref));
            }
        }
    }
    // Remove duplicity in return;
    HashSet<String> h = new HashSet<>();
    for (String s : l.toString().split("")) {
        h.add(s);
    }
    return new StrBuilder().appendAll(h).toString();
}

From source file:mitm.common.fetchmail.FetchmailConfigBuilder.java

/**
 * Writes the new config to targetConfig. Lines between START_TOKEN and END_TOKEN are replaced with the 
 * new config from FetchmailConfig.//from w  w w .j a  v a 2s. c  om
 */
public static void createConfig(FetchmailConfig config, InputStream sourceConfig, OutputStream targetConfig)
        throws IOException {
    LineNumberReader reader = new LineNumberReader(new InputStreamReader(sourceConfig, "US-ASCII"));

    StrBuilder outputBuilder = new StrBuilder();

    boolean inBlock = false;
    boolean blockInjected = false;

    String line;

    do {
        line = reader.readLine();

        if (line != null) {
            if (inBlock) {
                if (line.startsWith(END_TOKEN)) {
                    inBlock = false;
                    blockInjected = true;

                    injectConfig(config, outputBuilder);

                    outputBuilder.appendln(line);
                }
            } else {
                if (!blockInjected && line.startsWith(START_TOKEN)) {
                    inBlock = true;
                }

                outputBuilder.appendln(line);
            }
        }
    } while (line != null);

    targetConfig.write(MiscStringUtils.toAsciiBytes(outputBuilder.toString()));
}

From source file:com.haulmont.cuba.security.jmx.UserSessions.java

@Override
public String printSessions() {
    StrBuilder sb = new StrBuilder();
    sb.appendWithSeparators(userSessions.getUserSessionInfo(), "\n");
    return sb.toString();
}

From source file:me.taylorkelly.mywarp.bukkit.commands.printer.InfoPrinter.java

/**
 * Gets information text./*from   w  w w  . ja  v  a 2s  .c  om*/
 *
 * @param receiver the Actor who will receive the text
 * @return the text
 */
public String getText(Actor receiver) {
    StrBuilder info = new StrBuilder();
    // heading
    info.append(ChatColor.GOLD);
    info.append(MESSAGES.getString("info.heading",
            ChatColor.getByChar(warp.getType().getColorCharacter()) + warp.getName() + ChatColor.GOLD));
    info.appendNewLine();

    // creator
    info.append(ChatColor.GRAY);

    info.append(MESSAGES.getString("info.created-by"));
    info.append(" ");
    info.append(ChatColor.WHITE);
    Profile creator = warp.getCreator();
    info.append(creator.getName().or(creator.getUniqueId().toString()));
    if (receiver instanceof LocalPlayer && warp.isCreator((LocalPlayer) receiver)) {
        info.append(" ");
        info.append(MESSAGES.getString("info.created-by-you"));
    }
    info.appendNewLine();

    // location
    info.append(ChatColor.GRAY);
    info.append(MESSAGES.getString("info.location"));
    info.append(" ");
    info.append(ChatColor.WHITE);
    info.append(MESSAGES.getString("info.location.position", warp.getPosition().getFloorX(),
            warp.getPosition().getFloorY(), warp.getPosition().getFloorZ(), warp.getWorld().getName()));

    info.appendNewLine();

    // if the warp is modifiable, show information about invitations
    if (warp.isModifiable(receiver)) {

        // invited players
        info.append(ChatColor.GRAY);
        info.append(MESSAGES.getString("info.invited-players"));
        info.append(" ");
        info.append(ChatColor.WHITE);

        Set<Profile> invitedPlayers = warp.getInvitedPlayers();
        if (invitedPlayers.isEmpty()) {
            info.append("-");
        } else {
            List<String> invitedPlayerNames = new ArrayList<String>();
            for (Profile profile : invitedPlayers) {
                invitedPlayerNames.add(profile.getName().or(profile.getUniqueId().toString()));
            }
            Collections.sort(invitedPlayerNames);
            info.appendWithSeparators(invitedPlayerNames, ", ");
        }
        info.appendNewLine();

        // invited groups
        info.append(ChatColor.GRAY);
        info.append(MESSAGES.getString("info.invited-groups"));
        info.append(" ");
        info.append(ChatColor.WHITE);

        List<String> invitedGroups = Ordering.natural().sortedCopy(warp.getInvitedGroups());
        if (invitedGroups.isEmpty()) {
            info.append("-");
        } else {
            info.appendWithSeparators(invitedGroups, ", ");
        }
        info.appendNewLine();
    }

    // creation date
    info.append(ChatColor.GRAY);
    info.append(MESSAGES.getString("info.creation-date", warp.getCreationDate()));
    info.append(" ");
    info.append(ChatColor.WHITE);
    info.append(DateFormat.getDateInstance(DateFormat.DEFAULT, LocaleManager.getLocale())
            .format(warp.getCreationDate()));

    info.appendNewLine();

    // visits
    info.append(ChatColor.GRAY);
    info.append(MESSAGES.getString("info.visits"));
    info.append(" ");
    info.append(ChatColor.WHITE);
    info.append(MESSAGES.getString("info.visits.per-day", warp.getVisits(), warp.getVisitsPerDay()));
    return info.toString();
}