List of usage examples for java.lang StringBuilder deleteCharAt
@Override public StringBuilder deleteCharAt(int index)
From source file:edu.ku.brc.af.ui.forms.BaseBusRules.java
/** * @param stmt/* w w w .j a va 2 s. co m*/ * @param tableName * @param columnName * @param ids * @return */ public Integer getCount(final Statement stmt, final String tableName, final String columnName, final Integer... ids) { Integer count = null; try { StringBuilder idString = new StringBuilder(); for (Integer i : ids) { idString.append(i); idString.append(", "); } idString.deleteCharAt(idString.length() - 2); DBTableInfo tableInfo = DBTableIdMgr.getInstance().getInfoByTableName(tableName); String extraColumns = getExtraWhereColumns(tableInfo); String join = QueryAdjusterForDomain.getInstance().getJoinClause(tableInfo, false, tableInfo.getAbbrev(), false); String queryString = "select count(*) from " + tableName + " " + tableInfo.getAbbrev() + " " + (join != null ? join : "") + " where " + tableInfo.getAbbrev() + "." + columnName + " in (" + idString.toString() + ") "; if (StringUtils.isNotEmpty(extraColumns)) { queryString += " AND " + extraColumns; } //log.debug(queryString); ResultSet rs = stmt.executeQuery(queryString); if (rs.next()) { count = rs.getInt(1); } rs.close(); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(BaseBusRules.class, ex); ex.printStackTrace(); } return count; }
From source file:com.krawler.spring.crm.accountModule.crmAccountDAOImpl.java
public List<CrmAccount> getAccounts(List<String> recordIds) { if (recordIds == null || recordIds.isEmpty()) { return null; }//from w ww . j av a 2s . co m StringBuilder hql = new StringBuilder("from CrmAccount where accountid in ("); for (String record : recordIds) { hql.append("'" + record + "',"); } hql.deleteCharAt(hql.length() - 1); hql.append(")"); return executeQuery(hql.toString()); }
From source file:au.org.ala.delta.util.Utils.java
/** * Capitalises the first word in the supplied text (which may contain RTF * markup) the first letter of the word is preceded by a '|'. * /*from w w w . ja va 2 s. c o m*/ * @param text * the text to capitalise. * @return the text with the first word capitalised. */ public static String capitaliseFirstWord(String text) { if (StringUtils.isEmpty(text)) { return text; } StringBuilder tmp = new StringBuilder(); tmp.append(text); int index = 0; while (index >= 0 && index < text.length() && !Character.isLetterOrDigit(tmp.charAt(index))) { if (tmp.charAt(index) == '\\') { index = RTFUtils.skipKeyword(text, index); if (index < 0 || index >= tmp.length() || Character.isLetterOrDigit(tmp.charAt(index))) { break; } } index++; } if (index >= 0 && index < text.length() && Character.isLetter(tmp.charAt(index))) { if ((index == 0) || (tmp.charAt(index - 1) != '|')) { tmp.setCharAt(index, Character.toUpperCase(tmp.charAt(index))); } else if (tmp.charAt(index - 1) == '|') { tmp.deleteCharAt(index - 1); } } return tmp.toString(); }
From source file:net.sf.jabref.importer.fetcher.IEEEXploreFetcher.java
private String createBibtexQueryURL(JSONObject searchResultsJson) { //buffer to use for building the URL for fetching the bibtex data from IEEEXplore StringBuilder bibtexQueryURLStringBuf = new StringBuilder(); bibtexQueryURLStringBuf.append(URL_BIBTEX_START); //loop over each record and create a comma-separate list of article numbers which will be used to download the raw Bibtex JSONArray recordsJsonArray = searchResultsJson.getJSONArray("records"); for (int n = 0; n < recordsJsonArray.length(); n++) { if (!recordsJsonArray.getJSONObject(n).isNull("articleNumber")) { bibtexQueryURLStringBuf.append(recordsJsonArray.getJSONObject(n).getString("articleNumber")) .append(','); }//from w ww.j av a2 s .c o m } //delete the last comma bibtexQueryURLStringBuf.deleteCharAt(bibtexQueryURLStringBuf.length() - 1); //add the abstract setting boolean includeAbstract = absCheckBox.isSelected(); if (includeAbstract) { bibtexQueryURLStringBuf.append("&citations-format=citation-abstract"); } else { bibtexQueryURLStringBuf.append("&citations-format=citation-only"); } //append the remaining URL bibtexQueryURLStringBuf.append(URL_BIBTEX_END); return bibtexQueryURLStringBuf.toString(); }
From source file:com.cyberway.issue.net.PublicSuffixes.java
protected static void buildRegex(String stem, StringBuilder regex, SortedSet<String> prefixes) { if (prefixes.isEmpty()) { return;/*from w ww . j a va 2 s . com*/ } if (prefixes.size() == 1 && prefixes.first().equals(stem)) { // avoid unnecessary "(?:)" return; } regex.append("(?:"); if (stem.length() == 0) { regex.append("\n "); // linebreak-space before first character } Iterator<String> iter = prefixes.iterator(); char c = 0; while (iter.hasNext()) { String s = iter.next(); if (s.length() > stem.length()) { char d = s.charAt(stem.length()); if (d == '+') { // convert exception to zero-width-positive-lookahead regex.append("(?=" + s.substring(stem.length() + 1) + ")"); } else { if (d == c) { continue; } c = d; regex.append(c); String newStem = s.substring(0, stem.length() + 1); SortedSet<String> tail = prefixes.tailSet(newStem); SortedSet<String> range = null; successor: for (String candidate : tail) { if (!candidate.equals(newStem)) { range = prefixes.subSet(s, candidate); break successor; } } if (range == null) { range = prefixes.tailSet(s); } buildRegex(newStem, regex, range); } regex.append('|'); } else { // empty suffix; insert dummy to be eaten when loop exits regex.append('@'); } } // eat the trailing '|' (if no empty '@') or dummy regex.deleteCharAt(regex.length() - 1); regex.append(')'); if (stem.length() == 1) { regex.append('\n'); // linebreak for TLDs } }
From source file:com.baseproject.volley.toolbox.BasicNetwork.java
@Override public NetworkResponse performRequest(Request<?> request) throws VolleyError { long requestStart = SystemClock.elapsedRealtime(); while (true) { HttpResponse httpResponse = null; byte[] responseContents = null; Map<String, String> responseHeaders = new HashMap<String, String>(); try {/*from ww w . j ava2 s. c om*/ // Gather headers. Map<String, String> headers = new HashMap<String, String>(); addCacheHeaders(headers, request.getCacheEntry()); httpResponse = mHttpStack.performRequest(request, headers); StatusLine statusLine = httpResponse.getStatusLine(); int statusCode = statusLine.getStatusCode(); responseHeaders = convertHeaders(httpResponse.getAllHeaders()); // Handle cache validation. if (statusCode == HttpStatus.SC_NOT_MODIFIED) { return new NetworkResponse(HttpStatus.SC_NOT_MODIFIED, request.getCacheEntry() == null ? null : request.getCacheEntry().data, responseHeaders.get("Etag"), HttpHeaderParser.parseCharset(responseHeaders), true, request.getExpireTime()); } // Some responses such as 204s do not have content. We must check. if (httpResponse.getEntity() != null) { responseContents = entityToBytes(httpResponse.getEntity()); // TODO add to ensure download correct add by fenglei // long realLength = responseContents.length; // long requireLength = httpResponse.getEntity().getContentLength(); // if(realLength != requireLength && requireLength != -1) { // Log.i("Error", "realLength = " + realLength + ", requireLength = " + requireLength); // } if (responseContents != null && httpResponse.getEntity().getContentLength() > 0 && responseContents.length != httpResponse.getEntity().getContentLength()) { attemptRetryOnException("socket", request, new VolleyError(Util.buildHttpErrorMsg("failed", -1, "ContentLength Error"))); continue; } } else { // Add 0 byte response as a way of honestly representing a // no-content request. responseContents = new byte[0]; } // if the request is slow, log it. long requestLifetime = SystemClock.elapsedRealtime() - requestStart; logSlowRequests(requestLifetime, request, responseContents, statusLine); // if (statusCode < 200 || statusCode > 299) { // throw new IOException(); // } if (request.isUpdateCookie()) { Header[] cookies = httpResponse.getHeaders("Set-Cookie"); int count = cookies.length; int i = 0; StringBuilder cookieBuilder = new StringBuilder(); for (Header cookie : cookies) { String cookieStr = cookie.getValue(); i++; if (!TextUtils.isEmpty(cookieStr) && cookieStr.length() > 10) { int end = cookieStr.indexOf(" "); if (i == count) { cookieStr = cookieStr.subSequence(0, end - 1).toString(); } else { cookieStr = cookieStr.subSequence(0, end).toString(); } cookieBuilder.append(cookieStr).append(" "); } } if (cookieBuilder.length() > 0) { cookieBuilder.deleteCharAt(cookieBuilder.length() - 1); } request.setUpdateCookie(cookieBuilder.toString()); } return new NetworkResponse(statusCode, responseContents, responseHeaders.get("Etag"), HttpHeaderParser.parseCharset(responseHeaders), false, request.getExpireTime()); } catch (SocketTimeoutException e) { attemptRetryOnException("socket", request, new VolleyError( Util.buildHttpErrorMsg("failed", -1, HttpRequestManager.STATE_ERROR_TIMEOUT))); } catch (ConnectTimeoutException e) { attemptRetryOnException("connection", request, new VolleyError( Util.buildHttpErrorMsg("failed", -1, HttpRequestManager.STATE_ERROR_TIMEOUT))); } catch (MalformedURLException e) { throw new VolleyError(Util.buildHttpErrorMsg("failed", -1, HttpRequestManager.STATE_ERROR_MALFORMED_URL_EXCEPTION)); // throw new RuntimeException("Bad URL " + request.getUrl(), e); } catch (IOException e) { attemptRetryOnException("io", request, new VolleyError(e)); // int statusCode = 0; // NetworkResponse networkResponse = null; // if (httpResponse != null) { // statusCode = httpResponse.getStatusLine().getStatusCode(); // } else { // throw new NoConnectionError(e); // } // VolleyLog.e("Unexpected response code %d for %s", statusCode, request.getUrl()); // if (responseContents != null) { // networkResponse = new NetworkResponse(statusCode, responseContents, // responseHeaders, false); // if (statusCode == HttpStatus.SC_UNAUTHORIZED || // statusCode == HttpStatus.SC_FORBIDDEN) { // attemptRetryOnException("auth", // request, new AuthFailureError(networkResponse)); // } else { // // TODO: Only throw ServerError for 5xx status codes. // throw new ServerError(networkResponse); // } // } else { // throw new NetworkError(networkResponse); // } } } }
From source file:com.krawler.workflow.module.dao.DataObjectOperationDAOImpl.java
private String buildUpdateQuery(String objName, String keyName, Map<String, Object> dataObject, Object[] args) { StringBuilder query = new StringBuilder("UPDATE "); query.append(getTableName(objName)); query.append(" set "); Set<Entry<String, Object>> entrySet = dataObject.entrySet(); if (!entrySet.isEmpty()) { int i = 0; for (Entry<String, Object> entry : entrySet) { if (keyName.equals(entry.getKey())) { args[args.length - 1] = entry.getValue(); continue; }/* w w w . j a v a2 s. c o m*/ query.append(entry.getKey()); { query.append("= ?,"); } args[i++] = entry.getValue(); } query.deleteCharAt(query.length() - 1); } query.append(" where "); query.append(keyName); query.append(" = ?"); return query.toString(); }
From source file:com.ebay.cloud.cms.metadata.mongo.MongoMetadataServiceImpl.java
@Override public void deleteMetaClass(String className, MetadataContext metaContext) { long start = System.currentTimeMillis(); try {// www . j a v a 2s.c o m metadataLock.lock(); MetaClass meta = repo.getMetadataService().getMetaClass(className); if (meta == null) { throw new MetaClassNotExistsException(repo.getRepositoryName(), className); } if (!meta.getFromReference().isEmpty() || !meta.getDescendants().isEmpty()) { StringBuilder sb = new StringBuilder(); for (MetaRelationship mr : meta.getFromReference()) { sb.append(mr.getSourceDataType()).append(","); } for (MetaClass mc : meta.getDescendants()) { sb.append(mc.getName()).append(","); } sb.deleteCharAt(sb.length() - 1); throw new MetaDataException(MetaErrCodeEnum.NONE_ORPHAN_META_CLASS, MessageFormat .format("MetaClass {0} is referenced by other meta class: {1}!", className, sb.toString())); } innerDeleteMetaClass(meta); addMetaHistory(meta, "deleteMetaClass", metaContext); long duration = System.currentTimeMillis() - start; metaContext.addDbTimeCost(duration); } catch (InterruptedException e) { logger.info("lock interrupted for deletaMetaClass {}", className); throw new MetaDataException(MetaErrCodeEnum.LOCK_INTERRUPTED, "lock interrupted for deleteMetaClass " + className, e); } finally { metadataLock.unlock(); } }
From source file:com.google.ie.business.service.impl.IdeaServiceImpl.java
/** * Formats the tag string submitted by application user for display on view. * //from w w w . j av a 2s . c om * @param tagString String having tags submitted by application user. * @return formated comma separate tags string. */ protected final String formatTagString(String tagString) { String[] tags = tagString.trim().split("[\\s,]"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < tags.length; i++) { String tmpString = tags[i].trim().toLowerCase(); if (!tmpString.equals("")) sb.append(tmpString + ","); if (i == tags.length - 1) sb.deleteCharAt(sb.length() - 1); } return sb.toString(); }
From source file:com.heliosapm.tsdblite.handlers.json.SplitTraceInputHandler.java
public String toHostObjectNameName(final ObjectName on) { final StringBuilder b = new StringBuilder("meta."); TreeMap<String, String> tgs = new TreeMap<String, String>(on.getKeyPropertyList()); final String metricName = on.getDomain(); String h = tgs.remove("host"); String a = tgs.remove("app"); final String host = h; //==null ? "*" : h; final String app = a == null ? "ANYAPP" : a; final int segIndex = metricName.indexOf('.'); final String seg = segIndex == -1 ? metricName : metricName.substring(0, segIndex); if (host != null) { b.append(host).append(".").append(seg).append(":"); }/*from w ww. j a va 2 s . co m*/ if (app != null) { tgs.put("app", app); // b.append(app).append(".").append(seg).append(":"); } // if(segIndex!=-1) { // tgs.put("app", metricName.substring(segIndex+1)); // } for (Map.Entry<String, String> entry : tgs.entrySet()) { b.append(entry.getKey()).append("=").append(entry.getValue()).append(","); } b.deleteCharAt(b.length() - 1); return b.toString(); }