Example usage for java.lang StringBuffer substring

List of usage examples for java.lang StringBuffer substring

Introduction

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

Prototype

@Override
public synchronized String substring(int start, int end) 

Source Link

Usage

From source file:com.avricot.prediction.utils.Steemer.java

/**
  * Retrieve the "RV zone" from a buffer an return the corresponding string<br>
  * "If the word begins with two vowels, RV is the region after the third letter,
  * otherwise the region after the first vowel not at the beginning of the word,
  * or the end of the word if these positions cannot be found."<br>
  * @param buffer java.lang.StringBuffer - the in buffer
  * @return java.lang.String - the resulting string
  *///from   www . ja  v a  2s. c  om
 private String retrieveRV(StringBuffer buffer) {
     int len = buffer.length();
     if (buffer.length() > 3) {
         if (isVowel(buffer.charAt(0)) && isVowel(buffer.charAt(1))) {
             return buffer.substring(3, len);
         } else {
             int pos = 0;
             for (int c = 1; c < len; c++) {
                 if (isVowel(buffer.charAt(c))) {
                     pos = c;
                     break;
                 }
             }
             if (pos + 1 < len)
                 return buffer.substring(pos + 1, len);
             else
                 return null;
         }
     } else
         return null;
 }

From source file:org.jimcat.gui.perspective.boards.cards.Card.java

/**
 * update album list/*w w  w . j a  v a 2  s . c o  m*/
 */
private void updateAlbumList() {
    List<Album> albumList = new ArrayList<Album>(image.getAlbums());
    StringBuffer result = new StringBuffer();
    Collections.sort(albumList, ALBUM_COMPARATOR);

    for (Album a : albumList) {
        result.append(a.getName()).append(", ");
    }

    String list = " -none- ";
    if (albumList.size() > 0) {
        list = result.substring(0, result.length() - 2);
    }
    albums.setText(list);
    albums.setToolTipText(list);
}

From source file:fr.paris.lutece.plugins.search.solr.business.SolrSearchEngine.java

/**
 * Builds a field filter string./*from   w w  w.j  a va  2s .  com*/
 * field:(value0 value1 ...valueN)
 * @param strField the field
 * @param values the values
 * @return the filter string
 */
private String buildFilter(String strField, String[] values) {
    StringBuffer sb = new StringBuffer();
    sb.append(strField);
    sb.append(":(");

    for (String strValue : values) {
        sb.append(strValue);
        sb.append(" ");
    }

    String filterString = sb.substring(0, sb.length() - 1);
    filterString += ")";

    return filterString;
}

From source file:org.apache.hadoop.mapred.util.ProcfsBasedProcessTree.java

/**
 * Returns a string printing PIDs of process present in the
 * ProcfsBasedProcessTree. Output format : [pid pid ..]
 *//*from  w w w .ja v a 2  s .  c  o m*/
public String toString() {
    StringBuffer pTree = new StringBuffer("[ ");
    for (Integer p : processTree.keySet()) {
        pTree.append(p);
        pTree.append(" ");
    }
    return pTree.substring(0, pTree.length()) + "]";
}

From source file:ubic.gemma.loader.protein.ProteinLinkOutFormatter.java

/**
 * Convert a byte representing the evidence as stored in db to a textural display of evidence. e.g {0,1,0,0,0,1,0} >
 * GeneFusion:Database/*w ww.  j a v a 2s  .  co  m*/
 * 
 * @param bytes byte array representing evidence
 * @return Formated text of evidence
 */
public String getEvidenceDisplayText(byte[] bytes) {

    StringBuffer evidenceString;
    try {
        evidenceString = new StringBuffer();
        if (bytes != null && bytes.length == StringProteinInteractionEvidenceCodeEnum.values().length) {
            for (StringProteinInteractionEvidenceCodeEnum currentEvidence : StringProteinInteractionEvidenceCodeEnum
                    .values()) {
                // if the byte at that particular position is 1 then that means that there is evidence
                if ((bytes[currentEvidence.getPositionInArray()]) == 1) {
                    evidenceString.append(currentEvidence.getDisplayText()).append(EVIDENCESPACER);
                }
            }
            return evidenceString.substring(0, (evidenceString.lastIndexOf(EVIDENCESPACER)));
        }
        log.warn("The byte array provided was not the correct size for the protein protein interaction");

    } catch (Exception e) {
        // should really be a more specific exception
        throw new RuntimeException("Bit Vector representing evidence codes for proteins was at error " + e);
    }
    return evidenceString.toString();
}

From source file:org.pssframework.xsqlbuilder.XsqlBuilder.java

/**
 * @see #applyFilters(String, Map)//from   w  w  w.  j a v  a 2s  .  co  m
 */
private XsqlFilterResult applyFilters(StringBuffer xsql, Object filters) {
    LinkedHashMap acceptedFilters = new LinkedHashMap();
    for (int i = 0, end = 0, start = xsql.indexOf("/~"); ((start = xsql.indexOf("/~", end)) >= 0); i++) {
        end = xsql.indexOf("~/", start);
        KeyMetaDatas metadatas = getKeyMetaDatas(xsql, start, end);
        if (metadatas.markKeys.isEmpty() && metadatas.replaceKeys.isEmpty())
            throw new IllegalArgumentException("Not key found in segment=" + xsql.substring(start, end + 2));

        if (isAcceptedAllKeys(filters, metadatas.markKeys)
                && isAcceptedAllKeys(filters, metadatas.replaceKeys)) {
            if (logger.isDebugEnabled()) {
                logger.debug("The filter markKeys=" + metadatas.markKeys + " replaceKeys="
                        + metadatas.replaceKeys + " is accepted on segment=" + xsql.substring(start, end + 2));
            }
            String segment = xsql.substring(start + 2, end);
            segment = mergeMarkKeysIntoAcceptedFilters(filters, acceptedFilters, metadatas, segment);
            segment = replaceReplaceKeysWithValues(filters, metadatas.replaceKeys, segment);
            xsql.replace(start, end + 2, segment);
            end = start + segment.length();
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug(
                        "The filter markKeys=" + metadatas.markKeys + " replaceKeys=" + metadatas.replaceKeys
                                + " is removed from the query on segment=" + xsql.substring(start, end + 2));
            }
            xsql.replace(start, end + 2, "");
            end = start;
        }
    }
    return new XsqlFilterResult(xsql.toString(), acceptedFilters);
}

From source file:com.qut.middleware.spep.filter.SPEPFilter.java

/**
 * Transcodes %XX symbols per RFC 2369 to normalized character format - adapted from apache commons
 * //from w  ww  .  j  a  va 2  s .c o  m
 * @param buffer
 *            The stringBuffer object containing the request data
 * @param offset
 *            How far into the string buffer we should start processing from
 * @param length
 *            Number of chars in the buffer
 * @throws ServletException
 */
private void decode(final StringBuffer buffer, final int offset, final int length) throws ServletException {
    int index = offset;
    int count = length;
    int dig1, dig2;
    while (count > 0) {
        final char ch = buffer.charAt(index);
        if (ch != '%') {
            count--;
            index++;
            continue;
        }
        if (count < 3) {
            throw new ServletException(
                    Messages.getString("SPEPFilter.10") + buffer.substring(index, index + count)); //$NON-NLS-1$
        }

        dig1 = Character.digit(buffer.charAt(index + 1), 16);
        dig2 = Character.digit(buffer.charAt(index + 2), 16);
        if (dig1 == -1 || dig2 == -1) {
            throw new ServletException(
                    Messages.getString("SPEPFilter.11") + buffer.substring(index, index + count)); //$NON-NLS-1$
        }
        char value = (char) (dig1 << 4 | dig2);

        buffer.setCharAt(index, value);
        buffer.delete(index + 1, index + 3);
        count -= 3;
        index++;
    }
}

From source file:ubic.gemma.core.loader.protein.ProteinLinkOutFormatter.java

/**
 * Convert a byte representing the evidence as stored in db to a textural display of evidence. e.g {0,1,0,0,0,1,0} &gt;
 * GeneFusion:Database/*ww w  .  j  a  va 2s.c  o  m*/
 *
 * @param bytes byte array representing evidence
 * @return Formatted text of evidence
 */
public String getEvidenceDisplayText(byte[] bytes) {

    StringBuffer evidenceString;
    try {
        evidenceString = new StringBuffer();
        if (bytes != null && bytes.length == StringProteinInteractionEvidenceCodeEnum.values().length) {
            for (StringProteinInteractionEvidenceCodeEnum currentEvidence : StringProteinInteractionEvidenceCodeEnum
                    .values()) {
                // if the byte at that particular position is 1 then that means that there is evidence
                if ((bytes[currentEvidence.getPositionInArray()]) == 1) {
                    evidenceString.append(currentEvidence.getDisplayText()).append(EVIDENCE_SPACER);
                }
            }
            return evidenceString.substring(0, (evidenceString.lastIndexOf(EVIDENCE_SPACER)));
        }
        log.warn("The byte array provided was not the correct size for the protein protein interaction");

    } catch (Exception e) {
        // should really be a more specific exception
        throw new RuntimeException("Bit Vector representing evidence codes for proteins was at error " + e);
    }
    return evidenceString.toString();
}

From source file:org.nuxeo.ecm.webengine.model.impl.AbstractWebContext.java

@Override
public String getBaseURL() {
    StringBuffer sb = request.getRequestURL();
    int p = sb.indexOf(getBasePath());
    if (p > -1) {
        return sb.substring(0, p);
    }//from  w w w  . j  a v  a2 s .c  o m
    return sb.toString();
}

From source file:CircularGenerator.java

private void extendSequence(String header, StringBuffer sequence, PrintWriter outFastA,
        PrintWriter outChanged) {
    String currEntry = header.split(" ")[0]; //just use the forward part of the entry, never something else
    //Modify the data
    boolean regEx = false;
    for (String names : keys_to_treat_circular) {
        if (currEntry.contains(names)) {
            regEx = true;//from   ww  w . j ava 2  s .  com
        }
    }
    if (regEx) {
        if (sequence.length() < elongationfactor) {
            System.out.println(sequence.length());
            System.err
                    .println("You cannot extend your sequence with a value longer than your actual sequence.");
            System.exit(1);
        } else {
            String extension = sequence.substring(0, this.elongationfactor);
            sequence.append(extension);
            outChanged.println(header.split(" ")[0]);
        }
    }
    // write the sequence to the new file
    outFastA.println(">" + header);
    int index = 0;
    while (index <= sequence.length()) {
        outFastA.println(sequence.substring(index, Math.min(index + 80, sequence.length())));
        index += 80;
    }
    outFastA.flush();
}