Example usage for org.apache.commons.lang3.text StrBuilder build

List of usage examples for org.apache.commons.lang3.text StrBuilder build

Introduction

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

Prototype

@Override
public String build() 

Source Link

Document

Implement the Builder interface.

Usage

From source file:gov.usgs.cida.ConsulRegistratorMojoUnitTest.java

@org.junit.Test
public void testBuildScriptContextPathsOnly() {
    String[] contextPaths = { "/wow", "/big", "/time" };
    StrBuilder sb = new StrBuilder();
    sb.append(ConsulRegistratorMojo.URL_COMMAND);
    for (String contextPath : contextPaths) {
        sb.append(NON_CONTEXT_PATH).append(contextPath).append(' ');
    }//  ww  w .ja v  a2  s .c o m
    sb.trim();

    String expResult = sb.build();

    String result = buildScript(null, contextPaths);
    assertEquals(expResult, result);
    result = buildScript("", contextPaths);
    assertEquals(expResult, result);
}

From source file:com.opentangerine.clean.Replace.java

/**
 * Apply replace transformation on selected line only if matching
 * function returned true.//w w w .ja v a  2  s . c o m
 *
 * @param matching Closure that returns true if line has been matched.
 * @param transformation Closure with line transformation.
 * @return Replace object.
 */
public Replace replace(final Function<String, Boolean> matching,
        final Function<String, String> transformation) {
    final StrBuilder out = new StrBuilder();
    try (Scanner scanner = new Scanner(this.text)) {
        while (scanner.hasNextLine()) {
            final String line = scanner.nextLine();
            if (matching.apply(line)) {
                out.append(transformation.apply(line));
            } else {
                out.append(line);
            }
            out.appendNewLine();
        }
    }
    return new Replace(out.build());
}

From source file:de.vandermeer.skb.interfaces.application.IsApplication.java

/**
 * Prints a help screen for the application, to be used by an executing component.
 *//*  ww w . j a v  a2  s.  c  om*/
default void appHelpScreen() {
    STGroupFile stg = new STGroupFile("de/vandermeer/skb/interfaces/application/help.stg");
    ST st = stg.getInstanceOf("usage");
    st.add("appName", this.getAppName());
    st.add("appDisplayName", this.getAppDisplayName());
    st.add("appVersion", this.getAppVersion());
    st.add("appDescription", Text_To_FormattedText.left(this.getAppDescription(), this.getConsoleWidth()));
    st.add("required", CliOptionList.getRequired(getCLiALlOptions()));
    for (StrBuilder sb : this.getCliParser().usage(this.getConsoleWidth())) {
        st.add("cliOptions", sb);
    }

    if (this.getEnvironmentOptions().size() > 0) {
        TreeMap<String, Apo_TypedE<?>> map = EnvironmentOptionsList.sortedMap(this.getEnvironmentOptions());
        Map<String, String> envMap = new LinkedHashMap<>();
        int length = 0;
        for (Apo_TypedE<?> te : map.values()) {
            if (te.getEnvironmentKey().length() > length) {
                length = te.getEnvironmentKey().length();
            }
            envMap.put(te.getEnvironmentKey(), te.getDescription());
        }
        length += 2;

        for (Entry<String, String> entry : envMap.entrySet()) {
            StrBuilder argLine = new StrBuilder();
            argLine.append(entry.getKey()).appendPadding(length - argLine.length(), ' ').append("  - ");
            StrBuilder padLine = new StrBuilder();
            padLine.appendPadding(length + 4, ' ');

            Collection<StrBuilder> text = Text_To_FormattedText.left(entry.getValue(),
                    this.getConsoleWidth() - length);
            int i = 0;
            for (StrBuilder b : text) {
                if (i == 0) {
                    st.add("envOptions", argLine + b.build());
                } else {
                    st.add("envOptions", padLine + b.build());
                }
                i++;
            }
        }
    }

    if (this.getPropertyOptions().size() > 0) {
        TreeMap<String, Apo_TypedP<?>> map = PropertyOptionsList.sortedMap(this.getPropertyOptions());
        Map<String, String> envMap = new LinkedHashMap<>();
        int length = 0;
        for (Apo_TypedP<?> te : map.values()) {
            if (te.getPropertyKey().length() > length) {
                length = te.getPropertyKey().length();
            }
            envMap.put(te.getPropertyKey(), te.getDescription());
        }
        length += 2;

        for (Entry<String, String> entry : envMap.entrySet()) {
            StrBuilder argLine = new StrBuilder();
            argLine.append(entry.getKey()).appendPadding(length - argLine.length(), ' ').append("  - ");
            StrBuilder padLine = new StrBuilder();
            padLine.appendPadding(length + 4, ' ');

            Collection<StrBuilder> text = Text_To_FormattedText.left(entry.getValue(),
                    this.getConsoleWidth() - length);
            int i = 0;
            for (StrBuilder b : text) {
                if (i == 0) {
                    st.add("propOptions", argLine + b.build());
                } else {
                    st.add("propOptions", padLine + b.build());
                }
                i++;
            }
        }
    }
    System.out.println(st.render());
}

From source file:com.alta189.userscript.maven.plugin.UserscriptBuilder.java

private String assemble() throws UserscriptBuilderException {
    StrBuilder builder = new StrBuilder();

    builder.appendln("// ==UserScript==");
    appendValid(builder, "// @name          ", userscript.getMetadata().getName());
    appendValid(builder, "// @namespace     ", userscript.getMetadata().getNamespace());
    appendValid(builder, "// @description   ", userscript.getMetadata().getDescription());
    appendValid(builder, "// @version       ", userscript.getMetadata().getVersion());
    appendValid(builder, "// @author        ", userscript.getMetadata().getAuthor());
    appendValid(builder, "// @include       ", userscript.getMetadata().getIncludes());
    appendValid(builder, "// @exclude       ", userscript.getMetadata().getExcludes());
    appendValid(builder, "// @match         ", userscript.getMetadata().getMatches());
    appendValid(builder, "// @require       ", userscript.getMetadata().getRequires());
    appendValid(builder, "// @resource      ", userscript.getMetadata().getResources());
    appendValid(builder, "// @grant         ", userscript.getMetadata().getGrants());
    appendValid(builder, "// @noframes      ", userscript.getMetadata().isNoFrames());
    appendValid(builder, "// @run-at        ", userscript.getMetadata().getRunAt());
    appendValid(builder, "// @icon          ", userscript.getMetadata().getIcon());
    appendValid(builder, "// @downloadURL   ", userscript.getMetadata().getDownloadURL());
    appendValid(builder, "// @updateURL     ", userscript.getMetadata().getUpdateURL());
    builder.appendln("// ==/UserScript==");
    builder.appendNewLine();//from w w w  .j av a 2s .c om

    File sourceFile = new File(mojo.getSourceDirectory(), userscript.getSource());
    String source;
    try {
        source = FileUtils.readFileToString(sourceFile);
    } catch (IOException e) {
        throw new UserscriptBuilderException("Could not read sourceFile: " + sourceFile.getPath(), e);
    }

    builder.append(filterSource(source));

    return builder.build();
}