Example usage for java.lang StringBuilder charAt

List of usage examples for java.lang StringBuilder charAt

Introduction

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

Prototype

char charAt(int index);

Source Link

Document

Returns the char value at the specified index.

Usage

From source file:com.splicemachine.db.impl.ast.PlanPrinter.java

private static String printResults(int nTimes, List<Map<String, Object>> results) {
    String indent = Strings.repeat(spaces, nTimes);
    StringBuilder buf = new StringBuilder("\n");
    for (Map<String, Object> row : results) {
        buf.append(indent).append('{');
        for (Map.Entry<String, Object> entry : row.entrySet()) {
            buf.append(entry).append(", ");
        }/*from  w  ww .  ja va2 s . c  om*/
        if (buf.length() > 2 && buf.charAt(buf.length() - 2) == ',') {
            buf.setLength(buf.length() - 2);
            buf.append("}\n");
        }
    }
    if (buf.length() > 0) {
        // remove last '\n'
        buf.setLength(buf.length() - 1);
    }
    return buf.toString();
}

From source file:com.android.ide.eclipse.adt.internal.refactorings.core.RefactoringTestBase.java

public static String describe(Change change) throws Exception {
    StringBuilder sb = new StringBuilder(1000);
    describe(sb, change, 0);//from w  w w  .  ja va  2s.  c o m

    // Trim trailing space
    for (int i = sb.length() - 1; i >= 0; i--) {
        if (!Character.isWhitespace(sb.charAt(i))) {
            sb.setLength(i + 1);
            break;
        }
    }

    return sb.toString();
}

From source file:Main.java

/**
 * Used for flattening a collection of objects into a string
 * @param   array   Array of elements to flatten
 * @param   fmt Format string to use for array flattening
 * @param   separator   Separator to use for string concat
 * @return   Representative string made up of array elements */
private static String flattenCollection(String elemName, Collection<?> array, String fmt, char separator) {
    StringBuilder builder = new StringBuilder();

    //append all elements in the array into a string
    for (Object element : array) {
        String elemValue = null;//from  ww  w  .j ava 2s . c om

        //replace null values with empty string to maintain index order
        if (null == element) {
            elemValue = "";
            builder.append(String.format(fmt, elemName, elemValue, separator));
        } else {
            elemValue = tryUrlEncode(element.toString());
            builder.append(String.format(fmt, elemName, elemValue, separator));
        }
    }

    //remove the last separator, if appended
    if ((builder.length() > 1) && (builder.charAt(builder.length() - 1) == separator))
        builder.deleteCharAt(builder.length() - 1);

    return builder.toString();
}

From source file:com.abstratt.mdd.internal.frontend.textuml.TextUMLFormatter.java

private static boolean isAtWhitespace(StringBuilder output) {
    return output.length() > 0 && Character.isWhitespace(output.charAt(output.length() - 1));
}

From source file:org.fastj.fit.tool.JSONHelper.java

public static Object jsonValue(String path, Map<String, Object> jo) throws DataInvalidException {
    //find(), data(), loop(), unique(), asc(), desc()
    String regex = "^[\\S\\s]*\\[((find|data|loop|unique|asc|desc)\\(\\))\\][\\S\\s]*$";
    String regex1 = "\\[((find|data|loop|unique|asc|desc)\\(\\))\\]";

    if (path.matches(regex)) {
        Matcher m = Pattern.compile(regex1).matcher(path);
        String op = null;//from   w w  w. j  a  v a 2 s.c  o  m
        if (m.find()) {
            op = m.group(2);
        }

        if (m.find())
            throw new DataInvalidException("JSON path invalid: more op.");
        String sizePath = path.replaceAll(regex1, "[size()]");
        Object leno = jsonValueInner(sizePath, jo);
        if ("nil".equals(leno) || leno == null) {
            if ("loop".equals(op) || "find".equals(op))
                return new ArrayList<>();
            return "nil";
        }

        int lsize = (Integer) leno;

        List<Object> vl = new ArrayList<>();
        for (int i = 0; i < lsize; i++) {
            String npath = path.replaceAll(regex1, "[" + i + "]");
            Object o = jsonValueInner(npath, jo);
            if (!"nil".equals(o) && !"null".equals(o) && null != o) {
                vl.add(o);
            }
        }

        switch (op) {
        case "loop":
        case "find":
            return vl;
        case "data":
            StringBuilder buff = new StringBuilder("@data:");
            for (Object o : vl) {
                buff.append(String.valueOf(o)).append(",");
            }
            if (buff.charAt(buff.length() - 1) == ',')
                buff.deleteCharAt(buff.length() - 1);
            return buff.toString();
        case "unique":
            List<Object> chkl = new ArrayList<Object>();
            for (Object o : vl) {
                if (chkl.contains(o))
                    return "false";
                chkl.add(o);
            }
            return "true";
        case "asc":
            List<String> svl3 = new ArrayList<>();
            for (int i = 0; i < vl.size(); i++) {
                svl3.add(String.valueOf(vl.get(i)));
            }
            List<String> svl4 = new ArrayList<>();
            svl4.addAll(svl3);
            Collections.sort(svl4);

            for (int i = 0; i < svl3.size(); i++) {
                if (svl3.get(i).equals(svl4.get(i))) {
                    continue;
                } else {
                    return "false";
                }
            }

            return "true";
        case "desc":
            List<String> svl = new ArrayList<>();
            for (int i = 0; i < vl.size(); i++) {
                svl.add(String.valueOf(vl.get(i)));
            }
            List<String> svl2 = new ArrayList<>();
            svl2.addAll(svl);
            Collections.sort(svl2);

            int len = svl.size();
            for (int i = 0; i < svl.size(); i++) {
                if (svl.get(i).equals(svl2.get(len - i - 1))) {
                    continue;
                } else {
                    return "false";
                }
            }

            return "true";
        default:
            return "nil";
        }
    } else {
        return jsonValueInner(path, jo);
    }
}

From source file:Main.java

public static String toZenkakuCase(String str) {
    int f = str.length();
    StringBuilder buffer = new StringBuilder(str);

    for (int i = 0; i < f; i++) {
        char c = str.charAt(i);

        if (H2Z.containsKey(c)) {
            buffer.setCharAt(i, H2Z.get(c));
        } else if (c == 0x0020) {
            buffer.setCharAt(i, '\u3000');
        } else if (c <= 0x007E && 0x0021 <= c) {
            buffer.setCharAt(i, (char) (c + 0xFEE0));
        }/*from  w  ww  .  ja  v a  2 s .  c  o m*/

        if ((0x304B <= c && c <= 0x3062 && (c % 2 == 1)) || (0x30AB <= c && c <= 0x30C2 && (c % 2 == 1))
                || (0x3064 <= c && c <= 0x3069 && (c % 2 == 0))
                || (0x30C4 <= c && c <= 0x30C9 && (c % 2 == 0))) {
            char d = buffer.charAt(i + 1);
            buffer.setCharAt(i, (char) (c + ((d == '\u309B') ? 1 : 0)));
            if (c != buffer.charAt(i)) {
                buffer = buffer.deleteCharAt(i + 1);
                f--;
            }
            continue;
        }

        if ((0x306F <= c && c <= 0x307D && (c % 3 == 0)) || (0x30CF <= c && c <= 0x30DD && (c % 3 == 0))) {
            char d = buffer.charAt(i + 1);
            buffer.setCharAt(i, (char) (c + ((d == '\u309B') ? 1 : ((d == '\u309C') ? 2 : 0))));
            if (c != buffer.charAt(i)) {
                buffer = buffer.deleteCharAt(i + 1);
                f--;
            }
            continue;
        }

    }

    return buffer.toString();
}

From source file:org.apache.ofbiz.base.util.StringUtil.java

/** Make sure the string starts with a forward slash but does not end with one; converts back-slashes to forward-slashes; if in String is null or empty, returns zero length string. */
public static String cleanUpPathPrefix(String prefix) {
    if (UtilValidate.isEmpty(prefix))
        return "";

    StringBuilder cppBuff = new StringBuilder(prefix.replace('\\', '/'));

    if (cppBuff.charAt(0) != '/') {
        cppBuff.insert(0, '/');
    }/*from w  w  w .jav a2s. com*/
    if (cppBuff.charAt(cppBuff.length() - 1) == '/') {
        cppBuff.deleteCharAt(cppBuff.length() - 1);
    }
    return cppBuff.toString();
}

From source file:com.facebook.litho.ComponentsStethoManagerImpl.java

private static String toCSSString(String str) {
    final StringBuilder builder = new StringBuilder(str.length());
    builder.append(str);//  w ww .  j  a v a2s.c  om
    for (int i = 0, length = builder.length(); i < length; ++i) {
        final char oldChar = builder.charAt(i);
        final char lowerChar = Character.toLowerCase(oldChar);
        final char newChar = lowerChar == '_' ? '-' : lowerChar;
        builder.setCharAt(i, newChar);
    }
    return builder.toString();
}

From source file:com.facebook.litho.ComponentsStethoManagerImpl.java

private static String toEnumString(String str) {
    final StringBuilder builder = new StringBuilder(str.length());
    builder.append(str);/* w w  w  .  ja  v  a  2 s  .co  m*/
    for (int i = 0, length = builder.length(); i < length; ++i) {
        final char oldChar = builder.charAt(i);
        final char upperChar = Character.toUpperCase(oldChar);
        final char newChar = upperChar == '-' ? '_' : upperChar;
        builder.setCharAt(i, newChar);
    }
    return builder.toString();
}

From source file:org.cleverbus.common.Strings.java

/**
 * Removes last character from a builder if exists.
 *
 * @param sb string builder// w  w w. ja v a 2  s  . com
 * @param c the the character to be removed
 * @return original string builder
 */
public static StringBuilder removeLastCharacter(StringBuilder sb, char c) {
    if (sb == null) {
        return null;
    }
    int len = sb.length();
    if (len == 0) {
        return sb;
    }
    if (sb.charAt(len - 1) == c) {
        sb.setLength(len - 1);
    }
    return sb;
}