List of usage examples for java.lang StringBuilder delete
@Override public StringBuilder delete(int start, int end)
From source file:com.todoroo.astrid.adapter.UpdateAdapter.java
@SuppressWarnings("nls") private static String getRepeatString(Context context, String value) { if (TextUtils.isEmpty(value) || "null".equals(value)) return null; try {/*from w w w . ja v a 2s.c o m*/ JSONObject repeat = new JSONObject(value); boolean weekdays = false; if (repeat.has("freq")) { String freq = repeat.getString("freq"); int interval = repeat.getInt("interval"); JSONArray byDay = repeat.optJSONArray("byday"); String[] byDayStrings = null; if (byDay != null) { byDayStrings = new String[byDay.length()]; for (int i = 0; i < byDay.length(); i++) { byDayStrings[i] = byDay.getString(i); } } String result = ""; if ("WEEKLY".equals(freq) && byDay != null && byDayStrings != null) { Arrays.sort(byDayStrings); StringBuilder daysString = new StringBuilder(); daysString.append("["); for (String s : byDayStrings) { daysString.append("\"").append(s).append("\"").append(","); } daysString.deleteCharAt(daysString.length() - 1); daysString.append("]"); if (daysString.toString().equals("[\"FR\",\"MO\",\"TH\",\"TU\",\"WE\"]")) { result = context.getString(R.string.repeat_weekdays); weekdays = true; } } if (!weekdays) { if (interval == 1) { result = context.getString(INTERVAL_LABELS.get(freq)); result = result.substring(0, result.length() - 1); } else { result = interval + " " + context.getString(INTERVAL_LABELS.get(freq)); } } result = context.getString(R.string.history_repeat_every, result); if ("WEEKLY".equals(freq) && !weekdays && byDay != null && byDay.length() > 0 && byDayStrings != null) { Arrays.sort(byDayStrings, new Comparator<String>() { @Override public int compare(String lhs, String rhs) { int lhIndex = AndroidUtilities.indexOf(SORTED_WEEKDAYS, lhs); int rhIndex = AndroidUtilities.indexOf(SORTED_WEEKDAYS, rhs); if (lhIndex < rhIndex) return -1; else if (lhIndex > rhIndex) return 1; else return 0; } }); StringBuilder byDayDisplay = new StringBuilder(); for (String s : byDayStrings) { byDayDisplay.append(s).append(", "); } byDayDisplay.delete(byDayDisplay.length() - 2, byDayDisplay.length()); result += (" " + context.getString(R.string.history_repeat_on, byDayDisplay.toString())); } if ("COMPLETION".equals(repeat.optString("from"))) result += (" " + context.getString(R.string.history_repeat_from_completion)); return result; } else { return null; } } catch (JSONException e) { return null; } }
From source file:edu.uci.ics.external.connector.asterixdb.ConnectorUtils.java
public static void cleanDataset(StorageParameter storageParameter, DatasetInfo datasetInfo) throws Exception { // DDL service URL. String url = storageParameter.getServiceURL() + "/ddl"; // Builds the DDL string to delete and (re-)create the sink datset. StringBuilder ddlBuilder = new StringBuilder(); // use dataverse statement. ddlBuilder.append("use dataverse "); ddlBuilder.append(storageParameter.getDataverseName()); ddlBuilder.append(";"); // drop dataset statement. ddlBuilder.append("drop dataset "); ddlBuilder.append(storageParameter.getDatasetName()); ddlBuilder.append(";"); // create datset statement. ddlBuilder.append("create temporary dataset "); ddlBuilder.append(storageParameter.getDatasetName()); ddlBuilder.append("("); ddlBuilder.append(datasetInfo.getRecordType().getTypeName()); ddlBuilder.append(")"); ddlBuilder.append(" primary key "); for (String primaryKey : datasetInfo.getPrimaryKeyFields()) { ddlBuilder.append(primaryKey);/* w w w. j a va 2 s.c o m*/ ddlBuilder.append(","); } ddlBuilder.delete(ddlBuilder.length() - 1, ddlBuilder.length()); ddlBuilder.append(";"); // Create a method instance. PostMethod method = new PostMethod(url); method.setRequestEntity(new StringRequestEntity(ddlBuilder.toString())); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); // Execute the method. executeHttpMethod(method); }
From source file:com.ing.connector.util.WStringUtil.java
public static List<String> splitLine(String input, int splitPosition) { List<String> lines = new ArrayList<String>(); StringBuilder stringBuilder = new StringBuilder(input.trim()); boolean linesRemaining = true; while (linesRemaining) { if (stringBuilder.length() <= splitPosition || stringBuilder.lastIndexOf(" ") < splitPosition) { lines.add(stringBuilder.toString()); linesRemaining = false;/* w w w. jav a 2 s . com*/ } else { int indexOfSpace = stringBuilder.indexOf(" ", splitPosition); String nextLine = stringBuilder.substring(0, indexOfSpace + 1); lines.add(nextLine); stringBuilder.delete(0, indexOfSpace + 1); } } return lines; }
From source file:ObjectInspector.java
/** * Attempts to build a nicer looking string than the basic * {@link Object}.toString()//from w w w .ja va2 s .c om * * @param o * The object to build from * @return A descriptive string */ private static String buildString(Object o) { if (o == null) { return "null"; } // first see if there is a version of toString more specific // than that supplied by Object... try { Method m = o.getClass().getMethod("toString"); if (!m.getDeclaringClass().equals(Object.class)) { return o.toString(); } } catch (SecurityException e) { } catch (NoSuchMethodException e) { } // then see if it is an array... if (o.getClass().isArray()) { StringBuilder buff = new StringBuilder(" [ "); for (int i = 0; i < Array.getLength(o); i++) { /* * this could recurse infinitely, but only if the user is * trying to be malicious, like so - Object[] array = new * Object[ 1 ]; array[ 0 ] = array; - which, I'm sure * we'll agree, is and odd thing to do. I say let the * StackOverflowException catch it. */ buff.append(buildString(Array.get(o, i))); buff.append(", "); } if (Array.getLength(o) > 0) { buff.delete(buff.length() - 2, buff.length()); } buff.append(" ]"); return buff.toString(); } return getObjectPosition(o); }
From source file:models.MBox.java
/** * Returns a list of all selected e-mails of the given user * /*from ww w . ja v a 2s.c om*/ * @param userId * the user-id * @return a list of e-mails */ public static String getSelectedMailsForTxt(Long userId, List<Long> boxIds) { StringBuilder query = new StringBuilder(); if (boxIds.size() <= 0) return ""; query.append("SELECT m.id, m.address, m.domain FROM MAILBOXES m WHERE "); query.append("m.usr_id = ").append(userId); query.append(" AND ("); for (Long bId : boxIds) { query.append(" id = ").append(bId); query.append(" OR"); } query.delete(query.length() - 2, query.length()); query.append(");"); RawSql rawSql = RawSqlBuilder.parse(query.toString()).columnMapping("m.id", "id") .columnMapping("m.address", "address").columnMapping("m.domain", "domain").create(); Query<MBox> quer = Ebean.find(MBox.class).setRawSql(rawSql); List<MBox> selectedBoxes = quer.findList(); return getBoxListToText(selectedBoxes); }
From source file:com.ettrema.httpclient.RangedGetMethod.java
private String getRangesRequest(List<Range> ranges) { StringBuilder sb = new StringBuilder(); for (Range d : ranges) { sb.append(d.getRange()).append(","); }//w ww . j ava 2 s . co m sb.delete(sb.length() - 1, sb.length()); return sb.toString(); }
From source file:com.glaf.core.util.DateUtils.java
public static List<Integer> getYearDays(int year) { List<Integer> list = new ArrayList<Integer>(); StringBuilder buff = new StringBuilder(); for (int i = 1; i <= 12; i++) { int day = 30; switch (i) { case 1://ww w .ja va2s. c om case 3: case 5: case 7: case 8: case 10: case 12: day = 31; break; case 2: if (year % 4 == 0 || year % 400 == 0) { day = 29; } else { day = 28; } break; default: day = 30; break; } for (int j = 1; j <= day; j++) { buff.delete(0, buff.length()); buff.append(year); if (i < 10) { buff.append("0"); } buff.append(i); if (j < 10) { buff.append("0"); } buff.append(j); list.add(Integer.valueOf(buff.toString())); } } return list; }
From source file:com.springrts.springls.Client.java
private static void deleteLeadingWhiteSpace(StringBuilder str) { int wsPos = 0; while ((wsPos < str.length()) && isWhiteSpace(str.charAt(wsPos))) { wsPos++;// w w w . jav a2 s.c o m } str.delete(0, wsPos); }
From source file:com.cloud.utils.db.SqlGenerator.java
public static StringBuilder buildMysqlUpdateSql(String joins, Collection<Ternary<Attribute, Boolean, Object>> setters) { if (setters.size() == 0) { return null; }/*w w w . java2 s .c om*/ StringBuilder sql = new StringBuilder("UPDATE "); sql.append(joins); sql.append(" SET "); for (Ternary<Attribute, Boolean, Object> setter : setters) { Attribute attr = setter.first(); sql.append(attr.table).append(".").append(attr.columnName).append("="); if (setter.second() != null) { sql.append(attr.table).append(".").append(attr.columnName).append(setter.second() ? "+" : "-"); } sql.append("?, "); } sql.delete(sql.length() - 2, sql.length()); sql.append(" WHERE "); return sql; }
From source file:org.oscarehr.common.service.E2ESchedulerJob.java
/** * Helper function for reusing a StringBuilder object for efficiency * Blanks out existing sb contents and returns sb * //w w w .j av a2 s .co m * @param sb */ private StringBuilder reuseStringBuilder(final StringBuilder sb) { sb.delete(0, sb.length()); return sb; }