List of usage examples for java.lang StringBuffer delete
@Override public synchronized StringBuffer delete(int start, int end)
From source file:com.vmware.bdd.manager.ClusterManager.java
private List<String> validateGivenRp(List<String> specifiedRpNames) { List<String> exitsRps = new ArrayList<String>(); Set<String> allRps = clusterConfigMgr.getRpMgr().getAllRPNames(); StringBuffer nonexistentRpNames = new StringBuffer(); for (String rpName : specifiedRpNames) { if (!allRps.contains(rpName)) nonexistentRpNames.append(rpName).append(","); else/*from w ww .j av a 2 s. c o m*/ exitsRps.add(rpName); } if (nonexistentRpNames.length() > 0) { nonexistentRpNames.delete(nonexistentRpNames.length() - 1, nonexistentRpNames.length()); throw VcProviderException.RESOURCE_POOL_NOT_FOUND(nonexistentRpNames.toString()); } return exitsRps; }
From source file:org.csploit.android.services.UpdateService.java
/** * extract an archive into a directory//from w w w .j av a 2 s .c om * * @throws IOException if some I/O error occurs * @throws java.util.concurrent.CancellationException if task is cancelled by user * @throws java.lang.InterruptedException when the the running thread get cancelled. */ private void extract() throws RuntimeException, IOException, InterruptedException, ChildManager.ChildNotStartedException { ArchiveInputStream is = null; ArchiveEntry entry; CountingInputStream counter; OutputStream outputStream = null; File f, inFile; File[] list; String name; String envPath; final StringBuffer sb = new StringBuffer(); int mode; int count; long total; boolean isTar, r, w, x, isElf, isScript; short percentage, old_percentage; Child which; if (mCurrentTask.path == null || mCurrentTask.outputDir == null) return; mBuilder.setContentTitle(getString(R.string.extracting)).setContentText("").setContentInfo("") .setSmallIcon(android.R.drawable.ic_popup_sync).setProgress(100, 0, false); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); Logger.info(String.format("extracting '%s' to '%s'", mCurrentTask.path, mCurrentTask.outputDir)); envPath = null; which = null; try { if (mCurrentTask.fixShebang) { which = System.getTools().raw.async("which env", new Raw.RawReceiver() { @Override public void onNewLine(String line) { sb.delete(0, sb.length()); sb.append(line); } }); } inFile = new File(mCurrentTask.path); total = inFile.length(); counter = new CountingInputStream(new FileInputStream(inFile)); is = openArchiveStream(counter); isTar = mCurrentTask.archiver.equals(archiveAlgorithm.tar); old_percentage = -1; f = new File(mCurrentTask.outputDir); if (f.exists() && f.isDirectory() && (list = f.listFiles()) != null && list.length > 2) wipe(); if (mCurrentTask.fixShebang) { if (execShell(which, "cancelled while retrieving env path") != 0) { throw new RuntimeException("cannot find 'env' executable"); } envPath = sb.toString(); } while (mRunning && (entry = is.getNextEntry()) != null) { name = entry.getName().replaceFirst("^\\./?", ""); if (mCurrentTask.skipRoot) { if (name.contains("/")) name = name.substring(name.indexOf('/') + 1); else if (entry.isDirectory()) continue; } f = new File(mCurrentTask.outputDir, name); isElf = isScript = false; if (entry.isDirectory()) { if (!f.exists()) { if (!f.mkdirs()) { throw new IOException( String.format("Couldn't create directory '%s'.", f.getAbsolutePath())); } } } else { byte[] buffer = null; byte[] writeMe = null; outputStream = new FileOutputStream(f); // check il file is an ELF or a script if ((!isTar || mCurrentTask.fixShebang) && entry.getSize() > 4) { writeMe = buffer = new byte[4]; IOUtils.readFully(is, buffer); if (buffer[0] == 0x7F && buffer[1] == 0x45 && buffer[2] == 0x4C && buffer[3] == 0x46) { isElf = true; } else if (buffer[0] == '#' && buffer[1] == '!') { isScript = true; ByteArrayOutputStream firstLine = new ByteArrayOutputStream(); int newline = -1; // assume that '\n' is more far then 4 chars. firstLine.write(buffer); buffer = new byte[1024]; count = 0; while (mRunning && (count = is.read(buffer)) >= 0 && (newline = Arrays.binarySearch(buffer, 0, count, (byte) 0x0A)) < 0) { firstLine.write(buffer, 0, count); } if (!mRunning) { throw new CancellationException("cancelled while searching for newline."); } else if (count < 0) { newline = count = 0; } else if (newline < 0) { newline = count; } firstLine.write(buffer, 0, newline); firstLine.close(); byte[] newFirstLine = new String(firstLine.toByteArray()) .replace("/usr/bin/env", envPath).getBytes(); writeMe = new byte[newFirstLine.length + (count - newline)]; java.lang.System.arraycopy(newFirstLine, 0, writeMe, 0, newFirstLine.length); java.lang.System.arraycopy(buffer, newline, writeMe, newFirstLine.length, count - newline); } } if (writeMe != null) { outputStream.write(writeMe); } IOUtils.copy(is, outputStream); outputStream.close(); outputStream = null; percentage = (short) (((double) counter.getBytesRead() / total) * 100); if (percentage != old_percentage) { mBuilder.setProgress(100, percentage, false).setContentInfo(percentage + "%"); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); old_percentage = percentage; } } // Zip does not store file permissions. if (isTar) { mode = ((TarArchiveEntry) entry).getMode(); r = (mode & 0400) > 0; w = (mode & 0200) > 0; x = (mode & 0100) > 0; } else if (isElf || isScript) { r = w = x = true; } else { continue; } if (!f.setExecutable(x, true)) { Logger.warning(String.format("cannot set executable permission of '%s'", name)); } if (!f.setWritable(w, true)) { Logger.warning(String.format("cannot set writable permission of '%s'", name)); } if (!f.setReadable(r, true)) { Logger.warning(String.format("cannot set readable permission of '%s'", name)); } } if (!mRunning) throw new CancellationException("extraction cancelled."); Logger.info("extraction completed"); f = new File(mCurrentTask.outputDir, ".nomedia"); if (f.createNewFile()) Logger.info(".nomedia created"); mBuilder.setContentInfo("").setProgress(100, 100, true); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } finally { if (is != null) is.close(); if (outputStream != null) outputStream.close(); } }
From source file:com.gst.portfolio.group.service.CenterReadPlatformServiceImpl.java
private String getCenterExtraCriteria(final SearchParameters searchCriteria) { StringBuffer extraCriteria = new StringBuffer(200); extraCriteria.append(" and g.level_id = " + GroupTypes.CENTER.getId()); String sqlQueryCriteria = searchCriteria.getSqlSearch(); if (StringUtils.isNotBlank(sqlQueryCriteria)) { sqlQueryCriteria = sqlQueryCriteria.replaceAll(" display_name ", " g.display_name "); sqlQueryCriteria = sqlQueryCriteria.replaceAll("display_name ", "g.display_name "); extraCriteria.append(" and (").append(sqlQueryCriteria).append(") "); }/*w ww . ja v a2 s .c o m*/ final Long officeId = searchCriteria.getOfficeId(); if (officeId != null) { extraCriteria.append(" and g.office_id = ").append(officeId); } final String externalId = searchCriteria.getExternalId(); if (externalId != null) { extraCriteria.append(" and g.external_id = ").append(ApiParameterHelper.sqlEncodeString(externalId)); } final String name = searchCriteria.getName(); if (name != null) { extraCriteria.append(" and g.display_name like ") .append(ApiParameterHelper.sqlEncodeString(name + "%")); } final String hierarchy = searchCriteria.getHierarchy(); if (hierarchy != null) { extraCriteria.append(" and o.hierarchy like ") .append(ApiParameterHelper.sqlEncodeString(hierarchy + "%")); } if (StringUtils.isNotBlank(extraCriteria.toString())) { extraCriteria.delete(0, 4); } final Long staffId = searchCriteria.getStaffId(); if (staffId != null) { extraCriteria.append(" and g.staff_id = ").append(staffId); } return extraCriteria.toString(); }
From source file:it.cnr.icar.eric.server.profile.ws.wsdl.cataloger.WSDLCatalogerEngine.java
private String getCompleteRelativeFileName(String relativeFileName) { if (Utility.FILE_SEPARATOR.equalsIgnoreCase("\\")) { // Convert '/' to Windows file separator relativeFileName = relativeFileName.replaceAll("/", "\\\\"); }/*from w w w. j a v a2 s .c o m*/ String completeRelativeFileName = relativeFileName; // Check if this is a URL first try { new URL(relativeFileName); // This is a URL. Do not process return completeRelativeFileName; } catch (MalformedURLException ex) { // Not a URL. Continue processing } if (this.currentRelativeFilename != null) { // if relativeFileName starts with './' or '../' complete it: // Get directory of currently processed filename // Do directory update. For example: // topDir/dir1/file1.wsdl // topDir/dir2/file2.wsdl // file2.wsdl has import to ../dir1/file1.wsdl // Do following: // 1. Calculate directory of file doing the importing // In this example, file2.wsdl does import, its dir is: /topDir/dir2/ // 2. Append relative import to file1.wsdl to file2.wsdl's directory: // topDir/dir2/../dir1/file1.wsdl // 3. Resolve relative path to file1.wsdl // Replace the '../' and the directory above it. // topDir/dir2/../dir1/file1.wsdl -> topDir/dir1/file1.wsdl // Note, the algorithm will handle any number of '../' in the path int index = currentRelativeFilename.lastIndexOf(Utility.FILE_SEPARATOR); String currentRelativeDir = ""; if (index != -1) { currentRelativeDir = currentRelativeFilename.substring(0, index + 1); } String relativeDir = ""; int index2 = relativeFileName.lastIndexOf(Utility.FILE_SEPARATOR); if (index2 != -1) { relativeDir = relativeFileName.substring(0, index2 + 1); } if (!currentRelativeDir.equalsIgnoreCase(relativeDir)) { // In other words, if you do not have the same directory path to // both files, continue below String fullRelativePath = currentRelativeDir + relativeFileName; String[] dirs = null; if (Utility.FILE_SEPARATOR.equalsIgnoreCase("\\")) { // Handle Windows dir separator dirs = fullRelativePath.split("\\\\"); } else { dirs = fullRelativePath.split(Utility.FILE_SEPARATOR); } StringBuffer completeRelativePath = new StringBuffer(); for (int i = 0; i < dirs.length; i++) { int completeRelativePathLength = completeRelativePath.length(); if (dirs[i].equalsIgnoreCase("..")) { // delete the previously appended dir if (i > 0) { if (completeRelativePathLength > 0) { int lastDirIndex = completeRelativePath.lastIndexOf(Utility.FILE_SEPARATOR); if (lastDirIndex == -1) { lastDirIndex = 0; } completeRelativePath = completeRelativePath.delete(lastDirIndex, completeRelativePathLength); } } } else if (i < dirs.length - 1 && dirs[i].equalsIgnoreCase(".")) { continue; } else { if (i > 0 && completeRelativePathLength > 0) { completeRelativePath.append(Utility.FILE_SEPARATOR); } completeRelativePath.append(dirs[i]); } } completeRelativeFileName = completeRelativePath.toString(); } } return completeRelativeFileName; }
From source file:dao.DirectoryAbstractDao.java
/** * checks if this user is an organizer/moderator * @param collabrumId the id of the collabrum * @param userLogin the login/* w w w . jav a 2s .com*/ * @param userId the userId * @return boolean * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public boolean isOrganizer(String collabrumId, String userLogin, String userId) { if (RegexStrUtil.isNull(collabrumId) || RegexStrUtil.isNull(userId)) { throw new BaseDaoException("params are null"); } /** Jboss methods * fqn - full qualified name * check if the organizer already set in the cache * If it exists, return the organizer from the cache. */ Fqn fqn = cacheUtil.fqn(DbConstants.ORGANIZER); StringBuffer sb = new StringBuffer(collabrumId); sb.append("-"); sb.append(userId); String key = sb.toString(); Object obj = treeCache.get(fqn, key); if (obj != null) { if (((Member) obj).getValue(DbConstants.IS_ORGANIZER) != null) { return ((Member) obj).getValue(DbConstants.IS_ORGANIZER).equals("1"); } } /** * if admin, return organizer as true */ if (!RegexStrUtil.isNull(userLogin)) { if (diaryAdmin.isDiaryAdmin(userLogin)) { Member organizer = (Member) eop.newObject(DbConstants.MEMBER); if (organizer != null) { organizer.setValue(DbConstants.IS_ORGANIZER, "1"); treeCache.put(fqn, key, organizer); return true; } else { throw new BaseDaoException("could not allocate eop member"); } } } /** * Get scalability datasource, colladmin is not partitioned */ String sourceName = scalabilityManager.getReadZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { sb.delete(0, sb.length()); sb.append("ds is null for isOrganizer() in collabrumDaoDb "); sb.append(sourceName); sb.append("collabrumId = "); sb.append(collabrumId); sb.append(" userId "); sb.append(userId); throw new BaseDaoException(sb.toString()); } /** * check if this admin exists for this collabrum **/ List result = null; try { Object[] params = { (Object) collabrumId, (Object) userId }; result = adminExistsQuery.execute(params); } catch (Exception e) { sb.delete(0, sb.length()); sb.append("exception error in adminExistsQuery , "); sb.append(adminExistsQuery.getSql()); sb.append(" collabrumId = "); sb.append(collabrumId); sb.append(" userId = "); sb.append(userId); throw new BaseDaoException(sb.toString(), e); } if ((result != null) && (result.size() > 0)) { Member organizer = (Member) eop.newObject(DbConstants.MEMBER); organizer.setValue(DbConstants.IS_ORGANIZER, "1"); treeCache.put(fqn, key, organizer); return true; } return false; }
From source file:org.wso2.carbon.bpel.core.ode.integration.jmx.Instance.java
@Override public String[] getInstanceInfoFromInstanceId() { StringBuffer buffer = new StringBuffer(); PaginatedInstanceList paginatedInstanceList; String instanceInfoArray[] = null; int arrayCount = 0; try {/*from w w w . j ava2s . c o m*/ paginatedInstanceList = getPaginatedInstanceList(" ", "-last-active", 200, 0); LimitedInstanceInfoType[] instanceArray = paginatedInstanceList.getInstance(); instanceInfoArray = new String[instanceArray.length]; for (LimitedInstanceInfoType instance : instanceArray) { buffer.append("Instance id=" + instance.getIid()); buffer.append(" "); buffer.append("Process id=" + instance.getPid()); buffer.append(" "); buffer.append("Status =" + instance.getStatus()); buffer.append(" "); buffer.append("Started Date=" + instance.getDateStarted().get(5)); buffer.append("-" + instance.getDateStarted().get(2)); buffer.append("-" + instance.getDateStarted().get(1)); buffer.append(" "); buffer.append(instance.getDateStarted().get(11)); buffer.append(":" + instance.getDateStarted().get(12)); buffer.append(":" + instance.getDateStarted().get(13)); buffer.append(" "); buffer.append("Date Last Activate=" + instance.getDateLastActive().get(5)); buffer.append("-" + instance.getDateLastActive().get(2)); buffer.append("-" + instance.getDateLastActive().get(1)); buffer.append(" "); buffer.append(instance.getDateLastActive().get(11)); buffer.append(":" + instance.getDateLastActive().get(12)); buffer.append(":" + instance.getDateLastActive().get(13)); buffer.append(" "); instanceInfoArray[arrayCount] = buffer.toString(); arrayCount++; buffer.delete(0, buffer.length()); } } catch (InstanceManagementException e) { String errMsg = "failed to get instance information from instance id"; log.error(errMsg, e); } return instanceInfoArray; }
From source file:de.tarent.maven.plugins.pkg.helper.Helper.java
protected final String createPackageLine(List<String> packageDescriptors) { if (packageDescriptors == null || packageDescriptors.isEmpty()) { return null; }/* ww w . j av a 2s .c o m*/ StringBuffer packageLine = new StringBuffer(); Iterator<String> ite = packageDescriptors.iterator(); while (ite.hasNext()) { String packageDescriptor = ite.next(); packageLine.append(packageDescriptor); packageLine.append(", "); } // Remove last ", " if (packageLine.length() >= 2) { packageLine.delete(packageLine.length() - 2, packageLine.length()); } return packageLine.toString(); }
From source file:org.siberia.image.searcher.impl.GoogleImageSearcher.java
/** search */ public void search() { // http://images.google.fr/images?imgsz=xxlarge&gbv=2&hl=fr&q=b+e&btnG=Recherche+d%27images // http://images.google.fr/images?imgsz=xxlarge&hl=fr&q=b+e Runnable run = new Runnable() { public void run() { fireSearchHasBegan(new ImageSearcherEvent(GoogleImageSearcher.this)); StringBuffer buffer = new StringBuffer(50); if (getCriterions() != null) { boolean oneTokenAlreadyApplied = false; for (int i = 0; i < getCriterions().length; i++) { String current = getCriterions()[i]; if (current != null) { if (oneTokenAlreadyApplied) { buffer.append("+"); }/*w w w. j av a 2s .c om*/ buffer.append(current); oneTokenAlreadyApplied = true; } } } Locale locale = getLocale(); if (locale == null) { locale = Locale.getDefault(); } if (logger.isDebugEnabled()) { logger.debug("uri : " + buffer.toString()); } HttpClient client = new HttpClient(); HttpMethod method = new GetMethod(GOOGLE_URL); NameValuePair[] pairs = new NameValuePair[3]; pairs[0] = new NameValuePair("imgsz", convertImageSizeCriterion(getImageSize())); pairs[1] = new NameValuePair("hl", locale.getCountry().toLowerCase()); pairs[2] = new NameValuePair("q", buffer.toString()); method.setQueryString(pairs); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); InputStream stream = null; try { // Execute the method. int statusCode = client.executeMethod(method); if (statusCode == HttpStatus.SC_OK) { /** on recherche partir des motifs suivants * la premire occurrence de http:// partir de l, on prend jusqu'au prochaine espace ou '>' : * * exemple : * <img src=http://tbn0.google.com/images?q=tbn:GIJo-j_dSy4FiM:http://www.discogs.com/image/R-378796-1136999170.jpeg width=135 height=135> * * on trouve le motif, puis, on prend partir de http://www.discogs jusqu'au prochain espace... * * --> http://www.discogs.com/image/R-378796-1136999170.jpeg */ String searchMotif = "<img src=http://tbn0.google.com/images?q"; String urlMotif = "http://"; int indexInSearchMotif = -1; int indexInUrlMotif = -1; boolean motifFound = false; boolean foundUrl = false; StringBuffer urlBuffer = new StringBuffer(50); // Read the response body. byte[] bytes = new byte[1024 * 8]; stream = method.getResponseBodyAsStream(); if (stream != null) { int read = -1; int linksRetrieved = 0; while ((read = stream.read(bytes)) != -1) { for (int i = 0; i < read; i++) { byte currentByte = bytes[i]; if (motifFound) { if (foundUrl) { if (currentByte == ' ' || currentByte == '>') { /* add current url to list of result */ try { URL url = new URL(urlBuffer.toString()); fireImageFound(new ImageFoundEvent(GoogleImageSearcher.this, url, linksRetrieved)); linksRetrieved++; if (linksRetrieved >= getMaximumLinksRetrieved()) { break; } } catch (Exception e) { e.printStackTrace(); } finally { urlBuffer.delete(0, urlBuffer.length()); foundUrl = false; motifFound = false; } } else { /* add current byte to url buffer */ urlBuffer.append((char) currentByte); } } else { if (indexInUrlMotif == urlMotif.length() - 1) { urlBuffer.append(urlMotif); urlBuffer.append((char) currentByte); foundUrl = true; indexInUrlMotif = -1; } /* if the current byte is the same as that attempted on the url motif let's continue */ if (((char) currentByte) == urlMotif.charAt(indexInUrlMotif + 1)) { indexInUrlMotif++; } else { indexInUrlMotif = -1; } } } else { if (indexInSearchMotif == searchMotif.length() - 1) { motifFound = true; indexInSearchMotif = -1; } if (((char) currentByte) == searchMotif.charAt(indexInSearchMotif + 1)) { indexInSearchMotif++; } else { indexInSearchMotif = -1; } } } if (linksRetrieved >= getMaximumLinksRetrieved()) { break; } } } } else { System.err.println("Method failed: " + method.getStatusLine()); } } catch (HttpException e) { System.err.println("Fatal protocol violation: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { if (stream != null) { try { stream.close(); } catch (IOException ex) { System.err.println("Fatal transport error: " + ex.getMessage()); } } System.err.println("Fatal transport error: " + e.getMessage()); e.printStackTrace(); } finally { // Release the connection. method.releaseConnection(); fireSearchFinished(new ImageSearcherEvent(GoogleImageSearcher.this)); } } }; this.service.submit(run); }
From source file:my.home.model.datasource.AutoCompleteItemDataSourceImpl.java
@Override public void getAutoCompleteItems(Context context, String currentInput) { if (!mLoadSuccess) { BusProvider.getRestBusInstance().post(new MGetAutoCompleteItemEvent(new ArrayList())); return;// ww w . j a v a2 s . c o m } boolean in_msg_or_time_ind_state = false; boolean in_msg_or_time_state = false; boolean in_if_state = false; boolean in_if_then_state = false; boolean in_while_state = false; String leftString = ""; String lastString = ""; String lastPreMsg = ""; String lastState = ""; StringBuffer cmdBuffer = new StringBuffer(); StringBuffer inputBuffer = new StringBuffer(currentInput); String curState = mInitState; while (inputBuffer.length() > 0) { if (in_msg_or_time_ind_state) { if (inputBuffer.toString().startsWith(mMessageSeq) || inputBuffer.toString().startsWith(mTimeSeq)) { in_msg_or_time_ind_state = false; } cmdBuffer.append(inputBuffer.charAt(0)); inputBuffer.deleteCharAt(0); continue; } boolean found = false; String tempInput = inputBuffer.toString(); if (!mLinks.containsKey(curState)) { BusProvider.getRestBusInstance().post(new MGetAutoCompleteItemEvent(new ArrayList())); return; } for (String nextState : mLinks.get(curState)) { if (!in_if_state && !in_while_state) { if (nextState.equals("then") || nextState.equals("compare") || nextState.equals("logical")) continue; } if (!in_if_then_state) { if (nextState.equals("else")) continue; } for (String val : mNodes.get(nextState)) { if (tempInput.startsWith(val)) { leftString = inputBuffer.toString(); lastState = nextState; inputBuffer.delete(0, val.length()); cmdBuffer.append(val); found = true; in_msg_or_time_state = false; if (nextState.equals("message") || nextState.equals("time")) { in_msg_or_time_ind_state = true; lastPreMsg = lastString; } else if (nextState.equals("if")) { in_if_state = true; } else if (nextState.equals("while")) { in_while_state = true; } else if (nextState.equals("then")) { if (in_if_state) in_if_then_state = true; in_if_state = false; in_while_state = false; } else if (in_if_then_state && nextState.equals("else")) { in_if_then_state = false; } lastString = val; curState = nextState; break; } else if (nextState.equals("message") && val.startsWith(tempInput)) { lastState = nextState; } } if (inputBuffer.length() == 0) break; } if (inputBuffer.length() == 0) break; if (found) continue; if (curState.equals("message") || mLinks.get(curState).contains("message")) { in_msg_or_time_state = true; found = true; curState = "message"; cmdBuffer.append(inputBuffer.charAt(0)); inputBuffer.deleteCharAt(0); } else if (curState.equals("time") || mLinks.get(curState).contains("time")) { in_msg_or_time_state = true; found = true; curState = "time"; cmdBuffer.append(inputBuffer.charAt(0)); inputBuffer.deleteCharAt(0); } if (!found) break; } String cmdString = cmdBuffer.toString(); Set<AutoCompleteItem> resultSet = new HashSet<>(); if (in_msg_or_time_ind_state) { String cmd = cmdString + mMessageSeq; if (curState.equals("time")) { addTimeToolItemToResult(resultSet); addDateToolItemToResult(resultSet); } // 1 addFavorToolItemToResult(resultSet); // 2 addMsgHistoryItemToResult(resultSet, context, cmdString, lastPreMsg, curState); // 3 resultSet.add(new AutoCompleteItem(curState, 1.0f, mMessageSeq, cmd)); } else if (inputBuffer.length() == 0) { ArrayList<AutoCompleteItem> unweightItems = new ArrayList<>(); String tempLeft = new StringBuilder(leftString).delete(0, lastString.length()).toString(); if (tempLeft.length() != 0) { if (curState.equals("message") || curState.equals("time")) { for (String nextState : mLinks.get(lastState)) { for (String val : mNodes.get(nextState)) { if (val.startsWith(tempLeft)) { String tempCmd = new StringBuilder(val).delete(0, tempLeft.length()).toString(); String cmd = cmdString + tempCmd; // resultSet.add(new AutoCompleteItem(nextState, Float.MAX_VALUE, val, cmd)); unweightItems.add( new AutoCompleteItem(nextState, DEFAULT_AUTOCOMPLETE_WEIGHT, val, cmd)); } } } } else { for (String val : mNodes.get(curState)) { if (val.startsWith(tempLeft) && !val.equals(tempLeft)) { String tempCmd = new StringBuilder(val).delete(0, lastString.length()).toString(); String cmd = cmdString + tempCmd; // resultSet.add(new AutoCompleteItem(curState, Float.MAX_VALUE, val, cmd)); unweightItems .add(new AutoCompleteItem(curState, DEFAULT_AUTOCOMPLETE_WEIGHT, val, cmd)); } } } } else if (leftString.equals(lastString)) { for (String val : mNodes.get(curState)) { if (val.startsWith(leftString) && val.length() != leftString.length()) { String tempCmd = new StringBuilder(val).delete(0, lastString.length()).toString(); String cmd = cmdString + tempCmd; // resultSet.add(new AutoCompleteItem(curState, DEFAULT_AUTOCOMPLETE_WEIGHT, val, cmd)); unweightItems.add(new AutoCompleteItem(curState, DEFAULT_AUTOCOMPLETE_WEIGHT, val, cmd)); } } } if (in_msg_or_time_state) { addTimeToolItemToResult(resultSet); addDateToolItemToResult(resultSet); addFavorToolItemToResult(resultSet); } for (String nextState : mLinks.get(curState)) { if (nextState.equals("then")) { if (in_if_state || in_while_state) { for (String val : mNodes.get(nextState)) { String cmd = cmdString + val; resultSet.add(new AutoCompleteItem(nextState, 1.0f, val, cmd)); } } } else if (nextState.equals("else")) { if (in_if_then_state) { for (String val : mNodes.get(nextState)) { String cmd = cmdString + val; resultSet.add(new AutoCompleteItem(nextState, 1.0f, val, cmd)); } } } else { if (nextState.equals("compare") || nextState.equals("logical")) if (!in_if_state && !in_while_state) continue; if (nextState.equals("message") || nextState.equals("time")) { addTimeToolItemToResult(resultSet); addDateToolItemToResult(resultSet); addFavorToolItemToResult(resultSet); } for (String val : mNodes.get(nextState)) { String cmd = cmdString + val; unweightItems.add(new AutoCompleteItem(nextState, DEFAULT_AUTOCOMPLETE_WEIGHT, val, cmd)); } } } if (unweightItems.size() != 0) { setItemWeight(context, unweightItems, lastString); resultSet.addAll(unweightItems); } } else { String tempInput = inputBuffer.toString(); ArrayList<AutoCompleteItem> unweightItems = new ArrayList<>(); if (tempInput.length() != 0) { for (String nextState : mLinks.get(curState)) { for (String val : mNodes.get(nextState)) { if (val.startsWith(tempInput)) { String cmd = cmdString + val; unweightItems .add(new AutoCompleteItem(nextState, DEFAULT_AUTOCOMPLETE_WEIGHT, val, cmd)); } } } } if (unweightItems.size() != 0) { setItemWeight(context, unweightItems, tempInput); resultSet.addAll(unweightItems); } } List<AutoCompleteItem> resultList = new ArrayList<>(resultSet); Collections.sort(resultList, mResultComparator); BusProvider.getRestBusInstance().post(new MGetAutoCompleteItemEvent(resultList)); }
From source file:com.vmware.bdd.manager.ClusterManager.java
/** * Get the vCenter clusters to be used by the cluster *//*from ww w . ja va 2 s . c om*/ private List<VcCluster> getVcClustersToBeUsed(List<String> rpNames) { List<VcCluster> clusters = null; if (rpNames == null || rpNames.isEmpty()) { clusters = clusterConfigMgr.getRpMgr().getAllVcResourcePool(); } else { clusters = new ArrayList<VcCluster>(); StringBuffer nonexistentRpNames = new StringBuffer(); for (String rpName : rpNames) { List<VcCluster> vcClusters = clusterConfigMgr.getRpMgr().getVcResourcePoolByName(rpName); if (vcClusters == null) { nonexistentRpNames.append(rpName).append(","); } else { clusters.addAll(vcClusters); } } if (nonexistentRpNames.length() > 0) { nonexistentRpNames.delete(nonexistentRpNames.length() - 1, nonexistentRpNames.length()); throw VcProviderException.RESOURCE_POOL_NOT_FOUND(nonexistentRpNames.toString()); } } return clusters; }