Example usage for java.lang StringBuilder insert

List of usage examples for java.lang StringBuilder insert

Introduction

In this page you can find the example usage for java.lang StringBuilder insert.

Prototype

@Override
public StringBuilder insert(int offset, double d) 

Source Link

Usage

From source file:net.ymate.framework.core.taglib.bootstrap.AlertTag.java

@Override
protected StringBuilder __doTagContent(StringBuilder tagContent, StringBuilder bodyContent) {
    if (dismissable) {
        bodyContent.insert(0,
                "<button type=\"button\" class=\"close\" data-dismiss=\"alert\"><span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>");
    }/*from w  w  w  .j a  v a 2s.co  m*/
    //
    return super.__doTagContent(tagContent, bodyContent);
}

From source file:com.kactech.otj.Utils.java

public static String base62Encode(BigInteger number) {
    if (number.compareTo(BigInteger.ZERO) == -1) { // number < 0
        throw new IllegalArgumentException("number must not be negative");
    }//  ww  w  .  j  av a  2 s.co  m
    StringBuilder result = new StringBuilder();
    while (number.compareTo(BigInteger.ZERO) == 1) { // number > 0
        BigInteger[] divmod = number.divideAndRemainder(B62_BASE);
        number = divmod[0];
        int digit = divmod[1].intValue();
        result.insert(0, B62_DIGITS.charAt(digit));
    }
    return (result.length() == 0) ? B62_DIGITS.substring(0, 1) : result.toString();
}

From source file:bammerbom.ultimatecore.bukkit.configuration.ConfigSection.java

/**
 * Creates a relative path to the given {@link ConfigSection} from the given
 * relative section./*from w w w.j a v a2  s. co m*/
 * <p/>
 * You may use this method for any given {@link ConfigSection}, not only
 * {@link ConfigSection}.
 *
 * @param section Section to create a path for.
 * @param key Name of the specified section.
 * @param relativeTo Section to create the path relative to.
 * @return Full path of the section from its root.
 */
protected static String createPath(ConfigSection section, String key, ConfigSection relativeTo) {
    Validate.notNull(section, "Cannot create path without a section");
    MemoryConfiguration root = section.getRoot();
    if (root == null) {
        throw new IllegalStateException("Cannot create path without a root");
    }
    char separator = root.options().pathSeparator();

    StringBuilder builder = new StringBuilder();
    if (section != null) {
        for (ConfigSection parent = section; (parent != null)
                && (parent != relativeTo); parent = parent.getParent()) {
            if (builder.length() > 0) {
                builder.insert(0, separator);
            }

            builder.insert(0, parent.getName());
        }
    }

    if ((key != null) && (key.length() > 0)) {
        if (builder.length() > 0) {
            builder.append(separator);
        }

        builder.append(key);
    }

    return builder.toString();
}

From source file:net.triptech.metahive.model.Definition.java

/**
 * Builds the where statement.//from w  w  w.  j a v a  2 s  .  c o m
 *
 * @param filter the filter
 * @return the string
 */
private static String buildWhere(final DefinitionFilter filter) {
    StringBuilder where = new StringBuilder();

    if (StringUtils.isNotBlank(filter.getName())) {
        where.append("LOWER(d.name) LIKE LOWER(:name)");
    }

    if (StringUtils.isNotBlank(filter.getCategory())) {
        if (where.length() > 0) {
            where.append(" AND ");
        }
        where.append("LOWER(c.name) LIKE LOWER(:category)");
    }

    if (where.length() > 0) {
        where.insert(0, " WHERE ");
    }
    return where.toString();
}

From source file:de.mendelson.comm.as2.message.AS2MessageCreation.java

/**Escapes the AS2-TO and AS2-FROM headers in sending direction, related to
 * RFC 4130 section 6.2//  w w w.j  a  v  a2 s  .  c o  m
 * @param identification as2-from or as2-to value to escape
 * @return escaped value
 */
public static String escapeFromToHeader(String identification) {
    boolean containsBlank = false;
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < identification.length(); i++) {
        char singleChar = identification.charAt(i);
        if (singleChar == ' ') {
            containsBlank = true;
        } else if (singleChar == '"') {
            builder.append("\\");
        } else if (singleChar == '\\') {
            builder.append("\\");
        }
        builder.append(singleChar);
    }
    //quote the value if it contains blanks
    if (containsBlank) {
        builder.insert(0, "\"");
        builder.append("\"");
    }
    return (builder.toString());
}

From source file:com.linuxbox.util.ThreadAwareLogger.java

Object process(Object o) {
    if (o instanceof String) {
        StringBuilder s = new StringBuilder((String) o);
        s.insert(0, "] ");
        s.insert(0, Thread.currentThread().getId());
        s.insert(0, "[thread ");
        return s.toString();
    } else {//from  ww  w  . j  a v a  2  s  .  c  om
        return o;
    }
}

From source file:net.ymate.framework.core.taglib.bootstrap.TableTag.java

@Override
protected StringBuilder __doTagContent(StringBuilder tagContent, StringBuilder bodyContent) {
    if (responsive) {
        tagContent.insert(0, "<div class=\"table-responsive\">");
        return super.__doTagContent(tagContent, bodyContent).append("</div>");
    }//from w w w . j  a  v a  2  s .c  om
    return super.__doTagContent(tagContent, bodyContent);
}

From source file:org.ngrinder.script.handler.JythonScriptHandler.java

@Override
public String checkSyntaxErrors(String path, String script) {
    try {/*from w  ww .ja  v  a  2  s  . c  o  m*/
        org.python.core.ParserFacade.parse(script, CompileMode.exec, path,
                new CompilerFlags(CompilerFlags.PyCF_DONT_IMPLY_DEDENT | CompilerFlags.PyCF_ONLY_AST));

    } catch (PyException e) {
        try {
            PyTuple pyTuple = (PyTuple) ((PyTuple) e.value).get(1);
            Integer line = (Integer) pyTuple.get(1);
            Integer column = (Integer) pyTuple.get(2);
            String lineString = (String) pyTuple.get(3);
            StringBuilder buf = new StringBuilder(lineString);
            if (lineString.length() >= column) {
                buf.insert(column, "^");
            }
            return "Error occurred\n" + " - Invalid Syntax Error on line " + line + " / column " + column + "\n"
                    + buf.toString();
        } catch (Exception ex) {
            return "Error occurred while evaluation python syntax";
        }
    }
    return null;
}

From source file:uk.ac.kcl.mutators.StringMutatorService.java

public Mutant generateMutantDocument(String[] stringToMutate, int severity) {

    LoremIpsum loremIpsum = new LoremIpsum();
    int loremStart = 0;
    int loremEnd = random.nextInt(loremLength);

    StringBuilder sb = new StringBuilder();
    sb.insert(0, loremIpsum.getWords(random.nextInt(loremLength)));
    sb.append(" ");
    Mutant parentMutant = new Mutant();
    for (int i = 0; i < stringToMutate.length; i++) {
        Mutant childMutant = mutate(stringToMutate[i], severity);
        parentMutant.getInputTokens().addAll(childMutant.getInputTokens());
        parentMutant.getOutputTokens().addAll(childMutant.getOutputTokens());
        sb.append(childMutant.getFinalText()).append(" ").append(loremIpsum.getWords(loremEnd, loremStart))
                .append(" ");
        loremStart = loremEnd + 1;//w ww  . j a v a  2s .  c om
        loremEnd = loremStart + random.nextInt(loremLength);
    }
    parentMutant.setFinalText(sb.toString());
    return parentMutant;
}

From source file:FileCompressor.java

public String compress(String context) {

    context = context.toLowerCase();/* ww  w .  j  a v a2s . c  om*/
    preprocess(context);
    StringBuilder mapLine = new StringBuilder();
    for (Entry<String, Character> e : map.entrySet()) {
        String key = e.getKey();
        String value = e.getValue().toString();
        context = context.replace(key, value);
        mapLine.append(key);
        mapLine.append(value);
    }
    mapLine.append(System.getProperty("line.separator"));

    StringBuilder out = new StringBuilder(context);
    out.insert(0, mapLine.toString());

    map = null;

    return out.toString();
}