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

private static String listToString(ArrayList<String> pathSpec) {
    if (pathSpec.isEmpty())
        return "";
    StringBuilder ret = new StringBuilder();
    ret.append(pathSpec.get(0));
    for (int i = 1, n = pathSpec.size(); i < n; i++)
        ret.append(File.separator).append(pathSpec.get(i));
    return ret.toString();
}

From source file:Main.java

/**
 * Creates a Trackpoint string from the point values.
 * /* w ww .  j a  v  a  2  s. c  om*/
 * @param lat latitude of the point.
 * @param lon longitude of the point.
 * @param elev elevation of the point.
 * @param time the time at which the point was taken.
 * @return the trackpoint string.
 */
public static String getTrackPointString(double lat, double lon, double elev, String time) {
    StringBuilder sb = new StringBuilder();
    sb.append("<trkpt lat=\"" + lat + "\" lon=\"" + lon + "\">").append("\n");
    sb.append("  <ele>" + elev + "</ele>").append("\n");
    sb.append("  <time>" + time + "</time>").append("\n");
    sb.append("</trkpt>").append("\n");
    return sb.toString();
}

From source file:Main.java

public static String renderForm(String action, List<NameValuePair> postData) {
    StringBuilder form = new StringBuilder();
    form.append("<form id=\"submitform\" method=\"POST\" action=\"").append(action).append("\">");
    for (NameValuePair p : postData) {
        form.append("<input type=\"hidden\" name=\"").append(p.getName()).append("\" value=\"")
                .append(p.getValue()).append("\" />");
    }/*  www. j  a v a 2  s  . c o  m*/
    form.append("</form>");
    return form.toString();

}

From source file:Main.java

public static String getShorty(Collection<? extends CharSequence> params, String returnType) {
    StringBuilder sb = new StringBuilder(params.size() + 1);
    sb.append(getShortyType(returnType));
    for (CharSequence typeRef : params) {
        sb.append(getShortyType(typeRef));
    }/*from ww w. j ava2  s . c  o  m*/
    return sb.toString();
}

From source file:Main.java

public static StringBuilder attribute(StringBuilder builder, String type, String name, String value) {
    builder.append("<dia:attribute name=\"").append(name);
    builder.append("\"><dia:").append(type).append(" val=\"");
    builder.append(value);//w  ww. j  a  v  a  2 s.  com
    builder.append("\"/></dia:attribute>");
    return builder;
}

From source file:Main.java

public static String _byteArrayToHex(byte[] a) {
    StringBuilder sb = new StringBuilder();
    for (byte b : a)
        sb.append(String.format("%02x-", b & 0xff));
    sb.deleteCharAt(sb.length() - 1);/*from   w  w  w . j a  va2 s .c o  m*/
    return sb.toString();
}

From source file:Main.java

/**
 * Formats a stack trace into a single line that provides relevant information for debugging
 * @param element the element to format/*from   w  w w  .  ja  v  a  2 s  .c  o m*/
 * @return a well-formatted stack-trace line containing the class name, method name, and line number
 * that, when clicked in the logcat, will display the line or source from where the message originated.
 */
public static String formatStackTrace(StackTraceElement element) {
    StringBuilder b = new StringBuilder();

    b.append(" at ");
    String clazz = element.getClassName();
    b.append(clazz).append(".");
    b.append(element.getMethodName()).append("(");
    b.append(clazz.substring(clazz.lastIndexOf(".") + 1)).append(".java:");
    b.append(element.getLineNumber()).append(")").append(" , ##");
    return b.toString();
}

From source file:Main.java

private static final void createElem(final String elemName, final Object o, final StringBuilder sb) {
    assert o != null;
    sb.append('<');
    sb.append(elemName);/*from w w  w.  j  av a 2 s . com*/
    sb.append('>');
    sb.append(o.toString());
    sb.append("</");
    sb.append(elemName);
    sb.append('>');
}

From source file:Main.java

private static String encodeChar(char c) {
    StringBuilder buf = new StringBuilder();
    buf.append("_x");
    String str = Integer.toHexString(c);
    for (int i = 4 - str.length(); i > 0; i--) {
        buf.append("0");
    }/*  www. j a v a2  s.  c  o m*/
    return buf.append(str).append("_").toString();
}

From source file:Main.java

public static String getStarMobile(String mobile) {
    if (TextUtils.isEmpty(mobile))
        return "";
    int length = mobile.length();
    if (length == 11) {
        StringBuilder builder = new StringBuilder();
        builder.append(mobile.substring(0, 3)).append("****").append(mobile.substring(7));
        return builder.toString();
    } else if (length > 7 && length < 11) {
        StringBuilder builder = new StringBuilder();
        builder.append(mobile.substring(0, 2)).append("****").append(mobile.substring(6));
        return builder.toString();
    } else {/*  www. ja  va2  s  .co  m*/
        return mobile;
    }
}