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:ClassUtil.java

/**
 * Report the full name of the object class, without the package information
 *
 * @param obj the object to name//w  ww  . j  av  a 2s  .co  m
 * @return the concatenation of (enclosing) simple names
 */
public static String nameOf(Object obj) {
    StringBuilder sb = new StringBuilder();

    for (Class cl = obj.getClass(); cl != null; cl = cl.getEnclosingClass()) {
        if (sb.length() > 0) {
            sb.insert(0, "-");
        }

        sb.insert(0, cl.getSimpleName());
    }

    return sb.toString();
}

From source file:com.snaplogic.snaps.lunex.RequestProcessor.java

private static String formatResponse(StringBuilder response) {
    if (!response.toString().endsWith(CLOSEBRACKET) && !response.toString().startsWith(OPENBRACKET)) {
        response.insert(0, OPENBRACKET).append(CLOSEBRACKET);
    }//from   ww  w .ja v  a2  s  . c  o  m
    return response.toString();
}

From source file:com.fjn.helper.common.io.file.common.FileUpAndDownloadUtil.java

private static String buildFileName(String filename) {
    int index = filename.lastIndexOf(".");
    if (index == -1) {
        index = filename.length();//  ww  w  .  ja v  a2  s  .c  om
    }
    StringBuilder builder = new StringBuilder(filename);
    return builder.insert(index, getTime()).toString();
}

From source file:GitHubApiTestCase.java

@NotNull
protected static String rewind(@NotNull final String s) {
    StringBuilder sb = new StringBuilder();
    for (char c : s.toCharArray()) {
        sb.insert(0, c);
    }/*from   www .ja  va 2 s.  c om*/
    return sb.toString();
}

From source file:com.github.jknack.amd4j.ResourceURI.java

/**
 * Creates a {@link ResourceURI}.//from ww  w .j a  v a 2s. co m
 *
 * @param baseUrl The base url.
 * @param path The dependency's path. It might be prefixed with: <code>prefix!</code> where
 *        <code>prefix</code> is usually a plugin.
 * @return A new {@link ResourceURI}.
 */
public static ResourceURI create(final String baseUrl, final String path) {
    notEmpty(baseUrl, "The baseUrl is required.");
    String normBaseUrl = baseUrl;
    if (".".equals(normBaseUrl)) {
        normBaseUrl = SEPARATOR;
    }
    if (!normBaseUrl.startsWith(SEPARATOR)) {
        normBaseUrl = SEPARATOR + normBaseUrl;
    }
    if (!normBaseUrl.endsWith(SEPARATOR)) {
        normBaseUrl += SEPARATOR;
    }
    int idx = Math.max(0, path.indexOf('!') + 1);
    StringBuilder uri = new StringBuilder(path);
    if (uri.charAt(idx) == SEPARATOR.charAt(0)) {
        uri.deleteCharAt(idx);
    }
    uri.insert(idx, normBaseUrl);
    return create(uri.toString());
}

From source file:Main.java

/**
 * Return a BCD representation of an integer as a 4-byte array.
 * @param i int/*  w  w w .j av a  2s  .com*/
 * @return  byte[4]
 */
public static byte[] intToBcdArray(int i) {
    if (i < 0)
        throw new IllegalArgumentException("Argument cannot be a negative integer.");

    StringBuilder binaryString = new StringBuilder();

    while (true) {
        int quotient = i / 10;
        int remainder = i % 10;
        String nibble = String.format("%4s", Integer.toBinaryString(remainder)).replace(' ', '0');
        binaryString.insert(0, nibble);

        if (quotient == 0) {
            break;
        } else {
            i = quotient;
        }
    }

    return ByteBuffer.allocate(4).putInt(Integer.parseInt(binaryString.toString(), 2)).array();
}

From source file:com.ansorgit.plugins.bash.lang.valueExpansion.ValueExpansionUtil.java

private static StringBuilder makeLine(List<Expansion> reversed) {
    boolean lastFlipped = true;
    StringBuilder line = new StringBuilder();
    for (Expansion e : reversed) {
        line.insert(0, e.findNext(lastFlipped));
        lastFlipped = e.isFlipped();//from w  w  w.  j av  a  2 s. co m
    }
    return line;
}

From source file:com.ibm.soatf.tool.Utils.java

public static String insertTimestampToFilename(String fileName, Date date) {
    final int suffixPos = fileName.lastIndexOf(".");
    final String suffix = new SimpleDateFormat("_yyyyMMdd_HHmmss").format(date);
    StringBuilder sb = new StringBuilder(fileName);
    if (suffixPos == -1) {
        sb.append(suffix);/*from w ww.  j  a  v  a 2  s  .c  o m*/
    } else {
        sb.insert(suffixPos, suffix);
    }
    return sb.toString();
}

From source file:io.mpos.ui.shared.util.UiHelper.java

public static String formatAccountNumber(String accountNumber) {
    if (accountNumber == null) {
        return "";
    }//from  w w  w .ja v a2s.  c o  m
    accountNumber = accountNumber.replaceAll(" ", ""); // Removing spaces
    accountNumber = accountNumber.replaceAll("-", ""); // Removing dashes(-)
    accountNumber = accountNumber.replaceAll("[^0-9]", "\u2022"); // Making everything except numbers X's

    int initialLength = accountNumber.length();
    int numberOfSpaces = (initialLength - 1) / 4;

    StringBuilder sb = new StringBuilder(accountNumber);
    for (int i = 1; i <= numberOfSpaces; i++) {
        sb.insert(initialLength - 4 * i, " "); // Inserting spaces in the right spot.
    }

    return sb.toString();
}

From source file:Main.java

public static String addPadding(String t, String s, int num) {
    StringBuilder retVal;

    if (null == s || 0 >= num) {
        throw new IllegalArgumentException(INVALID_ARGUMENT);
    }/*w w w. j  ava2 s  .  co m*/

    if (s.length() <= num) {
        return s.concat(t);
    }

    retVal = new StringBuilder(s);

    for (int i = retVal.length(); i > 0; i -= num) {
        retVal.insert(i, t);
    }
    return retVal.toString();
}