List of usage examples for java.lang StringBuilder lastIndexOf
@Override public int lastIndexOf(String str)
From source file:com.impetus.kundera.client.cassandra.dsdriver.DSClient.java
@Override public List<Object> findByRelation(String colName, Object colValue, Class entityClazz) { EntityMetadata m = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClazz); CQLTranslator translator = new CQLTranslator(); String selectQuery = translator.SELECTALL_QUERY; selectQuery = StringUtils.replace(selectQuery, CQLTranslator.COLUMN_FAMILY, translator.ensureCase(new StringBuilder(), m.getTableName(), false).toString()); StringBuilder selectQueryBuilder = new StringBuilder(selectQuery); selectQueryBuilder.append(CQLTranslator.ADD_WHERE_CLAUSE); translator.buildWhereClause(selectQueryBuilder, colValue.getClass(), colName, colValue, CQLTranslator.EQ_CLAUSE, false); selectQueryBuilder.delete(selectQueryBuilder.lastIndexOf(CQLTranslator.AND_CLAUSE), selectQueryBuilder.length()); ResultSet rSet = (ResultSet) this.execute(selectQueryBuilder.toString(), null); return iterateAndReturn(rSet, m); }
From source file:com.impetus.client.rdbms.query.RDBMSEntityReader.java
/** * //w w w . j av a 2 s . c om * @param queryBuilder * @param value * @param isString */ private void buildINClause(StringBuilder queryBuilder, Object value, boolean isString) { if (List.class.isAssignableFrom(value.getClass()) || Set.class.isAssignableFrom(value.getClass())) { queryBuilder.append(" ("); Collection collection = ((Collection) value); for (Object obj : collection) { if (isString) { appendStringPrefix(queryBuilder, isString); } queryBuilder.append(obj.toString()); if (isString) { appendStringPrefix(queryBuilder, isString); } queryBuilder.append(","); } if (!collection.isEmpty()) { queryBuilder.deleteCharAt(queryBuilder.lastIndexOf(",")); } queryBuilder.append(")"); } else { queryBuilder.append(value.toString()); } }
From source file:com.impetus.kundera.client.cassandra.dsdriver.DSClient.java
@Override public <E> List<E> getColumnsById(String schemaName, String tableName, String pKeyColumnName, String columnName, Object pKeyColumnValue, Class columnJavaType) { // select columnName from tableName where pKeyColumnName = // pKeyColumnValue List results = new ArrayList(); CQLTranslator translator = new CQLTranslator(); String selectQuery = translator.SELECT_QUERY; selectQuery = StringUtils.replace(selectQuery, CQLTranslator.COLUMN_FAMILY, translator.ensureCase(new StringBuilder(), tableName, false).toString()); selectQuery = StringUtils.replace(selectQuery, CQLTranslator.COLUMNS, translator.ensureCase(new StringBuilder(), columnName, false).toString()); StringBuilder selectQueryBuilder = new StringBuilder(selectQuery); selectQueryBuilder.append(CQLTranslator.ADD_WHERE_CLAUSE); translator.buildWhereClause(selectQueryBuilder, columnJavaType, pKeyColumnName, pKeyColumnValue, CQLTranslator.EQ_CLAUSE, false); selectQueryBuilder.delete(selectQueryBuilder.lastIndexOf(CQLTranslator.AND_CLAUSE), selectQueryBuilder.length()); ResultSet rSet = execute(selectQueryBuilder.toString(), null); Iterator<Row> rowIter = rSet.iterator(); while (rowIter.hasNext()) { Row row = rowIter.next();// www .ja va 2 s . co m DataType dataType = row.getColumnDefinitions().getType(columnName); Object columnValue = DSClientUtilities.assign(row, null, null, dataType.getName(), null, columnName, null, null); results.add(columnValue); } return results; }
From source file:org.oscarehr.PMmodule.exporter.DATISGamingForm.java
@Override protected String exportData() throws ExportException { List<IntakeNode> intakeNodes = intake.getNode().getChildren(); StringBuilder buf = new StringBuilder(); IntakeNode file5Node = null;/* w w w. jav a 2s. com*/ for (IntakeNode inode : intakeNodes) { if (StringUtils.deleteWhitespace(inode.getLabelStr()).startsWith(FILE_PREFIX)) { file5Node = inode; break; } } Set<IntakeAnswer> answers = intake.getAnswers(); for (DATISField field : fields) { if (field.getName().equalsIgnoreCase(EMPTY_FIELD_Q3_3)) { // empty question field buf.append("00000000,"); continue; } String fieldQuestion = field.getQuestion(); String lbl = null; for (IntakeAnswer ans : answers) { if (ans.getNode().getGrandParent().equals(file5Node)) { lbl = ans.getNode().getParent().getLabelStr(); if (StringUtils.deleteWhitespace(lbl.toUpperCase()) .equals(StringUtils.deleteWhitespace(fieldQuestion.toUpperCase()))) { writeCSV(buf, ans, field); //writeData(buf, ans, field); } } } } if (buf.lastIndexOf(",") == -1) { return buf.toString(); } return buf.substring(0, buf.lastIndexOf(",")).toString(); }
From source file:org.alfresco.repo.content.transform.TransformerDebug.java
/** * Removes the final "Finished in..." message from a StringBuilder * @param sb/*from w w w. j a v a 2s . co m*/ */ private void stripFinishedLine(StringBuilder sb) { if (sb != null) { int i = sb.lastIndexOf(FINISHED_IN); if (i != -1) { sb.setLength(i); i = sb.lastIndexOf("\n", i); sb.setLength(i != -1 ? i : 0); } } }
From source file:com.wipro.ats.bdre.clustermigration.MigrationPreprocessor.java
private String formFilterCondition(Set<String> modifiedBusinessPartitionSet, String sourcePartitionColumns) { StringBuilder filterCondition = new StringBuilder(); Map<String, String> partitionDataTypeMap = new HashMap<>(); String[] partitionArray = sourcePartitionColumns.split(","); for (int i = 0; i < partitionArray.length; i++) { partitionDataTypeMap.put(partitionArray[i].toUpperCase().substring(0, partitionArray[i].indexOf(" ")), partitionArray[i].toUpperCase().substring(partitionArray[i].indexOf(" "), partitionArray[i].length())); }//from w ww . j a va 2 s.com for (String busPartition : modifiedBusinessPartitionSet) { String onePartition = ""; String[] eachPartitionValue = busPartition.split("/"); StringBuilder totalRow = new StringBuilder(""); for (int i = 0; i < eachPartitionValue.length; i++) { String partitionDataType = partitionDataTypeMap .get(eachPartitionValue[i].split("=")[0].toUpperCase()); String[] colAndPartitionValue = eachPartitionValue[i].split("="); if (partitionDataType.trim().contains("STRING") || partitionDataType.trim().contains("CHAR") || partitionDataType.trim().contains("DATE") || partitionDataType.trim().contains("TIME")) { colAndPartitionValue[1] = "'" + colAndPartitionValue[1] + "'"; } onePartition = colAndPartitionValue[0] + "=" + colAndPartitionValue[1] + " AND "; totalRow.append(onePartition); } String trimmedTotalRow = totalRow.substring(0, totalRow.lastIndexOf(" AND ")); filterCondition.append(trimmedTotalRow).append(" OR "); } return filterCondition.toString().isEmpty() ? "'a'='a'" : filterCondition.substring(0, filterCondition.lastIndexOf(" OR ")); }
From source file:org.jcommon.com.util.JsonUtils.java
public static String toJson(Object o, boolean encode) { StringBuilder sb = new StringBuilder(); Class<?> type = null;/*from ww w . jav a 2s. co m*/ sb.append("{"); try { java.lang.reflect.Field[] fs = o.getClass().getDeclaredFields(); String name, value; for (java.lang.reflect.Field f : fs) { value = null; name = f.getName(); type = f.getType(); java.lang.reflect.Method m = getMethod(o.getClass(), "get" + name); if (m == null) m = getMethod(o.getClass(), "is" + name); if (m != null) { if (String.class == type) { value = (String) m.invoke(o); } else if (java.lang.Integer.class == type || Integer.TYPE == type) { value = String.valueOf((Integer) m.invoke(o)); } else if (java.lang.Boolean.class == type || Boolean.TYPE == type) { value = String.valueOf((Boolean) m.invoke(o)); } else if (java.lang.Long.class == type || Long.TYPE == type) { value = String.valueOf((Long) m.invoke(o)); } else if (java.lang.Float.class == type || Float.TYPE == type) { value = String.valueOf((Float) m.invoke(o)); } else if (java.lang.Long.class == type || Long.TYPE == type) { logger.info("not map Class:" + type); } } if (value != null) { if (encode) sb.append("\"" + CoderUtils.encode(name) + "\"" + ":\"" + CoderUtils.encode(value) + "\""); else sb.append("\"" + name + "\"" + ":\"" + value + "\""); sb.append(","); } } } catch (Throwable t) { logger.error("", t); } if (sb.lastIndexOf(",") == sb.length() - 1) sb.deleteCharAt(sb.length() - 1); sb.append("}"); return sb.toString(); }
From source file:com.xorcode.andtweet.TweetListActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { super.onContextItemSelected(item); AdapterView.AdapterContextMenuInfo info; try {/*from w ww . j a va 2 s. c om*/ info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); } catch (ClassCastException e) { Log.e(TAG, "bad menuInfo", e); return false; } mCurrentId = info.id; Uri uri; Cursor c; switch (item.getItemId()) { case CONTEXT_MENU_ITEM_REPLY: uri = ContentUris.withAppendedId(Tweets.CONTENT_URI, info.id); c = getContentResolver().query(uri, new String[] { Tweets._ID, Tweets.AUTHOR_ID }, null, null, null); try { c.moveToFirst(); String reply = "@" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID)) + " "; long replyId = c.getLong(c.getColumnIndex(Tweets._ID)); mTweetEditor.startEditing(reply, replyId); } catch (Exception e) { Log.e(TAG, "onContextItemSelected: " + e.toString()); return false; } finally { if (c != null && !c.isClosed()) c.close(); } return true; case CONTEXT_MENU_ITEM_RETWEET: uri = ContentUris.withAppendedId(Tweets.CONTENT_URI, info.id); c = getContentResolver().query(uri, new String[] { Tweets._ID, Tweets.AUTHOR_ID, Tweets.MESSAGE }, null, null, null); try { c.moveToFirst(); StringBuilder message = new StringBuilder(); String reply = "RT @" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID)) + " "; message.append(reply); CharSequence text = c.getString(c.getColumnIndex(Tweets.MESSAGE)); int len = 140 - reply.length() - 3; if (text.length() < len) { len = text.length(); } message.append(text, 0, len); if (message.length() == 137) { message.append("..."); } mTweetEditor.startEditing(message.toString(), 0); } catch (Exception e) { Log.e(TAG, "onContextItemSelected: " + e.toString()); return false; } finally { if (c != null && !c.isClosed()) c.close(); } return true; case CONTEXT_MENU_ITEM_DESTROY_STATUS: sendCommand(new CommandData(CommandEnum.DESTROY_STATUS, mCurrentId)); return true; case CONTEXT_MENU_ITEM_FAVORITE: sendCommand(new CommandData(CommandEnum.CREATE_FAVORITE, mCurrentId)); return true; case CONTEXT_MENU_ITEM_DESTROY_FAVORITE: sendCommand(new CommandData(CommandEnum.DESTROY_FAVORITE, mCurrentId)); return true; case CONTEXT_MENU_ITEM_SHARE: uri = ContentUris.withAppendedId(Tweets.CONTENT_URI, info.id); c = getContentResolver().query(uri, new String[] { Tweets._ID, Tweets.AUTHOR_ID, Tweets.MESSAGE }, null, null, null); try { c.moveToFirst(); StringBuilder subject = new StringBuilder(); StringBuilder text = new StringBuilder(); String message = c.getString(c.getColumnIndex(Tweets.MESSAGE)); subject.append(getText(R.string.button_create_tweet)); subject.append(" - " + message); int maxlength = 80; if (subject.length() > maxlength) { subject.setLength(maxlength); // Truncate at the last space subject.setLength(subject.lastIndexOf(" ")); subject.append("..."); } text.append(message); text.append("\n-- \n" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID))); text.append("\n URL: " + "http://twitter.com/" + c.getString(c.getColumnIndex(Tweets.AUTHOR_ID)) + "/status/" + c.getString(c.getColumnIndex(Tweets._ID))); Intent share = new Intent(android.content.Intent.ACTION_SEND); share.setType("text/plain"); share.putExtra(Intent.EXTRA_SUBJECT, subject.toString()); share.putExtra(Intent.EXTRA_TEXT, text.toString()); startActivity(Intent.createChooser(share, getText(R.string.menu_item_share))); } catch (Exception e) { Log.e(TAG, "onContextItemSelected: " + e.toString()); return false; } finally { if (c != null && !c.isClosed()) c.close(); } return true; case CONTEXT_MENU_ITEM_UNFOLLOW: case CONTEXT_MENU_ITEM_BLOCK: case CONTEXT_MENU_ITEM_DIRECT_MESSAGE: case CONTEXT_MENU_ITEM_PROFILE: Toast.makeText(this, R.string.unimplemented, Toast.LENGTH_SHORT).show(); return true; } return false; }
From source file:com.vinaysshenoy.easyoauth.factory.OAuthFactory.java
public InputStream executeRequestForInputStream(HttpRequestTypes requestType, String requestUrl, Bundle params) throws OAuthFactoryException, OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, IllegalStateException, IOException { if (accessToken == null) { throw new OAuthFactoryException(OAuthFactoryException.OAuthExceptionMessages.OAUTH_NOT_AUTHORIZED); }/*from www. j av a 2s .com*/ StringBuilder requestParamsBuilder; switch (requestType) { case GET: HttpGet get = null; requestParamsBuilder = new StringBuilder('?'); if (params != null && params.size() > 0) { Set<String> keySet = params.keySet(); Iterator<String> keyIterator = keySet.iterator(); String curKey; while (keyIterator.hasNext()) { curKey = keyIterator.next(); requestParamsBuilder.append(curKey).append('=').append(params.get(curKey)); requestParamsBuilder.append('&'); } } switch (oAuthConfig.oAuthType) { case OAUTH_1_0_A: if (requestParamsBuilder.lastIndexOf("&") != -1) requestParamsBuilder.deleteCharAt(requestParamsBuilder.length() - 1); get = new HttpGet(requestUrl + requestParamsBuilder.toString()); signHttpRequest(get); break; case OAUTH_2_0: requestParamsBuilder.append(oAuthConfig.oAuthToken).append('=').append(accessToken.getToken()); get = new HttpGet(requestUrl + requestParamsBuilder.toString()); break; } return httpManager.executeHttpRequestForStreamResponse(get); case POST: HttpPost post = null; List<NameValuePair> postParams = null; if (params != null && params.size() > 0) { Set<String> keySet = params.keySet(); Iterator<String> keyIterator = keySet.iterator(); String curKey; postParams = new ArrayList<NameValuePair>(params.size()); while (keyIterator.hasNext()) { curKey = keyIterator.next(); postParams.add(new BasicNameValuePair(curKey, params.getString(curKey))); } } switch (oAuthConfig.oAuthType) { case OAUTH_1_0_A: post = new HttpPost(requestUrl); signHttpRequest(post); break; case OAUTH_2_0: requestParamsBuilder = new StringBuilder('?'); requestParamsBuilder.append(oAuthConfig.oAuthToken).append('=').append(accessToken.getToken()); post = new HttpPost(requestUrl + requestParamsBuilder.toString()); break; } post.setEntity(new UrlEncodedFormEntity(postParams)); return httpManager.executeHttpRequestForStreamResponse(post); default: throw new OAuthFactoryException(OAuthFactoryException.OAuthExceptionMessages.UNSUPPORTED_METHOD); } }
From source file:com.vinaysshenoy.easyoauth.factory.OAuthFactory.java
public String executeRequestForString(HttpRequestTypes requestType, String requestUrl, Bundle params) throws OAuthFactoryException, OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, IllegalStateException, IOException { if (accessToken == null) { throw new OAuthFactoryException(OAuthFactoryException.OAuthExceptionMessages.OAUTH_NOT_AUTHORIZED); }//from ww w .j av a2 s.com StringBuilder requestParamsBuilder; switch (requestType) { case GET: HttpGet get = null; requestParamsBuilder = new StringBuilder('?'); if (params != null && params.size() > 0) { Set<String> keySet = params.keySet(); Iterator<String> keyIterator = keySet.iterator(); String curKey; while (keyIterator.hasNext()) { curKey = keyIterator.next(); requestParamsBuilder.append(curKey).append('=').append(params.get(curKey)); requestParamsBuilder.append('&'); } } switch (oAuthConfig.oAuthType) { case OAUTH_1_0_A: if (requestParamsBuilder.lastIndexOf("&") != -1) requestParamsBuilder.deleteCharAt(requestParamsBuilder.length() - 1); get = new HttpGet(requestUrl + requestParamsBuilder.toString()); signHttpRequest(get); break; case OAUTH_2_0: requestParamsBuilder.append(oAuthConfig.oAuthToken).append('=').append(accessToken.getToken()); get = new HttpGet(requestUrl + requestParamsBuilder.toString()); break; } return httpManager.executeHttpRequestForStringResponse(get); case POST: HttpPost post = null; List<NameValuePair> postParams = null; if (params != null && params.size() > 0) { Set<String> keySet = params.keySet(); Iterator<String> keyIterator = keySet.iterator(); String curKey; postParams = new ArrayList<NameValuePair>(params.size()); while (keyIterator.hasNext()) { curKey = keyIterator.next(); postParams.add(new BasicNameValuePair(curKey, params.getString(curKey))); } } switch (oAuthConfig.oAuthType) { case OAUTH_1_0_A: post = new HttpPost(requestUrl); signHttpRequest(post); break; case OAUTH_2_0: requestParamsBuilder = new StringBuilder('?'); requestParamsBuilder.append(oAuthConfig.oAuthToken).append('=').append(accessToken.getToken()); post = new HttpPost(requestUrl + requestParamsBuilder.toString()); break; } post.setEntity(new UrlEncodedFormEntity(postParams)); return httpManager.executeHttpRequestForStringResponse(post); default: throw new OAuthFactoryException(OAuthFactoryException.OAuthExceptionMessages.UNSUPPORTED_METHOD); } }