List of usage examples for java.lang StringBuffer deleteCharAt
@Override public synchronized StringBuffer deleteCharAt(int index)
From source file:chibi.gemmaanalysis.GeneExpressionWriterCLI.java
@Override protected Exception doWork(String[] args) { StopWatch timer = new StopWatch(); timer.start();//from w ww.ja v a2 s . co m String HEADER = "HEADER"; processCommandLine(args); Collection<Gene> genes; try { genes = getQueryGenes(); } catch (IOException e) { return e; } StringBuffer sb = new StringBuffer(); for (Gene gene : genes) { sb.append(gene.toString()); sb.append(", "); } log.info(genes.size() + " genes: " + sb.toString()); sb = new StringBuffer(); for (BioAssaySet bas : this.expressionExperiments) { sb.append(bas.toString()); sb.append(", "); } log.info(this.expressionExperiments.size() + " experiments: " + sb.toString()); Map<Object, StringBuffer> outBuffs = new HashMap<>(); String fileName = outFilePrefix + ".txt"; log.info("Output filename " + fileName); for (BioAssaySet bas : this.expressionExperiments) { ExpressionExperiment ee = (ExpressionExperiment) bas; Collection<ArrayDesign> ads = eeService.getArrayDesignsUsed(ee); Collection<CompositeSequence> css = new HashSet<CompositeSequence>(); for (ArrayDesign ad : ads) { css.addAll(adService.getCompositeSequences(ad)); } log.info("===================================="); log.info("Experiment " + ee + "; Array Design " + ads + "; Composite sequences " + css.size()); Map<Gene, Collection<CompositeSequence>> gene2css = getGene2CsMap(css); // ExpressionDataDoubleMatrix dataMatrix = expressionDataMatrixService.getFilteredMatrix( ee, filterConfig // ); ExpressionDataDoubleMatrix dataMatrix = expressionDataMatrixService .getProcessedExpressionDataMatrix(ee); // store values inside a buffer if (!outBuffs.containsKey(HEADER)) { StringBuffer hb = new StringBuffer(); hb.append("Gene\tProbe\tID"); outBuffs.put(HEADER, hb); } for (BioMaterial bm : dataMatrix.getMatrix().getColNames()) { // bm.getFactorValues() // bm.getCharacteristics() // outBuffs.get( HEADER ) // .append( // "\t" + bm.getName() + "." // + StringUtils.collectionToDelimitedString( bm.getFactorValues(), "," ) ); outBuffs.get(HEADER) .append("\t" + ee.getShortName() + "." + bm.getName() + "." + StringUtils.collectionToDelimitedString(bm.getCharacteristics(), ",") + "." + StringUtils.collectionToDelimitedString(bm.getFactorValues(), ",")); } for (Gene gene : genes) { log.debug(" Getting component sequence for gene " + gene); Collection<CompositeSequence> c = gene2css.get(gene); if (c == null) { log.error("No composite sequences found for gene " + gene); continue; } for (CompositeSequence cs : c) { Double[] row = dataMatrix.getRow(cs); if (row == null) { log.error("Cannot get data from data matrix for " + gene.getOfficialSymbol() + " (" + cs.getName() + ")"); // continue; row = new Double[dataMatrix.getMatrix().columns()]; } if (!outBuffs.containsKey(cs)) { StringBuffer gb = new StringBuffer(); gb.append(gene.getOfficialSymbol() + "\t" + cs.getName() + "\t" + cs.getId()); outBuffs.put(cs, gb); } StringBuffer buf = new StringBuffer(); for (Double d : row) { if (d == null) buf.append("NA"); else buf.append(d); buf.append("\t"); } buf.deleteCharAt(buf.length() - 1); outBuffs.get(cs).append("\t" + buf.toString()); } } } // Output to file try (PrintWriter out = new PrintWriter(new FileWriter(fileName));) { out.println(outBuffs.get(HEADER)); for (Object key : outBuffs.keySet()) { if (key.equals(HEADER)) { continue; } out.println(outBuffs.get(key)); } } catch (IOException e) { return e; } log.info("Done. Wrote " + genes.size() + " genes and " + (outBuffs.keySet().size() - 1) + " composite sequences in " + this.expressionExperiments.size() + " experiments which took " + timer.getTime() + " ms. Output file " + fileName); return null; }
From source file:org.talend.dataquality.record.linkage.ui.section.BlockingKeySection.java
/** * if overwrite: need to delete all current keyss, and insert the keys according to the parameter:matchRule; else: * only add the keys in the parameter matchrule, to the current keys. * /* w w w. j a va 2 s.c o m*/ * @param matchRule * @param overwrite */ public void importMatchRule(MatchRuleDefinition matchRule, boolean overwrite) { if (overwrite) { // clear current keys this.removeAllBlockingKey(); } List<String> conflictKeys = new ArrayList<String>(); for (BlockKeyDefinition blockKey : matchRule.getBlockKeys()) { if (!overwrite && isKeyDefinitionAdded(blockKey.getName())) { // if conflict with current ones, do not import conflictKeys.add(blockKey.getName()); continue; } BlockKeyDefinition blockKeyDefinition = EcoreUtil.copy(blockKey); setColumnValueIfMatch(blockKeyDefinition); tableComposite.addKeyDefinition(blockKeyDefinition, this.getMatchRuleDefinition().getBlockKeys()); } // if there are some conflict keys, popup to let the user know if (conflictKeys.size() > 0) { StringBuffer names = new StringBuffer(); for (String name : conflictKeys) { names.append(name); names.append(PluginConstant.COMMA_STRING); } if (names.length() > 0) { names.deleteCharAt(names.lastIndexOf(PluginConstant.COMMA_STRING)); } MessageDialog.openWarning(null, DefaultMessagesImpl.getString("BlockingKeySection.conflictImport"), //$NON-NLS-1$ DefaultMessagesImpl.getString("BlockingKeySection.conflictImportKeys") + names.toString()); //$NON-NLS-1$ } }
From source file:net.sourceforge.eclipsetrader.yahoo.Feed.java
private void update() { // Builds the url for quotes download String host = "quote.yahoo.com"; //$NON-NLS-1$ StringBuffer url = new StringBuffer("http://" + host + "/download/javasoft.beans?symbols="); //$NON-NLS-1$ //$NON-NLS-2$ for (Iterator iter = map.values().iterator(); iter.hasNext();) url = url.append((String) iter.next() + "+"); //$NON-NLS-1$ if (url.charAt(url.length() - 1) == '+') url.deleteCharAt(url.length() - 1); url.append("&format=sl1d1t1c1ohgvbap"); //$NON-NLS-1$ log.debug(url.toString());// w w w . j av a 2 s .com // Read the last prices String line = ""; //$NON-NLS-1$ try { HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); BundleContext context = YahooPlugin.getDefault().getBundle().getBundleContext(); ServiceReference reference = context.getServiceReference(IProxyService.class.getName()); if (reference != null) { IProxyService proxy = (IProxyService) context.getService(reference); IProxyData data = proxy.getProxyDataForHost(host, IProxyData.HTTP_PROXY_TYPE); if (data != null) { if (data.getHost() != null) client.getHostConfiguration().setProxy(data.getHost(), data.getPort()); if (data.isRequiresAuthentication()) client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(data.getUserId(), data.getPassword())); } } HttpMethod method = new GetMethod(url.toString()); method.setFollowRedirects(true); client.executeMethod(method); BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); while ((line = in.readLine()) != null) { String[] item = line.split(","); //$NON-NLS-1$ if (line.indexOf(";") != -1) //$NON-NLS-1$ item = line.split(";"); //$NON-NLS-1$ Double open = null, high = null, low = null, close = null; Quote quote = new Quote(); // 2 = Date // 3 = Time try { GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone("EST"), Locale.US); //$NON-NLS-1$ usDateTimeParser.setTimeZone(c.getTimeZone()); usDateParser.setTimeZone(c.getTimeZone()); usTimeParser.setTimeZone(c.getTimeZone()); String date = stripQuotes(item[2]); if (date.indexOf("N/A") != -1) //$NON-NLS-1$ date = usDateParser.format(Calendar.getInstance().getTime()); String time = stripQuotes(item[3]); if (time.indexOf("N/A") != -1) //$NON-NLS-1$ time = usTimeParser.format(Calendar.getInstance().getTime()); c.setTime(usDateTimeParser.parse(date + " " + time)); //$NON-NLS-1$ c.setTimeZone(TimeZone.getDefault()); quote.setDate(c.getTime()); } catch (Exception e) { log.error(e.getMessage() + ": " + line); //$NON-NLS-1$ } // 1 = Last price or N/A if (item[1].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ quote.setLast(numberFormat.parse(item[1]).doubleValue()); // 4 = Change // 5 = Open if (item[5].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ open = new Double(numberFormat.parse(item[5]).doubleValue()); // 6 = Maximum if (item[6].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ high = new Double(numberFormat.parse(item[6]).doubleValue()); // 7 = Minimum if (item[7].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ low = new Double(numberFormat.parse(item[7]).doubleValue()); // 8 = Volume if (item[8].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ quote.setVolume(numberFormat.parse(item[8]).intValue()); // 9 = Bid Price if (item[9].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ quote.setBid(numberFormat.parse(item[9]).doubleValue()); // 10 = Ask Price if (item[10].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ quote.setAsk(numberFormat.parse(item[10]).doubleValue()); // 11 = Close Price if (item[11].equalsIgnoreCase("N/A") == false) //$NON-NLS-1$ close = new Double(numberFormat.parse(item[11]).doubleValue()); // 0 = Code String symbol = stripQuotes(item[0]); for (Iterator iter = map.keySet().iterator(); iter.hasNext();) { Security security = (Security) iter.next(); if (symbol.equalsIgnoreCase((String) map.get(security))) { security.setQuote(quote, open, high, low, close); } } } in.close(); } catch (Exception e) { log.error(e); } }
From source file:biz.taoconsulting.dominodav.repository.AbstractRepositoryImplementation.java
/** * @see biz.taoconsulting.dominodav.interfaces.IDAVRepository#getAvailableMethods() *///ww w. j av a2 s. c o m public String getAvailableMethods() { StringBuffer out = new StringBuffer(); LOGGER.debug("# of supported methods " + new Integer(this.supportedMethods.size()).toString()); for (String curM : this.supportedMethods) { out.append(curM); // Don't change this! OPTIONS needs a space! out.append(" "); } out.deleteCharAt(out.length() - 1); // Remove the last space return out.toString(); }
From source file:com.qk.applibrary.db.sqlite.SqlBuilder.java
public static String getCreatTableSQL(Class<?> clazz) { TableInfo table = TableInfo.get(clazz); Id id = table.getId();//from w ww.java 2 s . c om StringBuffer strSQL = new StringBuffer(); strSQL.append("CREATE TABLE IF NOT EXISTS "); strSQL.append(table.getTableName()); strSQL.append(" ( "); Class<?> primaryClazz = id.getDataType(); if (primaryClazz == int.class || primaryClazz == Integer.class || primaryClazz == long.class || primaryClazz == Long.class) { strSQL.append(id.getColumn()).append(" INTEGER PRIMARY KEY AUTOINCREMENT,"); } else { strSQL.append(id.getColumn()).append(" TEXT PRIMARY KEY,"); } Collection<Property> propertys = table.propertyMap.values(); for (Property property : propertys) { strSQL.append(property.getColumn()); Class<?> dataType = property.getDataType(); if (dataType == int.class || dataType == Integer.class || dataType == long.class || dataType == Long.class) { strSQL.append(" INTEGER"); } else if (dataType == float.class || dataType == Float.class || dataType == double.class || dataType == Double.class) { strSQL.append(" REAL"); } else if (dataType == boolean.class || dataType == Boolean.class) { strSQL.append(" NUMERIC"); } strSQL.append(","); } strSQL.deleteCharAt(strSQL.length() - 1); strSQL.append(" )"); return strSQL.toString(); }
From source file:org.kuali.ole.select.lookup.DocLookupServiceImpl.java
public Map<String, List<String>> getDDRelationship(Class c) { Map<String, List<String>> result = new HashMap<String, List<String>>(0); DataDictionaryEntry entryBase = SpringContext.getBean(DataDictionaryService.class).getDataDictionary() .getDictionaryObjectEntry(c.getName()); if (entryBase == null) { return null; }// www. j a v a2 s .c o m List<RelationshipDefinition> ddRelationships = entryBase.getRelationships(); RelationshipDefinition relationship = null; int minKeys = Integer.MAX_VALUE; for (RelationshipDefinition def : ddRelationships) { // favor key sizes of 1 first if (def.getPrimitiveAttributes().size() == 1) { for (PrimitiveAttributeDefinition primitive : def.getPrimitiveAttributes()) { if (def.getObjectAttributeName() != null) { List<String> data = new ArrayList<String>(0); Class cc = getDocClass(c, def.getObjectAttributeName());//cc= null;data.remove("java.lang.String"); if (cc != null) { data.add(cc.getName()); StringBuffer sb = new StringBuffer(); List<PrimitiveAttributeDefinition> res = def.getPrimitiveAttributes(); for (PrimitiveAttributeDefinition pdef : res) { sb.append(pdef.getSourceName() + "," + pdef.getTargetName() + ":"); } sb.deleteCharAt(sb.length() - 1); data.add(sb.toString()); result.put(def.getObjectAttributeName(), data); } } } } } return result;//result.remove("oleRequestor"); }
From source file:Main.java
/** * This method adds underscore in between the words (eg: converts GeneHomolog * to Gene_Homolog)//from www. j a v a2 s . co m * * @param name */ public static void evaluateString(String name, List<String> options, List<String> words) { if (options == null || words == null) throw new IllegalArgumentException("Options or Words is not initialized"); //remove package name if the name is a class name if (name != null) { int index = name.lastIndexOf("."); name = name.substring(index + 1); } //Set optionSet = new HashSet(); options.add(name); char firstChar = name.charAt(0); firstChar = Character.toUpperCase(firstChar); if (name.indexOf("_") > 0) { String temp = Character.toString(firstChar) + name.substring(1); options.add(temp); } String temp = firstChar + name.substring(1).toLowerCase(); options.add(temp); String evaluatedString = null; ; StringBuffer wholeWords = new StringBuffer(); StringBuffer tempSeparateWord = new StringBuffer(); char[] chars = name.toCharArray(); StringBuffer sb = new StringBuffer(); boolean first = true; int index = 0; for (int i = 0; i < chars.length; i++) { //Character c = new Character(chars[i]); //System.out.println("inside loop i = " +i); if (Character.isUpperCase(chars[i])) { if ((i > 1) && ((i - index) > 1)) { //System.out.println("Inside capital if"); first = false; sb.append("_").append(chars[i]); words.add(tempSeparateWord.toString()); tempSeparateWord = new StringBuffer(); tempSeparateWord.append(chars[i]); wholeWords.append(" ").append(chars[i]); } else { wholeWords.append(chars[i]); tempSeparateWord.append(chars[i]); sb.append(chars[i]); } index = i; } else { if (chars[i] != '_') { sb.append(chars[i]); wholeWords.append(chars[i]); tempSeparateWord.append(chars[i]); } } } //System.out.println("Converted string: "+sb.toString()); //if the string contains "_", then make the first character uppercase if (!first) { char c = Character.toUpperCase(sb.charAt(0)); sb.deleteCharAt(0); sb.insert(0, c); char c1 = Character.toUpperCase(wholeWords.charAt(0)); wholeWords.deleteCharAt(0); wholeWords.insert(0, c1); } options.add(sb.toString()); options.add(wholeWords.toString()); if (words.size() > 0) { /* StringBuffer tmp = (StringBuffer)separateWords.get(0); char c2 = Character.toUpperCase(tmp.charAt(0)); tmp.deleteCharAt(0); tmp.insert(0, c2); separateWords.remove(0); separateWords.add(0, tmp); */ String temp2 = words.get(words.size() - 1).toString(); if (tempSeparateWord != null) { temp = tempSeparateWord.toString(); if (temp2.compareToIgnoreCase(temp) != 0) { words.add(temp); } } } List possibleOptions = new ArrayList(options); options = null;//garbage collection ready //testing for (int i = 0; i < possibleOptions.size(); i++) { System.out.println("options[" + i + "]=" + possibleOptions.get(i)); } for (int i = 0; i < words.size(); i++) { System.out.println("separateWords[" + i + "]=" + words.get(i)); } return; }
From source file:com.cettco.buycar.activity.OrderDetailActivity.java
private void updateUI() { String state = detailEntity.getState(); if (state.equals("qualified")) { stateTextView.setText(",4s?"); cancelButton.setVisibility(View.VISIBLE); qRcodeLayout.setVisibility(View.GONE); } else if (state.equals("deal_made")) { stateTextView.setText("4s?"); cancelButton.setVisibility(View.VISIBLE); dealerInfoLayout.setVisibility(View.VISIBLE); dealerIntentionLayout.setVisibility(View.VISIBLE); dealerPhoneTextView.setText(detailEntity.getDealer().getPhone()); shopAddressTextView.setText(detailEntity.getShop().getAddress()); shopNameTextView.setText(detailEntity.getShop().getName()); //bid info insuranceTextView.setText(detailEntity.getBid().getInsurance() + " "); purTaxTextView.setText(detailEntity.getBid().getPurchase_tax() + " "); licFeeTextView.setText(detailEntity.getBid().getLicense_fee() + " "); miscFeeTextView.setText(detailEntity.getBid().getMisc_fee() + " "); desTextView.setText(detailEntity.getBid().getDescription() + " "); qRcodeLayout.setVisibility(View.VISIBLE); try {/*from w w w.ja va 2s. c om*/ qrImageView.setImageBitmap(Create2DCode(detailEntity.getVerfiy_code())); } catch (WriterException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if (state.equals("final_deal_closed")) { cancelButton.setVisibility(View.GONE); stateTextView.setText("?"); dealerInfoLayout.setVisibility(View.VISIBLE); dealerIntentionLayout.setVisibility(View.VISIBLE); dealerPhoneTextView.setText(detailEntity.getDealer().getPhone()); shopAddressTextView.setText(detailEntity.getShop().getAddress()); shopNameTextView.setText(detailEntity.getShop().getName()); //bid info insuranceTextView.setText(detailEntity.getBid().getInsurance() + " "); purTaxTextView.setText(detailEntity.getBid().getPurchase_tax() + " "); licFeeTextView.setText(detailEntity.getBid().getLicense_fee() + " "); miscFeeTextView.setText(detailEntity.getBid().getMisc_fee() + " "); desTextView.setText(detailEntity.getBid().getDescription() + " "); qRcodeLayout.setVisibility(View.GONE); // try { // qrImageView.setImageBitmap(Create2DCode(detailEntity // .getVerfiy_code())); // } catch (WriterException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } } else if (state.equals("canceled")) { cancelButton.setVisibility(View.GONE); stateTextView.setText("??"); qRcodeLayout.setVisibility(View.GONE); } MyApplication.IMAGE_CACHE.get(detailEntity.getPic_url(), carImageView); String brandName = detailEntity.getBrand().getName(); String makerName = detailEntity.getMaker().getName(); String modelName = detailEntity.getModel().getName(); String trimName = detailEntity.getTrim().getName(); StringBuffer colorBuffer = new StringBuffer(""); for (int i = 0; i < detailEntity.getColors().size(); i++) { colorBuffer.append(detailEntity.getColors().get(i).getName() + ","); } colorBuffer.deleteCharAt(colorBuffer.length() - 1); // detailEntity. colorTextView.setText(colorBuffer.toString()); modelTextView.setText(brandName + "(" + makerName + ") " + modelName); trimTextView.setText(trimName); priceTextView.setText(detailEntity.getPrice() + ""); DatabaseHelperTrim helperTrim = DatabaseHelperTrim.getHelper(this); try { CarTrimEntity trimEntity = helperTrim.getDao().queryBuilder().where() .eq("id", detailEntity.getTrim_id()).queryForFirst(); double guide = Double.valueOf(trimEntity.getGuide_price()); double myPrice = Double.valueOf(detailEntity.getPrice()); benefitTextView.setText(String.format("%.1f", guide - myPrice) + ""); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } // pickupTimeTextView.setText(detailEntity.getPickup_time()); if (detailEntity.getPickup_time().equals("0")) { pickupTimeTextView.setText("7"); } else if (detailEntity.getPickup_time().equals("1")) { pickupTimeTextView.setText("14"); } else if (detailEntity.getPickup_time().equals("2")) { pickupTimeTextView.setText("21?"); } licenseLocationTextView.setText(detailEntity.getLicense_location()); if (detailEntity.getGot_licence().equals("0")) { gotLicenseTextView.setText("?"); } else if (detailEntity.getGot_licence().equals("1")) { gotLicenseTextView.setText(""); } if (detailEntity.getLoan_option().equals("0")) { loanTextView.setText(""); } else if (detailEntity.getLoan_option().equals("1")) { loanTextView.setText(""); } else if (detailEntity.getLoan_option().equals("2")) { loanTextView.setText("??"); } }
From source file:com.zimbra.common.mime.MimeDetect.java
private String readLine(InputStream is) throws IOException { StringBuffer sb = new StringBuffer(); int c;//from ww w .ja va 2 s .com while ((c = is.read()) != -1 && c != '\n') sb.append((char) c); if (sb.length() > 0 && sb.charAt(sb.length() - 1) == '\r') { // drop trailing \r sb.deleteCharAt(sb.length() - 1); } return sb.length() == 0 ? null : sb.toString(); }
From source file:edu.arizona.kra.proposaldevelopment.dao.ojb.PropDevRoutingStateDaoOjb.java
/** * Searches the proposals associated with the given list of unitNumbers in either the cost sharing part of the budget or * by the proposal persons that are assigned a role in the proposal * and returns a list of unique proposalNumbers corresponding to those proposals * * @param workflowUnits - list of unitNumbers * @return/*from ww w . j a va 2s .c o m*/ * @throws SQLException * @throws LookupException */ protected List<String> findProposalsForWorkflowUnits(List<String> workflowUnits) throws SQLException, LookupException { LOG.debug("findProposalsForWorkflowUnits: workflowUnits {}.", workflowUnits); List<String> proposalNumbers = new ArrayList<String>(); if (workflowUnits != null && !workflowUnits.isEmpty()) { //create the subquery containing unitNumbers StringBuffer unitNumbersList = new StringBuffer("("); for (String unitNumber : workflowUnits) { unitNumbersList.append("'" + unitNumber + "',"); } //remove last hanging comma unitNumbersList.deleteCharAt(unitNumbersList.length() - 1); unitNumbersList.append(") "); StringBuffer query = new StringBuffer(WORKFLOW_UNITS_PROPOSALS_QUERY); query.append(unitNumbersList); query.append(WORKFLOW_UNITS_PROPOSALS_QUERY_CONT); query.append(unitNumbersList); query.append(WORKFLOW_UNITS_PROPOSALS_QUERY_FIN); try (DBConnection dbc = new DBConnection(this.getPersistenceBroker(true))) { ResultSet rs = dbc.executeQuery(query.toString(), null); while (rs.next()) { proposalNumbers.add(rs.getString(1)); } } catch (SQLException sqle) { LOG.error("SQLException: " + sqle.getMessage(), sqle); throw sqle; } catch (LookupException le) { LOG.error("LookupException: " + le.getMessage(), le); throw le; } } LOG.debug("findProposalsForWorkflowUnits: Finished results size={}.", proposalNumbers.size()); LOG.debug("PROPOSAL NUMBERS: {}", proposalNumbers.toString()); return proposalNumbers; }