List of usage examples for java.lang StringBuilder delete
@Override public StringBuilder delete(int start, int end)
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();// ww w. 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:my.grafos.ContactEditorUI.java
private void imprimeListaVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_imprimeListaVActionPerformed StringBuilder listaVertice = new StringBuilder(); listaVertice.append("Lista de Vrtices: {"); for (int q = 0; q < Fabrica.getTamanhoListaVertices(); q++) { vertice = Fabrica.listaVertices.get(q); listaVertice.append(vertice.getId() + ", "); System.out.println(vertice + vertice.getId() + vertice.isSubconjunto()); }/*from ww w . j a v a 2 s. c o m*/ listaVertice.delete((listaVertice.length() - 2), listaVertice.length()); listaVertice.append("}"); TextAreaUI.setText(listaVertice.toString()); }
From source file:com.virtusa.akura.common.controller.ManageSpecialEventsController.java
/** * Method is to return participant list. * // w ww. j a v a 2 s . c o m * @param specialEvents - SpecialEvents object * @param request - HttpServletRequest * @param modelMap - ModelMap attribute. * @return list of FaithLifeComment * @throws AkuraAppException - Detailed exception */ @ResponseBody @RequestMapping(value = "/findParticipentList.htm") public String populateParticipents(@ModelAttribute(MODEL_ATT_SPECIAL_EVENT) SpecialEvents specialEvents, ModelMap modelMap, HttpServletRequest request) throws AkuraAppException { StringBuilder allParticipents = new StringBuilder(); // int categoryId = specialEvents.getParticipantCategory().getParticipantCategoryId(); int categoryId = Integer.parseInt(request.getParameter("selectedValue")); if (categoryId == 1) { List<ClassGrade> classGradeList = SortUtil.sortClassGradeList(commonService.getClassGradeList()); boolean isFirst = true; StringBuilder classes = new StringBuilder(); for (ClassGrade cg : classGradeList) { classes.append(cg.getDescription()); classes.append("_"); classes.append(cg.getClassGradeId()); if (isFirst) { allParticipents.append(classes.toString()); // no comma isFirst = false; } else { allParticipents.append(","); // comma allParticipents.append(classes.toString()); } classes.delete(0, classes.length()); } } if (categoryId == 2) { List<SportCategory> sportCategoryList = SortUtil .sortSportCategoriesList(commonService.getSportCategoriesList()); boolean isFirst = true; StringBuilder sportCategories = new StringBuilder(); for (SportCategory sc : sportCategoryList) { sportCategories.append(sc.getSport().getDescription()); sportCategories.append("-"); sportCategories.append(sc.getSportSubCategory().getDescription()); sportCategories.append("_"); sportCategories.append(sc.getSportCategoryId()); if (isFirst) { allParticipents.append(sportCategories.toString()); // no comma isFirst = false; } else { allParticipents.append(","); // comma allParticipents.append(sportCategories.toString()); } sportCategories.delete(0, sportCategories.length()); } } if (categoryId == CATEGORY_TYPE_3) { List<ClubSociety> clubSocietyList = SortUtil.sortClubSocietyList(commonService.getClubsSocietiesList()); boolean isFirst = true; StringBuilder clubSocieties = new StringBuilder(); for (ClubSociety cs : clubSocietyList) { clubSocieties.append(cs.getName()); clubSocieties.append("_"); clubSocieties.append(cs.getClubSocietyId()); if (isFirst) { allParticipents.append(clubSocieties.toString()); // no comma isFirst = false; } else { allParticipents.append(","); // comma allParticipents.append(clubSocieties.toString()); } clubSocieties.delete(0, clubSocieties.length()); } } return allParticipents.toString(); }
From source file:my.grafos.ContactEditorUI.java
private void imprimeListaAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_imprimeListaAActionPerformed StringBuilder listaArestas = new StringBuilder(); listaArestas.append("Lista de Arestas: {"); for (int q = 0; q < Fabrica.getTamanhoListaArestas(); q++) { aresta = Fabrica.listaArestas.get(q); listaArestas.append(aresta.getId() + ", "); System.out.println(aresta + " " + aresta.getId() + " " + aresta.getOrigem().getId() + " " + aresta.getDestino().getId()); }/*from w ww.java 2 s . com*/ listaArestas.delete(listaArestas.length() - 2, listaArestas.length()); listaArestas.append("}"); TextAreaUI.setText(listaArestas.toString()); }
From source file:com.cloud.utils.db.SqlGenerator.java
public Pair<String, Attribute[]> buildRemoveSql() { Attribute attribute = findAttribute(GenericDao.REMOVED_COLUMN); if (attribute == null) { return null; }/*w w w . j a v a2 s.c om*/ StringBuilder sql = new StringBuilder("UPDATE "); sql.append(attribute.table).append(" SET "); sql.append(attribute.columnName).append(" = ? WHERE "); List<Attribute> ids = _ids.get(attribute.table); // if ids == null, that means the removed column was added as a JOIN // value to another table. We ignore it here. if (ids == null) { return null; } if (ids.size() == 0) { return null; } for (Attribute id : ids) { sql.append(id.table).append(".").append(id.columnName).append(" = ? AND "); } sql.delete(sql.length() - 5, sql.length()); Attribute[] attrs = ids.toArray(new Attribute[ids.size() + 1]); attrs[attrs.length - 1] = attribute; return new Pair<String, Attribute[]>(sql.toString(), attrs); }
From source file:net.rptools.maptool.client.functions.StrListFunctions.java
/** * MapTool call: <code>listInsert(list, index, target [,delim])</code> * //from w ww . jav a 2 s . c o m * @param index * A zero-based number from 0 to the list length (if equal to list length, <code>target</code> is * appended) * @param target * A string or number to insert * @param delim * An optional list delimiter (default ",") * @return A new list with <code>target</code> inserted before the item at position <code>index</code> */ public Object listInsert(List<Object> parameters, String listStr, String lastParam, List<String> list) throws ParameterException { Object retval = ""; String delim = ","; int minParams = 3; int maxParams = minParams + 1; checkVaryingParameters("listInsert()", minParams, maxParams, parameters, new Class[] { null, BigDecimal.class, null, String.class }); if (parameters.size() == maxParams) { delim = lastParam; } parse(listStr, list, delim); int index = ((BigDecimal) parameters.get(1)).intValue(); String target = parameters.get(2).toString().trim(); StringBuilder sb = new StringBuilder(); if (list.size() == 0) { if (index == 0) { retval = target; } } else { for (int i = 0; i < list.size() + 1; i++) { if (i == index) { sb.append(target); sb.append(delim); sb.append(" "); } if (i < list.size()) { sb.append(list.get(i)); sb.append(delim); sb.append(" "); } } sb.delete(sb.length() - 1 - delim.length(), sb.length()); // remove the trailing ", " retval = sb.toString(); } return retval; }
From source file:org.synyx.hades.dao.query.QueryCreator.java
/** * Constructs a query from the underlying {@link QueryMethod}. * /*from w w w. j av a 2 s.c om*/ * @return the query string * @throws QueryCreationException */ String constructQuery() { StringBuilder queryBuilder = new StringBuilder( getQueryString(READ_ALL_QUERY, getEntityName(method.getDomainClass()))); queryBuilder.append(" where "); PartSource source = new PartSource(method.getName()); // Split OR List<PartSource> orParts = source.getParts(OR); int parametersBound = 0; for (PartSource orPart : orParts) { // Split AND List<PartSource> andParts = orPart.getParts(AND); StringBuilder andBuilder = new StringBuilder(); for (PartSource andPart : andParts) { Parameters parameters = method.getParameters().getBindableParameters(); Parameter parameter = parameters.hasParameterAt(parametersBound) ? parameters.getParameter(parametersBound) : null; try { Part part = new Part(andPart.cleanedUp(), method, parameter); andBuilder.append(part.getQueryPart()).append(" and "); parametersBound += part.getNumberOfArguments(); } catch (ParameterOutOfBoundsException e) { throw QueryCreationException.create(method, e); } } andBuilder.delete(andBuilder.length() - 5, andBuilder.length()); queryBuilder.append(andBuilder); queryBuilder.append(" or "); } // Assert correct number of parameters if (!method.isCorrectNumberOfParameters(parametersBound)) { throw QueryCreationException.create(method, INVALID_PARAMETER_SIZE); } queryBuilder.delete(queryBuilder.length() - 4, queryBuilder.length()); if (source.hasOrderByClause()) { queryBuilder.append(" ").append(source.getOrderBySource().getClause()); } String query = queryBuilder.toString(); LOG.debug("Created query '{}' from method {}", query, method.getName()); return query; }
From source file:ch.iceage.icedms.persistence.jdbc.query.impl.DefaultDocumentQueries.java
@Override public String getAll(Document criteria, FetchType oneToMany, FetchType manyToOne) { StringBuilder sb = getSelectStatement("DOCUMENT", TABLE_ALIAS, oneToMany, manyToOne); sb.append(" WHERE "); if (criteria.getConfidential() != null) { sb.append(" CONFIDENTIAL =").append(criteria.getConfidential().equals(true) ? 1 : 0).append(" AND "); }// ww w . j a v a2 s.c o m if (criteria.getArchiveDate() != null) { sb.append(" ARCHIVE_DATE=").append(criteria.getArchiveDate()).append(" AND "); } if (criteria.getCurrentVersion() != null) { sb.append(" CURRENT_VERSION=").append(criteria.getCurrentVersion()).append(" AND "); } if (criteria.getDocumentType() != null) { sb.append(" DOCUMENT_TYPE_ID=").append(criteria.getDocumentType().getId()).append(" AND "); } if (criteria.getLanguage() != null) { sb.append(" LANGUAGE_ID=").append(criteria.getLanguage().getId()).append(" AND "); } if (criteria.getStatus() != null) { sb.append(" STATUS=").append(criteria.getStatus().ordinal()).append(" AND "); } if (criteria.getLastRevision() != null) { sb.append(" LAST_REVISION='").append(criteria.getLastRevision()).append("' AND "); } sb.delete(sb.length() - 4, sb.length()); return sb.toString(); }
From source file:gov.nih.nci.ncicb.tcga.dcc.common.dao.UUIDDAOImpl.java
/** * process the sequential union clause needed for the multiple barcode/uuid mapping query * * @param maxParameter max size of underlying list of arguments * @param name name of element to select, uuid or barcode here * @param caseSensitivity lowe, upper or normal * @return fully constructed query arguments *//*from www. j av a2 s . com*/ protected String processUnionClause(int maxParameter, final String name, final StringUtil.CaseSensitivity caseSensitivity) { final StringBuilder placeHolderString = new StringBuilder(); for (int i = 0; i < maxParameter; i++) { switch (caseSensitivity) { case CASE_SENSITIVE: placeHolderString.append("select ? as " + name + " from dual union "); break; case LOWER_CASE: placeHolderString.append("select lower(?) as " + name + " from dual union "); break; case UPPER_CASE: placeHolderString.append("select upper(?) as " + name + " from dual union "); break; } } placeHolderString.delete(placeHolderString.lastIndexOf(" union "), placeHolderString.length()); return placeHolderString.toString(); }
From source file:sapience.injectors.stax.inject.StringBasedStaxStreamInjector.java
/** * Helper method, taking a XML string like <ows:Metadata xmlns:ows=\"http://ogc.org/ows\" xmlns:xlink=\"http://wrc.org/xlink\" * xlink:href=\"http://dude.com\"></ows:Metadata> from the reference * and checks if /*from w ww .j av a 2 s . c om*/ * a the used prefixes match the globally used ones and * b) any of the declared namespaces are redundant * * The same is true for the XPath definition * * @param resultingXMLString * @param context */ private void processNamespace(StringBuilder sb, NamespaceContext global, LocalNamespaceContext local) { Matcher prefixMatcher = prefixPattern.matcher(sb); Matcher nsMatcher = nsPattern.matcher(sb); String prefix; String uri; /* process the local namespaces */ while (nsMatcher.find()) { int start = nsMatcher.start(); int end = nsMatcher.end(); StringBuilder sbu = new StringBuilder(sb.substring(start, end)); String thisPrefix = sbu.substring(sbu.indexOf(":") + 1, sbu.lastIndexOf("=")); String thisUri = sbu.substring(sbu.indexOf("\"") + 1, sbu.lastIndexOf("\"")); // add to local namespace context local.put(thisPrefix, thisUri); if ((prefix = global.getPrefix(thisUri)) != null) { // namespace is registered, let's remove it sb.delete(start - 1, end); // we have to reset, since we changed the state of the matched string with the deletion nsMatcher.reset(); } } /* change the prefixes */ try { while (prefixMatcher.find()) { int start = prefixMatcher.start(); int end = prefixMatcher.end(); String localprefix = sb.substring(start + 1, end - 1); if ((global.getNamespaceURI(localprefix) == null) && (uri = local.getNamespaceURI(localprefix)) != null) { // get the other prefix prefix = global.getPrefix(uri); if ((prefix != null) && (!(localprefix.contentEquals(prefix)))) { sb.replace(start + 1, end - 1, prefix); prefixMatcher.reset(); } } } } catch (StringIndexOutOfBoundsException e) { // we do nothing here } }