Example usage for java.lang StringBuilder charAt

List of usage examples for java.lang StringBuilder charAt

Introduction

In this page you can find the example usage for java.lang StringBuilder charAt.

Prototype

char charAt(int index);

Source Link

Document

Returns the char value at the specified index.

Usage

From source file:net.sourceforge.vulcan.jabber.JabberBuildStatusListener.java

String generateBuildReportUrl(String view) {
    final StringBuilder sb = new StringBuilder(getVulcanUrl());
    if (sb.charAt(sb.length() - 1) != '/') {
        sb.append('/');
    }// ww w.  j  a va 2  s  .  c o m
    sb.append("projects/");

    try {
        sb.append(URLEncoder.encode(status.getName(), "utf-8"));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }

    sb.append("/");
    sb.append(status.getBuildNumber());
    sb.append("/");
    sb.append(view);

    String url = sb.toString();
    return url;
}

From source file:org.alfresco.repo.action.executer.TransformActionExecuter.java

/**
 * Transform a name from original extension to new extension, if appropriate.
 * If the original name seems to end with a reasonable file extension, then the name
 * will be transformed such that the old extension is replaced with the new.
 * Otherwise the name will be returned unaltered.
 * <P/>//from   www .  ja v  a  2s .  c  o m
 * The original name will be deemed to have a reasonable extension if there are one
 * or more characters after the (required) final dot, none of which are spaces.
 * 
 * @param mimetypeService the mimetype service
 * @param original the original name
 * @param newMimetype the new mime type
 * @param alwaysAdd if the name has no extension, then add the new one
 * 
 * @return name with new extension as appropriate for the mimetype
 */
public static String transformName(MimetypeService mimetypeService, String original, String newMimetype,
        boolean alwaysAdd) {
    // get the current extension
    int dotIndex = original.lastIndexOf('.');
    StringBuilder sb = new StringBuilder(original.length());
    if (dotIndex > -1) {
        // we found it
        String nameBeforeDot = original.substring(0, dotIndex);
        String originalExtension = original.substring(dotIndex + 1, original.length());

        // See ALF-1937, which actually relates to cm:title not cm:name.
        // It is possible that the text after the '.' is not actually an extension
        // in which case it should not be replaced.
        boolean originalExtensionIsReasonable = isExtensionReasonable(originalExtension);
        String newExtension = mimetypeService.getExtension(newMimetype);
        if (originalExtensionIsReasonable) {
            sb.append(nameBeforeDot);
            sb.append('.').append(newExtension);
        } else {
            sb.append(original);
            if (alwaysAdd == true) {
                if (sb.charAt(sb.length() - 1) != '.') {
                    sb.append('.');
                }
                sb.append(newExtension);
            }
        }
    } else {
        // no extension so don't add a new one
        sb.append(original);

        if (alwaysAdd == true) {
            // add the new extension - defaults to .bin
            String newExtension = mimetypeService.getExtension(newMimetype);
            sb.append('.').append(newExtension);
        }
    }
    // done
    return sb.toString();
}

From source file:org.obiba.onyx.core.service.impl.ConfigurablePasswordValidationStrategyImpl.java

private StringBuilder removeLastCommaFromList(StringBuilder sb) {
    if (sb.length() == 0)
        return sb;
    if (sb.charAt(sb.length() - 1) == ',') {
        sb.setLength(sb.length() - 1);//from   ww  w. ja  v a  2  s  .c  o m
    }
    return sb;
}

From source file:ca.uhn.fhir.rest.client.apache.ApacheHttpClient.java

private StringBuilder newHeaderBuilder(StringBuilder theUrlBase) {
    StringBuilder b = new StringBuilder();
    b.append(theUrlBase);/*from w ww.  j a  v  a2s  .  c o  m*/
    if (theUrlBase.length() > 0 && theUrlBase.charAt(theUrlBase.length() - 1) == '/') {
        b.deleteCharAt(b.length() - 1);
    }
    return b;
}

From source file:org.batoo.common.util.StringUtils.java

/**
 * Trim all occurences of the supplied leading character from the given String.
 * /*  w  w w  . ja  v  a  2  s.  c  o m*/
 * @param str
 *            the String to check
 * @param leadingCharacter
 *            the leading character to be trimmed
 * @return the trimmed String
 */
public static String trimLeadingCharacter(String str, char leadingCharacter) {
    if (!StringUtils.hasLength(str)) {
        return str;
    }
    final StringBuilder sb = new StringBuilder(str);
    while ((sb.length() > 0) && (sb.charAt(0) == leadingCharacter)) {
        sb.deleteCharAt(0);
    }
    return sb.toString();
}

From source file:org.batoo.common.util.StringUtils.java

/**
 * Trim all occurences of the supplied trailing character from the given String.
 * /*from  w  w  w . ja  v  a2  s  .  co m*/
 * @param str
 *            the String to check
 * @param trailingCharacter
 *            the trailing character to be trimmed
 * @return the trimmed String
 */
public static String trimTrailingCharacter(String str, char trailingCharacter) {
    if (!StringUtils.hasLength(str)) {
        return str;
    }
    final StringBuilder sb = new StringBuilder(str);
    while ((sb.length() > 0) && (sb.charAt(sb.length() - 1) == trailingCharacter)) {
        sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
}

From source file:de.highbyte_le.weberknecht.request.taglibs.SiteBaseLinkTag.java

protected String getBaseUrl() throws JspException {

    if (!(pageContext.getRequest() instanceof HttpServletRequest))
        throw new JspException("unable to get a HttpServletRequest");

    StringBuilder baseUrl = new StringBuilder();

    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

    try {/*from ww  w  .ja v  a 2  s.  c  om*/
        ContextConfig conf = new ContextConfig();
        baseUrl.append(conf.getValue("webapp_base_url"));

        if (baseUrl.charAt(baseUrl.length() - 1) != '/')
            baseUrl.append("/");
    } catch (NamingException e) {
        logger.error("getTokenUrl() - naming exception while fetching webapp_base_url: " + e.getMessage()); //$NON-NLS-1$

        logger.warn("automatically generating base URL");
        String contextPath = request.getContextPath();
        String localHost = request.getLocalName();
        int localPort = request.getLocalPort();

        if (baseUrl.length() > 0) //just to be sure
            baseUrl = new StringBuilder();

        baseUrl.append("http://").append(localHost).append(":").append(localPort + contextPath).append("/");
    }

    return baseUrl.toString();
}

From source file:com.orange.wro.taglib.tag.AsJsArrayIncludeTag.java

@Override
protected void writeEnd(StringBuilder builder) {
    int length = builder.length();
    if (length == 0) {
        throw new AssertionError(
                "The builder length is zero. This should not happen as we normally append something at the very beginning.");
    }/*from w  w w  . j a va  2  s. co m*/

    try {
        if (builder.charAt(length - 1) == ',') {
            // will be false if we didn't add any file
            builder.deleteCharAt(length - 1);
        }
    } catch (IndexOutOfBoundsException e) {
        // must not happen as we check before
        throw new AssertionError(
                "deleteCharAt triggered a StringIndexOutOfBoundsException, which should not happen.");
    }

    builder.append("]");
}

From source file:edu.chalmers.dat076.moviefinder.service.TitleParser.java

/**
 * Check if mySb has the potential to contain an episode of some series. It
 * is assumed that vital season information is available in index 0.
 *
 * @param mySb//from   w w w.  ja  v  a2 s .co  m
 * @return true if mySb contains season and episode information
 */
public boolean getEpisodePotential(StringBuilder mySb) {

    if (mySb.length() >= 4 && (mySb.charAt(0) == 'S' || mySb.charAt(0) == 's')) {

        if (Character.isDigit(mySb.charAt(1))) {
            if (Character.isDigit(mySb.charAt(3)) && (mySb.charAt(2) == 'E' || mySb.charAt(2) == 'e')) {
                return true; // SxEx
            } else if (mySb.length() >= 6 && (Character.isDigit(mySb.charAt(2))
                    && Character.isDigit(mySb.charAt(4)) && (mySb.charAt(3) == 'E' || mySb.charAt(3) == 'e'))) {
                return true; //SxxEx
            }
        } else if (mySb.length() > 13 && mySb.substring(0, 6).equalsIgnoreCase("season")) {
            for (int i = 6; i < mySb.length() - 7; i++) {
                if (mySb.substring(i, i + 7).equalsIgnoreCase("episode")) {
                    return true; // season ... episode
                }
            }
        }
    } else if (mySb.length() >= 3 && Character.isDigit(mySb.charAt(0))) {
        if ((Character.isDigit(mySb.charAt(2)) && (mySb.charAt(1) == 'x' || mySb.charAt(1) == 'X'))
                || (mySb.length() >= 4 && Character.isDigit(mySb.charAt(1)) && Character.isDigit(mySb.charAt(3))
                        && (mySb.charAt(2) == 'x' || mySb.charAt(2) == 'X'))) {
            return true; // xXx xxXx
        }
    }
    return false;
}

From source file:org.batoo.common.util.StringUtils.java

/**
 * Trim leading whitespace from the given String.
 * /*from  www. j  a  va  2  s .c  om*/
 * @param str
 *            the String to check
 * @return the trimmed String
 * @see java.lang.Character#isWhitespace
 */
public static String trimLeadingWhitespace(String str) {
    if (!StringUtils.hasLength(str)) {
        return str;
    }
    final StringBuilder sb = new StringBuilder(str);
    while ((sb.length() > 0) && Character.isWhitespace(sb.charAt(0))) {
        sb.deleteCharAt(0);
    }
    return sb.toString();
}