Example usage for java.lang StringBuffer append

List of usage examples for java.lang StringBuffer append

Introduction

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

Prototype

@Override
    public synchronized StringBuffer append(double d) 

Source Link

Usage

From source file:gov.nyc.doitt.gis.geoclient.parser.regex.PatternUtils.java

public static String literalMatchGroup(Collection<String> strings) {
    Assert.notEmpty(strings, "Collection of strings argument cannot be empty or null");
    StringBuffer buff = new StringBuffer("(");
    for (String s : strings) {
        buff.append(s);
        buff.append("|");
    }//from   w  w  w . j av a 2 s . co m
    buff.deleteCharAt(buff.lastIndexOf("|"));
    buff.append(")");
    return buff.toString();
}

From source file:Main.java

/**
 * /*from www.  j a va2s.c  o m*/
 * Get a valid xPath string to enable retrieval of an Element by ANDing
 * attributes name and their corresponding value. note that the full tag
 * path must also be stated
 * 
 * @param tagPath
 *            example: /calls/step
 * @param attrNames
 *            example: call_step
 * @param attrValues
 *            example: Call failed
 * 
 * @return A valid xPath string
 * 
 * 
 */
public static String getXpathAND(String tagPath, String[] attrNames, String[] attrValues) {
    StringBuffer buf = new StringBuffer();
    String retStr;

    buf.append(tagPath);
    buf.append("[");
    for (int i = 0; i < attrValues.length; i++) {
        buf.append("@");
        buf.append(attrNames[i]);
        buf.append("=");
        buf.append("'");
        buf.append(attrValues[i]);
        buf.append("'");
        if (i != (attrValues.length - 1))
            buf.append(" and ");
    }
    buf.append("]");

    System.out.println("Xpath generated: " + (retStr = buf.toString()));

    return retStr;
}

From source file:Main.java

public static String getFileSize(long fileSize) {
    int freeUnit;
    for (freeUnit = 0; fileSize >= 100; freeUnit++) {
        fileSize /= 1024;//from  w w  w  . ja va 2s. c  o  m
    }
    DecimalFormat decFormat = new DecimalFormat("0.0");
    String doubleString = decFormat.format(fileSize);
    StringBuffer buffer = new StringBuffer();
    buffer.append(doubleString);
    switch (freeUnit) {
    case 0:
        buffer.append("B");
        break;
    case 1:
        buffer.append("KB");
        break;
    case 2:
        buffer.append("MB");
        break;
    case 3:
        buffer.append("GB");
        break;
    case 4:
        buffer.append("TB");
        break;
    default:
        buffer.append("err");
        break;
    }
    return buffer.toString();
}

From source file:Main.java

public static String bytesToHexes(byte[] bytes) {
    if (bytes == null || bytes.length == 0) {
        return null;
    }//  w ww.  j  a v a2  s  . co m
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < bytes.length; i++) {
        sb.append(byteToHexDigits(bytes[i]));
    }
    return sb.toString();
}

From source file:Main.java

/**
 * Escape unprintable characters using <backslash>uxxxx notation
 * for U+0000 to U+FFFF and <backslash>Uxxxxxxxx for U+10000 and
 * above.  If the character is printable ASCII, then do nothing
 * and return FALSE.  Otherwise, append the escaped notation and
 * return TRUE./*from  www .ja  va2s.  c  om*/
 */
public static boolean escapeUnprintable(StringBuffer result, int c) {
    if (isUnprintable(c)) {
        result.append('\\');
        if ((c & ~0xFFFF) != 0) {
            result.append('U');
            result.append(DIGITS[0xF & (c >> 28)]);
            result.append(DIGITS[0xF & (c >> 24)]);
            result.append(DIGITS[0xF & (c >> 20)]);
            result.append(DIGITS[0xF & (c >> 16)]);
        } else {
            result.append('u');
        }
        result.append(DIGITS[0xF & (c >> 12)]);
        result.append(DIGITS[0xF & (c >> 8)]);
        result.append(DIGITS[0xF & (c >> 4)]);
        result.append(DIGITS[0xF & c]);
        return true;
    }
    return false;
}

From source file:Main.java

public static String truncateChange(String change, boolean isPercentChange) {
    String weight = change.substring(0, 1);
    String ampersand = "";
    if (isPercentChange) {
        ampersand = change.substring(change.length() - 1, change.length());
        change = change.substring(0, change.length() - 1);
    }/* w  ww.j  av a  2s  .  co  m*/
    change = change.substring(1, change.length());
    double round = (double) Math.round(Double.parseDouble(change) * 100) / 100;
    change = String.format("%.2f", round);
    StringBuffer changeBuffer = new StringBuffer(change);
    changeBuffer.insert(0, weight);
    changeBuffer.append(ampersand);
    change = changeBuffer.toString();
    return change;
}

From source file:Main.java

public static String toHex(byte[] buffer) {
    StringBuffer sb = new StringBuffer(buffer.length * 2);
    for (int i = 0; i < buffer.length; i++) {
        sb.append(Character.forDigit((buffer[i] & 240) >> 4, 16));
        sb.append(Character.forDigit(buffer[i] & 15, 16));
    }/* www  .j  a v  a 2  s . c o  m*/
    return sb.toString();
}

From source file:Main.java

/**
 * Returns a string representing the cutpoints
 *//*from  www  .j  a  v a2s .c om*/
public static String cutpointsToString(double[] cutPoints, boolean[] cutAndLeft) {
    StringBuffer text = new StringBuffer("");
    if (cutPoints == null) {
        text.append("\n# no cutpoints found - attribute \n");
    } else {
        text.append("\n#* " + cutPoints.length + " cutpoint(s) -\n");
        for (int i = 0; i < cutPoints.length; i++) {
            text.append("# " + cutPoints[i] + " ");
            text.append("" + cutAndLeft[i] + "\n");
        }
        text.append("# end\n");
    }
    return text.toString();
}

From source file:Main.java

public static String toMD5(String md5) {
    try {//from   w ww  .j ava 2 s. c  om
        java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
        byte[] array = md.digest(md5.getBytes());
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < array.length; ++i) {
            sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
        }
        return sb.toString();
    } catch (java.security.NoSuchAlgorithmException e) {
    }
    return null;
}

From source file:Util.java

/**
 * Return a string representation of a color
 * //from w  w w  . j  a  v  a2  s.c o  m
 * @param color
 * @return string representation
 */
public static String colorToString(Color color) {
    if (color == null) {
        return "";
    }

    StringBuffer buf = new StringBuffer();
    buf.append('#');
    buf.append(numberToPaddedHexString(color.getRed(), 2));
    buf.append(numberToPaddedHexString(color.getGreen(), 2));
    buf.append(numberToPaddedHexString(color.getBlue(), 2));

    return buf.toString();
}