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:cn.remex.core.util.StringUtils.java

/**
 *  //from   w  w w .j a va  2  s.  c o  m
 * Trim trailing whitespace from the given String.
 * @param str the String to check 
 * @return the trimmed String ??
 * @see java.lang.Character#isWhitespace
 */
public static String trimTrailingWhitespace(final String str) {
    if (!hasLength(str)) {
        return str;
    }
    StringBuffer buf = new StringBuffer(str);
    while (buf.length() > 0 && Character.isWhitespace(buf.charAt(buf.length() - 1))) {
        buf.deleteCharAt(buf.length() - 1);
    }
    return buf.toString();
}

From source file:com.seedboxer.seedboxer.mule.processor.postaction.SSHCommandSender.java

@SuppressWarnings("unchecked")
private String processTemplate(String command, Map<String, Object> templateVars)
        throws IOException, TemplateException {

    List<String> files = (List<String>) templateVars.get(Configuration.FILES);
    StringBuffer sb = new StringBuffer();
    for (String file : files) {
        sb.append(new File(file).getName());
        sb.append(",");
    }/*from   w  w w . j a va  2  s . c om*/
    sb.deleteCharAt(sb.length() - 1);

    return command.replaceAll(variableNameInCmd, sb.toString());
}

From source file:com.linuxbox.enkive.docsearch.indri.IndriQueryComposer.java

/**
 * Creates an Indri query by using the filter-require (#filreq) and
 * filter-reject (#filrej) operators to filter the results. Then it uses the
 * #compose operator to rank/weight the result of the the required elements.
 * If there are no required elements, it uses a simple #not to complete the
 * query./*from  ww w  .java2s .co  m*/
 * 
 * @param query
 * @return
 * @throws DocSearchException
 */
public static CharSequence composeQuery(TextQueryParser.Query query) throws DocSearchException {
    if (LOGGER.isTraceEnabled()) {
        StringBuilder output = new StringBuilder();
        boolean first = true;
        for (Phrase p : query) {
            if (first) {
                first = false;
            } else {
                output.append(", ");
            }
            output.append(p.getTermsAsCharSeq());
        }
        LOGGER.trace("composeQuery receives phrases: " + output.toString());
    }

    StringBuffer result = new StringBuffer();

    /*
     * Separate the requirements and the rejections and sanitize in place.
     */
    List<Phrase> requirements = new LinkedList<Phrase>();
    List<Phrase> rejections = new LinkedList<Phrase>();
    for (Phrase p : query) {
        sanitizePhraseInPlace(p);

        if (p.isNegated()) {
            rejections.add(p);
        } else {
            requirements.add(p);
        }
    }

    if (!requirements.isEmpty()) {
        // prefer to combine requirements with #combine, which does some
        // perhaps useful weighting of search terms based on frequency
        if (requirements.size() > 1) {
            result.append("#combine(");
        }

        for (Phrase p : requirements) {
            result.append(composePhrase(p));
            result.append(' ');
        }
        result.deleteCharAt(result.length() - 1);

        if (requirements.size() > 1) {
            result.append(")");
        }
    } else if (!rejections.isEmpty()) {
        // if everything is negation, so we have something in the query,
        // just prohibit the first element, given that we've already
        // #filrej'ed everything
        result.append("#not(");
        result.append(composePhrase(rejections.get(0)));
        result.append(')');
    } else {
        throw new DocSearchException("illegal query: empty");
    }

    // now we have the core; lets add the filters to the outside; since
    // requirements (#filereq) are likely to reduce the number of results
    // more quickly, make that the outer filter with the rejections within.

    // first wrap rejection filter if necessary
    if (!rejections.isEmpty()) {
        StringBuffer prefix = new StringBuffer("#filrej(");

        if (rejections.size() > 1) {
            prefix.append("#syn(");
        }

        for (Phrase p : rejections) {
            prefix.append(composePhrase(p));
            prefix.append(' ');
        }

        // delete last space
        prefix.deleteCharAt(prefix.length() - 1);

        if (rejections.size() > 1) {
            prefix.append(')');
        }

        prefix.append(' ');

        result.insert(0, prefix);
        result.append(")");
    }

    // now wrap requirements filter if necessary; this will be executed
    // before any rejection filter
    if (!requirements.isEmpty()) {
        StringBuffer prefix = new StringBuffer("#filreq(");

        if (requirements.size() > 1) {
            prefix.append("#band(");
        }

        for (Phrase p : requirements) {
            prefix.append(composePhrase(p));
            prefix.append(' ');
        }

        // delete last space
        prefix.deleteCharAt(prefix.length() - 1);

        if (requirements.size() > 1) {
            prefix.append(')');
        }

        prefix.append(' ');

        result.insert(0, prefix);
        result.append(")");
    }

    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("composeQuery produces: " + result);
    }
    return result;
}

From source file:egovframework.rte.fdl.string.EgovStringUtil.java

/**
 * convert first letter to a big letter or a small
 * letter.<br>//from w ww .j av  a 2 s .c  om
 * 
 * <pre>
 * StringUtil.trim('Password') = 'password'
 * StringUtil.trim('password') = 'Password'
 * </pre>
 * @param str
 *        String to be swapped
 * @return String converting result
 */
public static String swapFirstLetterCase(String str) {
    StringBuffer sbuf = new StringBuffer(str);
    sbuf.deleteCharAt(0);
    if (Character.isLowerCase(str.substring(0, 1).toCharArray()[0])) {
        sbuf.insert(0, str.substring(0, 1).toUpperCase());
    } else {
        sbuf.insert(0, str.substring(0, 1).toLowerCase());
    }
    return sbuf.toString();
}

From source file:org.talend.dataquality.standardization.record.OutputRecord.java

@Override
public String toString() {
    StringBuffer buf = new StringBuffer();
    for (String element : record) {
        buf.append(element).append(" ; ");//$NON-NLS-1$
    }//from   w  w  w . j  a  v a2s .c  om
    buf.deleteCharAt(buf.length() - 2);
    buf.append(" | score= " + score);//$NON-NLS-1$
    buf.append(" ->" + scores).append("| nb match=").append(nbMatch).append("/").append(record.length);//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    return buf.toString();
}

From source file:cn.remex.core.util.StringUtils.java

/**
 *  //from   w  w  w . ja v a 2 s  .c om
 * Trim <i>all</i> whitespace from the given String:
 * leading, trailing, and inbetween characters.
 * @param str the String to check  ?? 
 * @return the trimmed String ??
 * @see java.lang.Character#isWhitespace
 */
public static String trimAllWhitespace(final String str) {
    if (!hasLength(str)) {
        return str;
    }
    StringBuffer buf = new StringBuffer(str);
    int index = 0;
    while (buf.length() > index) {
        if (Character.isWhitespace(buf.charAt(index))) {
            buf.deleteCharAt(index);
        } else {
            index++;
        }
    }
    return buf.toString();
}

From source file:org.j2free.util.ServletUtils.java

/**
 * Redirects the user to the current url over HTTP
 *
 * @param request a HttpServletRequest/*w ww  .  j  a  va 2 s  .  c  o  m*/
 * @param response a HttpServletResponse
 * @param nonSslPort the port Non-SSL requests should be forwarded to
 * @throws ServletException
 * @throws IOException
 */
public static void redirectOverNonSSL(HttpServletRequest request, HttpServletResponse response, int nonSslPort)
        throws ServletException, IOException {

    StringBuffer url = request.getRequestURL();

    // Make sure we're on http
    if (url.charAt(4) == 's')
        url.deleteCharAt(4);

    // If there is a non-ssl port, make sure we're on it,
    // otherwise assume we're already on the right port
    if (nonSslPort > 0) {
        int portStart = url.indexOf(":", 8) + 1;
        int portEnd = url.indexOf("/", 8);

        if (portEnd == -1) // If their isn't a trailing slash, then the end is the last char
            portEnd = url.length() - 1;

        if (portStart > 0 && portStart < portEnd) { // If we detected a : before the trailing slash or end of url, delete the port
            url.delete(portStart, portEnd);
        } else {
            url.insert(portEnd, ':'); // If the url didn't have a port, add in the :
            portStart = portEnd;
        }

        url.insert(portStart, nonSslPort); // Insert the right port where it should be
    }

    LogFactory.getLog(ServletUtils.class).debug("redirectOverSSL sending 301: " + url.toString());
    sendPermanentRedirect(response, url.toString());
}

From source file:org.j2free.util.ServletUtils.java

/**
 * Redirects the user to the current url over HTTPS
 *
 * @param request a HttpServletRequest/*from   www.  j  a v a  2 s .  c  o m*/
 * @param response a HttpServletResponse
 * @param urlStr 
 * @param nonSslPort the port Non-SSL requests should be forwarded to
 * @throws ServletException
 * @throws IOException
 */
public static void redirectOverNonSSL(HttpServletRequest request, HttpServletResponse response, String urlStr,
        int nonSslPort) throws ServletException, IOException {

    StringBuffer url = new StringBuffer(urlStr);

    // Make sure we're on http
    if (url.charAt(4) == 's')
        url.deleteCharAt(4);

    // If there is a non-ssl port, make sure we're on it,
    // otherwise assume we're already on the right port
    if (nonSslPort > 0) {
        int portStart = url.indexOf(":", 8) + 1;
        int portEnd = url.indexOf("/", 8);

        if (portEnd == -1) // If their isn't a trailing slash, then the end is the last char
            portEnd = url.length() - 1;

        if (portStart > 0 && portStart < portEnd) { // If we detected a : before the trailing slash or end of url, delete the port
            url.delete(portStart, portEnd);
        } else {
            url.insert(portEnd, ':'); // If the url didn't have a port, add in the :
            portStart = portEnd;
        }

        url.insert(portStart, nonSslPort); // Insert the right port where it should be
    }

    LogFactory.getLog(ServletUtils.class).debug("redirectOverSSL sending 301: " + url.toString());
    sendPermanentRedirect(response, url.toString());
}

From source file:com.fantasia.snakerflow.engine.SnakerHelper.java

private static String getProperty(NodeModel node) {
    StringBuffer buffer = new StringBuffer();
    buffer.append("props:{");
    try {/*  w  w w . ja  va 2  s  .co  m*/
        PropertyDescriptor[] beanProperties = PropertyUtils.getPropertyDescriptors(node);
        for (PropertyDescriptor propertyDescriptor : beanProperties) {
            if (propertyDescriptor.getReadMethod() == null || propertyDescriptor.getWriteMethod() == null)
                continue;
            String name = propertyDescriptor.getName();
            String value = "";
            if (propertyDescriptor.getPropertyType() == String.class) {
                value = (String) BeanUtils.getProperty(node, name);
            } else {
                continue;
            }
            if (value == null || value.equals(""))
                continue;
            buffer.append(name);
            buffer.append(":{value:'");
            buffer.append(convert(value));
            buffer.append("'},");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    buffer.deleteCharAt(buffer.length() - 1);
    buffer.append("}}");
    return buffer.toString();
}

From source file:org.wso2.carbon.identity.relyingparty.RelyingPartyData.java

private List<String>[] readBlackWhiteList(String paramString) {
    List<String>[] dnList = null;
    String[] array = paramString.split("\\},\\{");

    if (array != null) {
        if ((array.length > 1) && array[0].startsWith("{")) {
            StringBuffer buff = new StringBuffer(array[0]);
            buff.deleteCharAt(0);
            array[0] = buff.toString();//w w  w . ja  v  a  2  s  .c  o m
        }
        int lastIndex = array.length - 1;
        if ((array.length > 1) && array[lastIndex].endsWith("}")) {
            StringBuffer buff = new StringBuffer(array[lastIndex]);
            buff.deleteCharAt(buff.length() - 1);
            array[lastIndex] = buff.toString();
        }

        dnList = new List[array.length];
        for (int i = 0; i < array.length; i++) {
            List<String> lst = IssuerCertificateUtil.getDNOfIssuer(array[i]);
            dnList[i] = lst;
        }
    }
    return dnList;
}