List of usage examples for java.lang StringBuffer deleteCharAt
@Override public synchronized StringBuffer deleteCharAt(int index)
From source file:org.wso2.carbon.appfactory.common.AppFactoryConfigurationBuilder.java
private String getKey(Stack<String> nameStack) { StringBuffer key = new StringBuffer(); for (int i = 0; i < nameStack.size(); i++) { String name = nameStack.elementAt(i); key.append(name).append("."); }// ww w .ja v a 2 s.co m key.deleteCharAt(key.lastIndexOf(".")); return key.toString(); }
From source file:padl.creator.javafile.eclipse.util.PadlParserUtil.java
/** * Get or create a ghost entity//w w w . j a v a 2 s . c o m * * @param isDealingWithExtend * @param anEntityTypeBinding * @param aPadlModel * @param aCurrentPackagePath * @return */ private static IFirstClassEntity getOrCreateGhostEntity(final boolean isDealingWithExtend, final ITypeBinding anEntityTypeBinding, final ICodeLevelModel aPadlModel, final String aCurrentPackagePath) { final StringBuffer tmpStringBuffer = new StringBuffer(); String ghostName = null; String ghostPackagePath = null; String fullyQualifiedName = null; final String entityBindingKey = anEntityTypeBinding.getKey(); final String prefix = "Recovered#currentType"; if (entityBindingKey.startsWith(prefix)) { // ghosts in existing entities tmpStringBuffer.append(entityBindingKey.substring(prefix.length())); tmpStringBuffer.deleteCharAt(tmpStringBuffer.length() - 1); // Yann 2015/03/16: Symbols collision with IConstants! // I make sure that the name of the entity does not contain // any symbol used in the models, see IConstants, because // the entityBindingKey will be of the form: // org.hibernate.envers.entities.mapper.relation.lazy.initializor.Initializor<List<U>>0<Ljava/util/List<Lorg/hibernate/envers/entities/mapper/relation/lazy/proxy/C:\Data\Java Programs\hibernate-orm-3.6.4.Final\hibernate-envers\src\main\java\org\hibernate\envers\entities\mapper\relation\lazy\proxy\ListProxy~ListProxy;:TU;>;> if (entityBindingKey.indexOf('/') > -1 || entityBindingKey.indexOf('\\') > -1) { ghostName = tmpStringBuffer.substring(0, tmpStringBuffer.indexOf("0")); } else { ghostName = tmpStringBuffer.toString(); } ghostPackagePath = anEntityTypeBinding.getPackage().getName(); } else if (isDealingWithExtend && entityBindingKey.startsWith("Recovered#typeBinding")) { ghostName = anEntityTypeBinding.getQualifiedName(); ghostPackagePath = anEntityTypeBinding.getPackage().getName(); } else { // Pure ghosts // Fix for eclipse_12-15-2009 (fixed) case of generic types // (templates) (fixed) final String[] packageComponents; if (anEntityTypeBinding.getPackage() == null) {// case of templates packageComponents = new String[0]; // should be deleted (only for debug purpose) /* * Output .getInstance() .normalOutput() .println( * "PadlParserUtil in getOrCreateGhostEntity anEntityTypeBinding.getPackage() == null " * + anEntityTypeBinding .getQualifiedName()); */ } else { packageComponents = anEntityTypeBinding.getPackage().getNameComponents(); } final int numberOfNames = packageComponents.length; char firstLetter; int i = 0; boolean checkPackage = true; if (numberOfNames > 0) { firstLetter = packageComponents[0].toCharArray()[0]; if (Character.isLowerCase(firstLetter)) { tmpStringBuffer.append(packageComponents[0]); i++; } else { checkPackage = false; } while (i < numberOfNames && checkPackage) { firstLetter = packageComponents[i].toCharArray()[0]; if (Character.isLowerCase(firstLetter)) { tmpStringBuffer.append('.'); tmpStringBuffer.append(packageComponents[i]); i++; } else { checkPackage = false; } } } ghostPackagePath = tmpStringBuffer.toString(); // why? aCurrentPackagePath=display path, is it more than the // package??? String packagePath = aCurrentPackagePath; if (aCurrentPackagePath.length() > 2) { /* * Output .getInstance() .normalOutput() .println( * "PadlParserUtil in getOrCreateGhostEntity aCurrentPackagePath.length() > 2 " * + aCurrentPackagePath.length()); */ packagePath = aCurrentPackagePath.substring(aCurrentPackagePath.indexOf('|') + 1).replace("|", "."); } // if package ghost is the same with the current package and this // ghost is not from source // this means generally that there is a probleme of resolving so we // put this ghost in a specific package // also when this ghost is a generic type, we do the same // These conditions are not always true but permit to handle a lot // of cases if ((ghostPackagePath.equals(packagePath) || ghostPackagePath.length() == 0 && ArrayUtils.isEquals(packagePath.toCharArray(), Constants.DEFAULT_PACKAGE_ID)) && !anEntityTypeBinding.isFromSource() || ghostPackagePath.length() == 0 && anEntityTypeBinding.isFromSource() && anEntityTypeBinding.isTypeVariable()) { ghostPackagePath = "unknown.ghost.packag"; } tmpStringBuffer.setLength(0); while (i < numberOfNames) { tmpStringBuffer.append(packageComponents[i]); tmpStringBuffer.append('.'); i++; } tmpStringBuffer.append(anEntityTypeBinding.getName()); ghostName = tmpStringBuffer.toString(); } tmpStringBuffer.setLength(0); tmpStringBuffer.append(ghostPackagePath); if (tmpStringBuffer.length() != 0) { tmpStringBuffer.append('.'); } tmpStringBuffer.append(ghostName); fullyQualifiedName = tmpStringBuffer.toString(); final int indexOfDot = ghostName.lastIndexOf('.'); if (indexOfDot < 0) { // Case of a ghost IFirstClassEntity ghost = aPadlModel.getTopLevelEntityFromID(fullyQualifiedName.toCharArray()); if (ghost == null) { ghost = PadlParserUtil.createGhost(aPadlModel, fullyQualifiedName.toCharArray()); } return ghost; } else { // case of a ghost member // get or create a ghost based on the package name and the ghostName final String searchedGhostID = PadlParserUtil.renameWith$(fullyQualifiedName, ghostPackagePath); StringTokenizer tokenizer; // int nbTokens = tokenizer.countTokens(); // number of entities in the // hierarchy=class>memberClass1>MemberClass2 tokenizer = new StringTokenizer(searchedGhostID, "$"); IPackage searchedPackage = null; IFirstClassEntity currentEntity = null; final String currentEntityID = tokenizer.nextToken(); searchedPackage = PadlParserUtil.getPackage(ghostPackagePath, aPadlModel); if (searchedPackage != null) { currentEntity = aPadlModel.getTopLevelEntityFromID(currentEntityID.toCharArray()); if (currentEntity == null) { currentEntity = PadlParserUtil.createGhost(aPadlModel, currentEntityID.toCharArray()); } } else { currentEntity = PadlParserUtil.createGhost(aPadlModel, currentEntityID.toCharArray()); } // create the member entities IFirstClassEntity currentMemberEntity; String currentMemberEntityID; String currentMemberEntityName; while (tokenizer.hasMoreTokens()) { currentMemberEntityName = tokenizer.nextToken(); currentMemberEntityID = currentEntity.getDisplayID() + '$' + currentMemberEntityName; currentMemberEntity = (IFirstClassEntity) currentEntity .getConstituentFromID(currentMemberEntityID.toCharArray()); if (currentMemberEntity == null) { currentMemberEntity = aPadlModel.getFactory().createMemberGhost( currentMemberEntityID.toCharArray(), currentMemberEntityName.toCharArray()); currentEntity.addConstituent((IConstituentOfEntity) currentMemberEntity); } currentEntity = currentMemberEntity; } // The last entity created or got in the padl model is which // is searched for return currentEntity; } }
From source file:org.squale.squalix.tools.mccabe.McCabeConfiguration.java
/** * Remplit la configuration avec les paramtres lis au projet. * // w ww . ja va 2s. c o m * @param pConfig configuration remplir. * @param pDatas la liste des paramtres du projet. * @throws ConfigurationException */ private static void setParameters(final McCabeConfiguration pConfig, final TaskData pDatas) throws ConfigurationException { // On modifie le classpath // Lorsqu'on rcupre les paramtres, si mClasspath n'est pas null // on remplace la valeur key.substition.classpath par mClasspath String classpath = "\"\""; if (null != pDatas.getData(TaskData.CLASSPATH)) { classpath = (String) pDatas.getData(TaskData.CLASSPATH); // On cre un classpath destin Unix, en s'assurant que chaque entre spcifie // existe, sinon elle est supprime de la liste StringBuffer sb = new StringBuffer(); StringTokenizer tok = new StringTokenizer(classpath, ";"); File f = null; while (tok.hasMoreTokens()) { f = new File(tok.nextToken()); if (f.exists()) { sb.append(f.getAbsolutePath()); // Les entres du Classpath doivent tre spars par des ":" pour Unix sb.append(File.pathSeparator); } } if (sb.length() > 0) { // S'il y a des valeurs dans le classpath, on sait // qu'un : a t ajout en trop sb.deleteCharAt(sb.length() - 1); } // On s'assure que la valeur du classpath est considre comme un seul paramtre classpath = "\"" + sb.toString() + "\""; } // String classPathPattern = McCabeMessages.getString("key.substition.classpath"); // On remplace le sourcepath par le premire reprtoire source ListParameterBO sources = (ListParameterBO) pConfig.getProject().getParameters().getParameters() .get(ParametersConstants.SOURCES); String firstProjectSourcePath = "." + File.separator; if ((null != sources) && (null != sources.getParameters()) && (!sources.getParameters().isEmpty())) { firstProjectSourcePath = ((StringParameterBO) sources.getParameters().get(0)).getValue(); } StringBuffer absProjectSourcePath = new StringBuffer(); absProjectSourcePath.append(pDatas.getData(TaskData.VIEW_PATH)); if (pDatas.getData(TaskData.SUP_PATH) != null) { String supPath = (String) pDatas.getData(TaskData.SUP_PATH); absProjectSourcePath.append(File.separator).append(supPath); firstProjectSourcePath = firstProjectSourcePath.replaceFirst(supPath, ""); } absProjectSourcePath.append(File.separator).append(firstProjectSourcePath); String replaceSourcePath = (String) pDatas.getData(TaskData.VIEW_PATH); File f2 = new File(absProjectSourcePath.toString()); if (f2.exists()) { replaceSourcePath = f2.getAbsolutePath(); } String sourceRootDirPattern = McCabeMessages.getString("key.substition.sourcerootdir"); for (int i = 0; i < pConfig.mParseParameters.length; i++) { if (pConfig.mParseParameters[i].equals(classPathPattern)) { pConfig.mParseParameters[i] = classpath; } else if (pConfig.mParseParameters[i].contains(sourceRootDirPattern)) { pConfig.mParseParameters[i] = pConfig.mParseParameters[i].replaceAll(sourceRootDirPattern, replaceSourcePath); } } }
From source file:org.duracloud.snapshot.service.impl.SpaceItemWriter.java
protected void writeContentProperties(ContentItem contentItem, Map<String, String> props, boolean lastItem) throws IOException { Set<String> propKeys = props.keySet(); StringBuffer sb = new StringBuffer(100); sb.append("{\n \"" + contentItem.getContentId() + "\": {\n"); for (String propKey : propKeys) { sb.append(" \"" + propKey + "\": \"" + props.get(propKey) + "\",\n"); }//from w ww. j a v a 2 s . c om sb.deleteCharAt(sb.length() - 2); // delete comma after last key/value pair sb.append(" }\n}"); if (!lastItem) { sb.append(","); } sb.append("\n"); synchronized (propsWriter) { propsWriter.write(sb.toString()); } }
From source file:org.overlord.rtgov.activity.server.rest.client.RESTActivityServer.java
/** * This method initializes the authentication properties on the supplied * URL connection./* ww w . j ava 2 s. co m*/ * * @param connection The connection */ protected void initAuth(HttpURLConnection connection) { String userPassword = _serverUsername + ":" + _serverPassword; String encoding = org.apache.commons.codec.binary.Base64.encodeBase64String(userPassword.getBytes()); StringBuffer buf = new StringBuffer(encoding); for (int i = 0; i < buf.length(); i++) { if (Character.isWhitespace(buf.charAt(i))) { buf.deleteCharAt(i); i--; } } connection.setRequestProperty("Authorization", "Basic " + buf.toString()); }
From source file:org.apache.usergrid.persistence.index.impl.EsProvider.java
/** * Create a node client//from w w w . j a v a 2s . c om * @return */ public Client createNodeClient() { // we will connect to ES on all configured hosts final String clusterName = indexFig.getClusterName(); final String nodeName = indexFig.getNodeName(); final int port = indexFig.getPort(); /** * Create our hosts */ final StringBuffer hosts = new StringBuffer(); for (String host : indexFig.getHosts().split(",")) { hosts.append(host).append(":").append(port).append(","); } //remove the last comma hosts.deleteCharAt(hosts.length() - 1); final String hostString = hosts.toString(); Settings settings = ImmutableSettings.settingsBuilder() .put("cluster.name", clusterName) // this assumes that we're using zen for host discovery. Putting an // explicit set of bootstrap hosts ensures we connect to a valid cluster. .put("discovery.zen.ping.unicast.hosts", hostString) .put("discovery.zen.ping.multicast.enabled", "false").put("http.enabled", false) .put("client.transport.ping_timeout", 2000) // milliseconds .put("client.transport.nodes_sampler_interval", 100).put("network.tcp.blocking", true) .put("node.client", true).put("node.name", nodeName) .build(); if (logger.isTraceEnabled()) { logger.trace("Creating ElasticSearch client with settings: {}", settings.getAsMap()); } Node node = NodeBuilder.nodeBuilder().settings(settings).client(true).data(false).node(); return node.client(); }
From source file:org.objectstyle.wolips.ruleeditor.model.RightHandSide.java
private String valueForObject(Object object) { if (object == null) { return null; }// w w w. ja v a 2 s.c o m if (object instanceof Collection) { Collection<Object> arrayOfValues = (Collection<Object>) object; if (arrayOfValues.size() == 0) { return "()"; } StringBuffer buffer = new StringBuffer(); buffer.append("( "); for (Object value : arrayOfValues) { buffer.append(valueForObject(value)); buffer.append(", "); } buffer.deleteCharAt(buffer.lastIndexOf(", ")); buffer.append(")"); return buffer.toString(); } if (object instanceof Map) { Map<Comparable, ?> mapOfValues = (Map<Comparable, ?>) object; StringBuffer buffer = new StringBuffer(); buffer.append("{ "); ArrayList<Comparable> list = new ArrayList<Comparable>(); list.addAll(mapOfValues.keySet()); Collections.sort(list); for (Object key : list) { buffer.append("\""); buffer.append(key); buffer.append("\" = "); buffer.append(valueForObject(mapOfValues.get(key))); buffer.append("; "); } buffer.append("}"); return buffer.toString(); } return "\"" + object.toString() + "\""; }
From source file:com.fsoft.bn.service.impl.BNJournalArticleLocalServiceImpl.java
@SuppressWarnings("unchecked") public List<News> getNewsInCategories(PortletRequest req, long groupId, String structureId, List<NewsCategory> lstNewsCate, int numberOfRecord, List<KeyValuePair> sortbys, Date fromDate, Date toDate) {//from ww w .ja v a2s .co m StringBuffer categoriesId = new StringBuffer(); for (NewsCategory newsCate : lstNewsCate) { categoriesId.append(newsCate.getId()); categoriesId.append(CommonConstants.COMMA); } if (!Validator.isBlankOrNull(categoriesId) && categoriesId.length() > 0) { categoriesId.deleteCharAt(categoriesId.length() - 1); } List<JournalArticle> news = BNJournalArticleFinderUtil.getNewsInCategories(groupId, structureId, String.valueOf(categoriesId), numberOfRecord, sortbys, fromDate, toDate); List<News> lstNews = new ArrayList<News>(); if (news.size() != 0) { lstNews = (List<News>) CollectionUtils.collect(news, new JournalArticle2NewsTransformer(req, structureId)); } return lstNews; }
From source file:org.apache.lucene.analysis.de.GermanStemmer.java
/** * Does some optimizations on the term. This optimisations are contextual. */// ww w .ja v a 2 s . c om private void optimize(StringBuffer buffer) { // Additional step for female plurals of professions and inhabitants. if (buffer.length() > 5 && buffer.substring(buffer.length() - 5, buffer.length()).equals("erin*")) { buffer.deleteCharAt(buffer.length() - 1); strip(buffer); } // Additional step for irregular plural nouns like "Matrizen -> Matrix". if (buffer.charAt(buffer.length() - 1) == ('z')) { buffer.setCharAt(buffer.length() - 1, 'x'); } }
From source file:indexer.DocVector.java
String getCoordinates() { StringBuffer buff = new StringBuffer("("); for (float x_i : x) { buff.append(x_i).append(","); }//from w w w . j a v a 2 s . c o m buff.deleteCharAt(buff.length() - 1); buff.append(")"); return buff.toString(); }