List of usage examples for java.lang StringBuilder charAt
char charAt(int index);
From source file:com.googlecode.mashups.services.generic.impl.FeedReaderImpl.java
private static Object getJSONData(String arrayName, StringBuilder content) throws Exception { if (arrayName.equalsIgnoreCase(NONE)) { // This means it is not an array, it is a simple dummy object ... if (content.indexOf("[") == -1 && content.indexOf("{") == 0) { //System.out.println("content: " + content); return new JSONObject(content.toString()); }/*from w w w . j av a 2 s . c o m*/ return new JSONArray(content.toString()); } String searchFor = "\"" + arrayName + "\":["; int arrayStartIndex = content.indexOf(searchFor); int arrayEndIndex = 0; if (arrayStartIndex <= -1) { return new JSONArray(); } // TODO optimize. int balance = 0; for (int i = (arrayStartIndex + searchFor.length()); i < content.length(); ++i) { char streamChar = content.charAt(i); if (streamChar == '[') { ++balance; } else if (streamChar == ']') { if (balance == 0) { arrayEndIndex = i + 1; break; } --balance; } } String arrayContent = "{" + content.substring(arrayStartIndex, arrayEndIndex) + "}"; // create the JSON array. JSONObject json = new JSONObject(arrayContent); return json.getJSONArray(arrayName); }
From source file:com.abstratt.mdd.internal.frontend.textuml.TextUMLFormatter.java
private static boolean endsWith(StringBuilder toCheck, String ending) { final int suffixLength = ending.length(); final int bufferLength = toCheck.length(); int bufferOffset = bufferLength - suffixLength; if (bufferOffset < 0) return false; for (int i = 0; i < suffixLength; i++) if (ending.charAt(i) != toCheck.charAt(bufferOffset + i)) return false; return true;//from w w w .j a v a2s. co m }
From source file:nl.strohalm.cyclos.utils.ActionHelper.java
/** * Return a redirect for the ActionForward with the specified parameters *//*from ww w .j av a2 s .c o m*/ public static ActionForward redirectWithParams(final HttpServletRequest request, ActionForward forward, final Map<String, Object> params) { if (forward == null) { return null; } final LocalSettings settings = SpringHelper .bean(request.getSession().getServletContext(), SettingsService.class).getLocalSettings(); forward = new ActionForward(forward); final StringBuilder path = new StringBuilder(); path.append(forward.getPath()); if (MapUtils.isNotEmpty(params)) { path.append('?'); for (final Entry<String, Object> entry : params.entrySet()) { final Object value = entry.getValue(); try { path.append(entry.getKey()).append('=').append( URLEncoder.encode(value == null ? "" : value.toString(), settings.getCharset())); } catch (final UnsupportedEncodingException e) { } path.append('&'); } if (path.charAt(path.length() - 1) == '&') { path.setLength(path.length() - 1); } forward.setPath(path.toString()); } forward.setRedirect(true); return forward; }
From source file:netbeanstypescript.TSElementHandle.java
static String symbolDisplayToHTML(Object displayParts) { if (displayParts == null) { return ""; }/* www . j a v a 2s . co m*/ StringBuilder sb = new StringBuilder(); for (JSONObject part : (List<JSONObject>) displayParts) { String text = (String) part.get("text"); String kind = (String) part.get("kind"); if (kind.endsWith("Name")) { sb.append("<b>"); } for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); switch (c) { case '<': sb.append("<"); break; case '>': sb.append(">"); break; case '&': sb.append("&"); break; case '\n': sb.append("<br>"); break; case ' ': sb.append(sb.length() == 0 || sb.charAt(sb.length() - 1) == ' ' ? " " : " "); break; default: sb.append(c); break; } } if (kind.endsWith("Name")) { sb.append("</b>"); } } sb.append("</pre>"); return sb.toString(); }
From source file:im.r_c.android.dbox.SQLBuilder.java
static String[] createAllMappingTables(TableInfo tableInfo) { // Example://from w w w.j av a2 s . c om // TableA.field1 -> TableB // TableA.field2 -> List<TableB> // TableA.field3 -> TableC // Key: table name // Value: mapping table create sql builder Map<String, StringBuilder> builderMap = new ArrayMap<>(); // Key: object column info object (aka an instance field) // Value: table name Map<ObjectColumnInfo, String> tableNameMap = new ArrayMap<>(); for (Map.Entry<String, ObjectColumnInfo> entry : tableInfo.mObjectColumnMap.entrySet()) { String field = entry.getKey(); ObjectColumnInfo oci = entry.getValue(); // Get table info of TableB or TableC String tn = tableNameMap.get(oci); if (tn == null) { tn = TableInfo.nameOf(oci.mElemClass); tableNameMap.put(oci, tn); } // Get mapping table create sql builder // for TableA to TableB/TableC mapping StringBuilder sqlBuilder = builderMap.get(tn); if (sqlBuilder == null) { sqlBuilder = new StringBuilder(); sqlBuilder.append("CREATE TABLE IF NOT EXISTS ") // Because the two table classes can't contain objects of each other, // the order of the two names does not matter. // There will NEVER be both _TableA_TableB_mapping and _TableB_TableA_mapping. .append(getMappingTableName(tableInfo.mName, tn)).append(" ("); builderMap.put(tn, sqlBuilder); } // Append current column definition to sql builder if (sqlBuilder.charAt(sqlBuilder.length() - 1) != '(') { // This is not the first column definition sqlBuilder.append(", "); } // Append column "_TableA_field1_id" sqlBuilder.append(getMappingTableIdColumn(tableInfo.mName, field)).append(" INTEGER"); if (oci.mType == ObjectColumnInfo.TYPE_OBJECT_ARRAY || oci.mType == ObjectColumnInfo.TYPE_OBJECT_LIST) { sqlBuilder.append(", ").append(getMappingTableIndexColumn(tableInfo.mName, field)) .append(" INTEGER"); } } String[] sqls = new String[builderMap.size()]; int n = 0; // Append last column "_TableB_id" for all mapping table for (Map.Entry<String, StringBuilder> entry : builderMap.entrySet()) { StringBuilder builder = entry.getValue(); builder.append(", ").append(getMappingTableIdColumn(entry.getKey(), null)) .append(" INTEGER NOT NULL);"); sqls[n++] = builder.toString(); } return sqls; }
From source file:org.dhatim.edisax.util.EDIUtils.java
private static boolean builderEndsWith(StringBuilder stringBuilder, String string) { if (string == null) { return false; }//from w w w. jav a 2 s. c o m int builderLen = stringBuilder.length(); int stringLen = string.length(); if (builderLen < stringLen) { return false; } int stringIndx = 0; for (int i = (builderLen - stringLen); i < builderLen; i++) { if (stringBuilder.charAt(i) != string.charAt(stringIndx)) { return false; } stringIndx++; } return true; }
From source file:org.eclipse.wb.internal.rcp.databinding.emf.model.bindables.EmfCodeGenUtil.java
/** * This method breaks sourceName into words delimited by separator and/or mixed-case naming. *//* w ww . j a va 2 s . c o m*/ public static List<String> parseName(String sourceName, char separator) { List<String> result = new ArrayList<String>(); if (sourceName != null) { StringBuilder currentWord = new StringBuilder(); boolean lastIsLower = false; for (int index = 0, length = sourceName.length(); index < length; ++index) { char curChar = sourceName.charAt(index); if (Character.isUpperCase(curChar) || !lastIsLower && Character.isDigit(curChar) || curChar == separator) { if (lastIsLower && currentWord.length() > 1 || curChar == separator && currentWord.length() > 0) { result.add(currentWord.toString()); currentWord = new StringBuilder(); } lastIsLower = false; } else { if (!lastIsLower) { int currentWordLength = currentWord.length(); if (currentWordLength > 1) { char lastChar = currentWord.charAt(--currentWordLength); currentWord.setLength(currentWordLength); result.add(currentWord.toString()); currentWord = new StringBuilder(); currentWord.append(lastChar); } } lastIsLower = true; } if (curChar != separator) { currentWord.append(curChar); } } result.add(currentWord.toString()); } return result; }
From source file:com.shishu.utility.string.StringUtil.java
/** * ????/*from w w w. ja v a2 s. com*/ * * @param s1 * 1 * @param s2 * 2 * @return * * @author wangtao */ public static String prepareURLString(String s1, String s2) { int len1 = s1.length(); int len2 = s2.length(); char[] b1 = new char[len1]; char[] b2 = new char[len2]; s1.getChars(0, len1, b1, 0); s2.getChars(0, len2, b2, 0); StringBuilder stringBuilder = new StringBuilder(""); // ???@ int dis = Math.abs(len1 - len2); int j = 0; char[] high, low; if (len1 > len2) { high = b1; low = b2; } else { high = b2; low = b1; } for (int i = 0; i < high.length; i++) { if (high[i] == low[j]) { stringBuilder.append(high[i]); } else if (stringBuilder.charAt(stringBuilder.length() - 1) != '@') { stringBuilder.append("@"); } if (stringBuilder.charAt(stringBuilder.length() - 1) == '@' && dis > 0) { dis--; } else { j++; } } return stringBuilder.toString(); }
From source file:com.aurel.track.exchange.msProject.exchange.MsProjectExchangeBL.java
/** * Get the time span fields into a map//from w ww .ja va 2 s . co m * * @param str * @return */ private static Map<String, Double> getTimeSpanFields(String str) { Map<String, Double> timeUnitsMap = new HashMap<String, Double>(); if (str == null || str.charAt(0) != MSPROJECT_TIME_UNITS.START_CHAR) { return timeUnitsMap; } StringBuilder stringBuffer = new StringBuilder(str.substring(1)); StringBuilder gatherUnitValue = new StringBuilder(); boolean isMinute = false; for (int i = 0; i < stringBuffer.length(); i++) { char c = stringBuffer.charAt(i); if (Character.isDigit(c)) { gatherUnitValue.append(c); } else { if (c == MSPROJECT_TIME_UNITS.TIME_SEPARATOR) { isMinute = true; continue; } if (c == MSPROJECT_TIME_UNITS.MINUTE_OR_MONTH) { if (isMinute) { timeUnitsMap.put(MSPROJECT_TIME_UNITS.MINUTE, Double.valueOf(gatherUnitValue.toString())); } else { timeUnitsMap.put(MSPROJECT_TIME_UNITS.MONTH, Double.valueOf(gatherUnitValue.toString())); } } else { timeUnitsMap.put(Character.toString(c), Double.valueOf(gatherUnitValue.toString())); } gatherUnitValue = new StringBuilder(); } } return timeUnitsMap; }
From source file:com.webbfontaine.valuewebb.model.util.Utils.java
public static String toWords(CharSequence str) { StringBuilder res = new StringBuilder(str.length()); for (int i = 0; i < str.length(); i++) { Character ch = str.charAt(i); if (Character.isUpperCase(ch)) { res.append(' ').append(ch); } else {/*from www . j av a 2 s. c om*/ res.append(ch); } } char c = Character.toUpperCase(res.charAt(0)); res.replace(0, 1, new String(new char[] { c })); return res.toString(); }