Example usage for java.lang StringBuilder append

List of usage examples for java.lang StringBuilder append

Introduction

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

Prototype

@Override
    public StringBuilder append(double d) 

Source Link

Usage

From source file:Main.java

public static String convertByteArrayToHex(byte[] bytes) {
    if (bytes == null) {
        return null;
    }//from ww  w  .j  a  va 2  s .  co m
    StringBuilder sb = new StringBuilder();
    for (byte b : bytes) {
        sb.append(String.format("%02X", b));
    }
    return sb.toString();
}

From source file:Main.java

/**
 * Format a string with size information about a map whose values are lists of elements.
 * @param <T> the type of the keys in the map.
 * @param <U> the type of the values in the map.
 * @param name an arbitrary name given to the map.
 * @param map the map from which to get size information.
 * @return a string containing information about the number of elements in the map. 
 *//*from   ww  w. j a v a2s .c om*/
public static <T, U> String formatSizeMapInfo(String name, Map<T, List<U>> map) {
    StringBuilder sb = new StringBuilder();
    sb.append(name).append("[shallow size=").append(map.size());
    sb.append(", total elements=").append(sizeOfListMap(map)).append("]");
    return sb.toString();
}

From source file:Main.java

/**
 * @param output/* w ww.  ja v a2  s  .  c o  m*/
 * @param propertyName
 */
public static void appendEmptyNode(StringBuilder output, String propertyName) {
    output.append(START_BRACKET).append(getCleanPropertyName(propertyName)).append(END_SLASH)
            .append(END_BRACKET);
}

From source file:Main.java

/**
 * Constructs a string representation of the specified collection.
 * // w ww.  j  a  v a2  s .com
 * <p>Empty collections are represented as {@code "[ ]"}. A collection with a single
 * element would be represented as {@code "[ item ]"}, where <em>"item"</em> is the
 * value of {@link String#valueOf(Object) String.valueOf(theOneItem)}. Collections
 * with multiple items follow the same pattern, with multiple items separated by a
 * comma and a single space, like so: {@code "[ item1, item2, item3 ]"}.
 *
 * @param coll the collection
 * @return a string representation of {@code coll}
 */
public static String toString(Iterable<?> coll) {
    StringBuilder sb = new StringBuilder();
    sb.append("[");
    boolean first = true;
    for (Object item : coll) {
        if (first) {
            first = false;
        } else {
            sb.append(",");
        }
        sb.append(" ");
        if (item == coll) {
            // don't overflow stack if collection contains itself
            sb.append("( this collection )");
        } else {
            sb.append(String.valueOf(item));
        }
    }
    sb.append(" ]");
    return sb.toString();
}

From source file:Main.java

public static String formatDuration(Integer seconds) {
    if (seconds == null) {
        return null;
    }//  w  w w  .j  a v a  2s .  c om

    int minutes = seconds / 60;
    int secs = seconds % 60;

    StringBuilder builder = new StringBuilder(6);
    builder.append(minutes).append(":");
    if (secs < 10) {
        builder.append("0");
    }
    builder.append(secs);
    return builder.toString();
}

From source file:Main.java

public static String arrayToString(String[] arr) {
    if (arr == null)
        return "<Null>";
    StringBuilder b = new StringBuilder();
    for (String str : arr) {
        b.append(str);
        b.append(" ");
    }/*from  w w w .  j av  a  2  s .c  o m*/
    return b.toString();
}

From source file:Main.java

private static String wrap(String s, float width, Paint p) {
    String[] str = s.split("\\s"); // regex
    StringBuilder smb = new StringBuilder(); // save memory
    smb.append(SYSTEM_NEWLINE);
    for (String element : str) {
        float length = p.measureText(element);
        String[] pieces = smb.toString().split(SYSTEM_NEWLINE);
        try {//  w  w w . j  av a2  s.  c o m
            if ((p.measureText(pieces[pieces.length - 1]) + length) > width) {
                smb.append(SYSTEM_NEWLINE);
            }
        } catch (Exception e) {
        }
        smb.append(element + " ");
    }
    return smb.toString().replaceFirst(SYSTEM_NEWLINE, "");
}

From source file:fr.free.divde.webcam.image.DataImageUrl.java

public static String imageToDataURL(BufferedImage image, String format, String mimeType) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ImageIO.write(image, format, out);
    byte[] imageBytes = out.toByteArray();
    String base64 = Base64.encodeBase64String(imageBytes);
    StringBuilder res = new StringBuilder("data:");
    res.append(mimeType);
    res.append(";base64,");
    res.append(base64);//from w ww  .j  a va 2 s . c  o  m
    return res.toString();
}

From source file:Main.java

public static String implode(Iterator it) {
    StringBuilder sb = new StringBuilder();
    while (it.hasNext()) {
        sb.append(it.next());
        sb.append(", ");
    }// w  w w  .  ja  v  a 2  s.c om

    return sb.toString().replaceAll(", +$", "");
}

From source file:Main.java

/**
 * Prepare and sanitize a string to be used as parameter for a command
 * @param s/*from  www  .  j  a va 2  s . co m*/
 * @return A string safe to use as parameter for a command
 */
public static String shellEscape(String s) {
    StringBuilder sb = new StringBuilder(s.length() + 200);
    sb.append("'");
    sb.append(s.replace("'", "\\'").replace("\n", "\\\n"));
    sb.append("'");
    return sb.toString();
}