Example usage for java.lang StringBuffer deleteCharAt

List of usage examples for java.lang StringBuffer deleteCharAt

Introduction

In this page you can find the example usage for java.lang StringBuffer deleteCharAt.

Prototype

@Override
public synchronized StringBuffer deleteCharAt(int index) 

Source Link

Usage

From source file:com.edgenius.wiki.integration.client.Authentication.java

/**
 * @param cookieTokens the tokens to be encoded.
 * @return base64 encoding of the tokens concatenated with the ":" delimiter.
 *//*from  www  . j  ava 2 s .  co  m*/
private String encodeCookie(String[] cookieTokens) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < cookieTokens.length; i++) {
        sb.append(cookieTokens[i]);

        if (i < cookieTokens.length - 1) {
            sb.append(WsContants.DELIMITER);
        }
    }

    String value = sb.toString();

    sb = new StringBuffer(new String(Base64.encodeBase64(value.getBytes())));

    while (sb.charAt(sb.length() - 1) == '=') {
        sb.deleteCharAt(sb.length() - 1);
    }

    return sb.toString();
}

From source file:com.wabacus.system.component.application.report.configbean.editablereport.StoreProcedureActionBean.java

public void parseActionscript(String reportTypeKey, String actionscript) {
    ReportBean rbean = this.ownerGroupBean.getOwnerUpdateBean().getOwner().getReportBean();
    actionscript = this.parseAndRemoveReturnParamname(actionscript);
    if (actionscript.startsWith("{") && actionscript.endsWith("}")) {
        actionscript = actionscript.substring(1, actionscript.length() - 1).trim();
    }/* www.  j a  v  a2 s .co m*/
    String procedure = actionscript.substring("call ".length()).trim();
    if (procedure.equals("")) {
        throw new WabacusConfigLoadingException("" + rbean.getPath() + "?"
                + actionscript + "???");
    }
    String procname = procedure;
    List lstProcedureParams = new ArrayList();
    int idxLeft = procedure.indexOf("(");
    if (idxLeft > 0) {
        int idxRight = procedure.lastIndexOf(")");
        if (idxLeft == 0 || idxRight != procedure.length() - 1) {
            throw new WabacusConfigLoadingException("" + rbean.getPath() + "?"
                    + actionscript + "????");
        }
        procname = procedure.substring(0, idxLeft).trim();
        String params = procedure.substring(idxLeft + 1, idxRight).trim();
        if (!params.equals("")) {
            List<String> lstParamsTmp = Tools.parseStringToList(params, ',', '\'');
            Object paramObjTmp;
            for (String paramTmp : lstParamsTmp) {
                paramObjTmp = createEditParams(paramTmp, reportTypeKey);
                if (paramObjTmp instanceof String) {
                    String strParamTmp = ((String) paramObjTmp);
                    if (strParamTmp.startsWith("'") && strParamTmp.endsWith("'"))
                        strParamTmp = strParamTmp.substring(1, strParamTmp.length() - 1);
                    if (strParamTmp.startsWith("\"") && strParamTmp.endsWith("\""))
                        strParamTmp = strParamTmp.substring(1, strParamTmp.length() - 1);
                    paramObjTmp = strParamTmp;
                }
                lstProcedureParams.add(paramObjTmp);
            }
        }
    }
    StringBuffer tmpBuf = new StringBuffer("{call " + procname + "(");
    for (int i = 0, len = lstProcedureParams.size(); i < len; i++) {
        tmpBuf.append("?,");
    }
    if (this.returnValueParamname != null && !this.returnValueParamname.trim().equals(""))
        tmpBuf.append("?");
    if (tmpBuf.charAt(tmpBuf.length() - 1) == ',')
        tmpBuf.deleteCharAt(tmpBuf.length() - 1);
    tmpBuf.append(")}");
    this.sql = tmpBuf.toString();
    this.lstParams = lstProcedureParams;
    this.ownerGroupBean.addActionBean(this);
}

From source file:chibi.gemmaanalysis.SummaryStatistics.java

private void printGenesPerProbeCountMap(Map<ArrayDesign, Map<Integer, Integer>> countMap) throws IOException {
    PrintWriter out;/*w ww  .ja  va2s . co  m*/
    if (outFileName == null) {
        out = new PrintWriter(System.out);
    } else {
        out = new PrintWriter(new FileWriter(outFileName));
    }

    // get max number of genes
    int maxNumGenes = 0;
    for (Map<Integer, Integer> counts : countMap.values()) {
        for (Integer n : counts.keySet()) {
            int count = counts.get(n);
            if (count > 0 && n > maxNumGenes)
                maxNumGenes = n;
        }
    }

    StringBuffer buf = new StringBuffer("Count\t");
    for (ArrayDesign ad : countMap.keySet()) {
        buf.append(ad.getShortName() + "\t");
    }
    buf.deleteCharAt(buf.length() - 1);
    out.println(buf);

    for (int numGenes = 0; numGenes <= maxNumGenes; numGenes++) {
        buf = new StringBuffer();
        buf.append(numGenes + "\t");
        for (ArrayDesign ad : countMap.keySet()) {
            Map<Integer, Integer> counts = countMap.get(ad);
            if (counts.get(numGenes) != null)
                buf.append(counts.get(numGenes));
            else
                buf.append("0");
            buf.append("\t");
        }
        buf.deleteCharAt(buf.length() - 1);
        out.println(buf);
    }
    out.close();
}

From source file:org.latticesoft.util.container.tree.noderule.RangeRule.java

public Node findNode(Object data) {
    Node theNode = null;//from w  ww  .  j  a v a 2 s .com
    String nodeName = null;
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < keyList.size(); i++) {
        RangeRuleKey key = (RangeRuleKey) this.keyList.get(i);
        Object dataAttribute = BeanUtil.getAttribute(data, this.attributeName);
        Object value = key.evaluate(dataAttribute);
        if (value != null) {
            sb.append(value);
            sb.append("|");
        }
    }
    if (sb.length() > 0) {
        sb.deleteCharAt(sb.length() - 1);
    }
    if (sb.length() == 0) {
        sb.append("default");
    }
    nodeName = (String) this.reference.get(sb.toString());
    if (log.isInfoEnabled()) {
        log.info(sb.toString() + " --> " + nodeName);
    }
    theNode = this.parentNode.getChild(nodeName);
    return theNode;
}

From source file:chibi.gemmaanalysis.GeneExpressionProfileWriterCLI.java

@Override
protected Exception doWork(String[] args) {
    processCommandLine(args);/* www  . j  a v  a2  s  . c  o m*/

    Collection<Gene> genes;
    try {
        genes = getQueryGenes();
    } catch (IOException e) {
        return e;
    }

    FilterConfig filterConfig = new FilterConfig();
    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));
        }
        Map<Gene, Collection<CompositeSequence>> gene2css = coexpAnalysisService.getGene2CsMap(css);
        ExpressionDataDoubleMatrix dataMatrix = coexpAnalysisService.getExpressionDataMatrix(ee, filterConfig);
        String fileName = outFilePrefix + "." + ee.getShortName() + ".txt";
        try (PrintWriter out = new PrintWriter(new FileWriter(fileName));) {
            for (Gene gene : genes) {
                Collection<CompositeSequence> c = gene2css.get(gene);
                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;
                    }
                    StringBuffer buf = new StringBuffer();
                    buf.append(gene.getOfficialSymbol() + "\t" + cs.getName() + "\t");
                    for (Double d : row) {
                        if (d == null)
                            buf.append("NaN");
                        else
                            buf.append(d);
                        buf.append("\t");
                    }
                    buf.deleteCharAt(buf.length() - 1);
                    out.println(buf.toString());
                }
            }

        } catch (IOException e) {
            return e;
        }
    }

    return null;
}

From source file:de.iteratec.iteraplan.common.util.HashBucketMatrix.java

/**
 * String representation of the HashBucketMatrix. for each entry it shows the key and all of its
 * values. the toString method of each object is used for that.
 * //  w  w w. j  a  va 2  s.  c om
 * @return the string representation
 */
@Override
public String toString() {
    StringBuilder sb = new StringBuilder(30);

    // get keys
    HashSet<K2> secondDimensionKeys = new HashSet<K2>();
    for (HashBucketMap<K2, V> bucketMap : this.firstDimension.values()) {
        for (K2 secondKey : bucketMap.keySet()) {
            secondDimensionKeys.add(secondKey);
        }
    }

    sb.append("\n          || ");
    for (K1 key : this.firstDimension.keySet()) {
        if (key == null) {
            sb.append(StringUtils.rightPad("null", 10));
        } else {
            sb.append(StringUtils.rightPad(key.toString(), 10));
        }
        sb.append("| ");
    }
    sb.append('\n');

    for (K2 secondKey : secondDimensionKeys) {
        if (secondKey == null) {
            sb.append(StringUtils.rightPad("null", 10));
        } else {
            sb.append(StringUtils.rightPad(secondKey.toString(), 10));
        }
        sb.append("|| ");
        for (K1 firstKey : this.firstDimension.keySet()) {
            List<V> bucket = this.getBucketNotNull(firstKey, secondKey);
            StringBuffer bucketBuffer = new StringBuffer();
            for (V value : bucket) {
                bucketBuffer.append(value);
                bucketBuffer.append(';');
            }
            if (bucketBuffer.length() > 0) {
                bucketBuffer.deleteCharAt(bucketBuffer.length() - 1);
            }
            sb.append(StringUtils.rightPad(bucketBuffer.toString(), 10));
            sb.append("| ");
        }
        sb.append('\n');
    }

    return sb.toString();
}

From source file:com.weitaomi.systemconfig.filter.LoggingFilter.java

private String getPostParamsStr(HttpServletRequest request) {
    StringBuffer sb = new StringBuffer();
    sb.append("{");

    Enumeration<String> parameterNames = request.getParameterNames();

    while (parameterNames.hasMoreElements()) {
        String name = parameterNames.nextElement();
        sb.append("\"").append(name).append("\"").append(":")
                .append(StringUtil.stringArrayToStringWithQuot(request.getParameterValues(name))).append(",");
    }//from  w  w  w  .  j a  v  a 2  s  . c o m
    if (sb.length() > 1) {
        sb.deleteCharAt(sb.length() - 1);
    }
    sb.append("}");

    return sb.toString();
}

From source file:org.bigsolr.hadoop.SolrRecord.java

@Override
public String toString() {
    log.debug("SolrRecord -> toString");

    StringBuffer jsonStr = new StringBuffer();
    jsonStr.append("{");
    for (String fieldName : sd.getFieldNames()) {
        String escapedFieldName = StringEscapeUtils.escapeJava((String) fieldName);
        String escapedFieldValue = StringEscapeUtils
                .escapeJava((String) sd.getFieldValue(fieldName).toString());
        jsonStr.append("\"" + escapedFieldName + "\":\"" + escapedFieldValue + "\",");
    }/*from  ww w.  j  a  v  a2 s  .  c  o  m*/

    jsonStr = jsonStr.deleteCharAt(jsonStr.length() - 1); // remove the last ',' character
    jsonStr.append("}");

    return jsonStr.toString();
}

From source file:org.netflux.core.RecordMetadata.java

/**
 * Returns a string representation of this record metadata. The string representation is a comma separated list of values surrounded
 * by square brackets.// w  w  w .  ja  va 2  s  . co  m
 * 
 * @return a string representation of this record metadata.
 */
@Override
public String toString() {
    StringBuffer metadataString = new StringBuffer("[");
    for (FieldMetadata fieldMetadata : this.fieldMetadata) {
        metadataString.append(fieldMetadata.toString());
        metadataString.append(',');
    }
    if (!this.fieldMetadata.isEmpty()) {
        metadataString.deleteCharAt(metadataString.length() - 1);
    }
    metadataString.append(']');
    return metadataString.toString();
}

From source file:br.org.indt.ndg.common.MD5.java

public static String getMD5FromSurvey(StringBuffer input) throws IOException, NoSuchAlgorithmException {

    StringBuffer inputMD5 = new StringBuffer(input);

    // remove XML header
    String xmlStartFlag = "<?";
    String xmlEndFlag = "?>";

    int xmlFlagStartPosition = inputMD5.indexOf(xmlStartFlag);
    int xmlFlagEndPosition = inputMD5.indexOf(xmlEndFlag);

    if ((xmlFlagStartPosition >= 0) && (xmlFlagEndPosition >= 0)) {
        inputMD5.delete(xmlFlagStartPosition, xmlFlagEndPosition + xmlEndFlag.length() + 1);
    }/*www.j av  a 2  s .c  om*/

    // remove checksum key
    String checksumFlag = "checksum=\"";
    int checksumFlagStartPosition = inputMD5.indexOf(checksumFlag) + checksumFlag.length();
    int checksumKeySize = 32;

    inputMD5.replace(checksumFlagStartPosition, checksumFlagStartPosition + checksumKeySize, "");

    // we need to remove last '\n' once NDG editor calculates its md5
    // checksum without it (both input and inputMD5)
    if (input.charAt(input.toString().length() - 1) == '\n') {
        input.deleteCharAt(input.toString().length() - 1);
    }

    if (inputMD5.charAt(inputMD5.toString().length() - 1) == '\n') {
        inputMD5.deleteCharAt(inputMD5.toString().length() - 1);
    }

    MessageDigest messageDigest = java.security.MessageDigest.getInstance("MD5");
    messageDigest.update(inputMD5.toString().getBytes("UTF-8"));
    byte[] byteArrayMD5 = messageDigest.digest();

    String surveyFileMD5 = getByteArrayAsString(byteArrayMD5);

    return surveyFileMD5;
}