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:com.geemvc.taglib.GeemvcTagSupport.java

protected String toElementId(String name, String idSuffix) {
    StringBuilder id = new StringBuilder(ELEMENT_ID_PREFIX).append(CaseFormat.UPPER_CAMEL
            .to(CaseFormat.LOWER_HYPHEN, name).replace(Char.SQUARE_BRACKET_OPEN, Char.HYPHEN)
            .replace(Char.SQUARE_BRACKET_CLOSE, Char.HYPHEN).replace(Char.DOT, Char.HYPHEN)
            .replace(Char.SPACE, Char.HYPHEN).replace(Char.UNDERSCORE, Char.HYPHEN)
            .replace(Str.HYPHEN_2x, Str.HYPHEN));

    if (id.charAt(id.length() - 1) == Char.HYPHEN)
        id.deleteCharAt(id.length() - 1);

    if (!Str.isEmpty(idSuffix)) {
        id.append(Char.HYPHEN)//from  w w  w .j  av  a2s.  c om
                .append(idSuffix.toLowerCase().replace(Char.SQUARE_BRACKET_OPEN, Char.HYPHEN)
                        .replace(Char.SQUARE_BRACKET_CLOSE, Char.HYPHEN).replace(Char.DOT, Char.HYPHEN)
                        .replace(Char.SPACE, Char.HYPHEN).replace(Char.UNDERSCORE, Char.HYPHEN)
                        .replace(Str.HYPHEN_2x, Str.HYPHEN));
    }

    if (id.charAt(id.length() - 1) == Char.HYPHEN)
        id.deleteCharAt(id.length() - 1);

    return id.toString();
}

From source file:com.cloudlbs.core.utils.DateUtil.java

/**
 * Formats the date and returns the calendar instance that was used (which
 * may be reused)//from w ww .j ava 2 s.  c o m
 */
public static Calendar formatDate(Date date, Calendar cal, Appendable out) throws IOException {
    // using a stringBuilder for numbers can be nice since
    // a temporary string isn't used (it's added directly to the
    // builder's buffer.

    StringBuilder sb = out instanceof StringBuilder ? (StringBuilder) out : new StringBuilder();
    if (cal == null)
        cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.US);
    cal.setTime(date);

    int i = cal.get(Calendar.YEAR);
    sb.append(i);
    sb.append('-');
    i = cal.get(Calendar.MONTH) + 1; // 0 based, so add 1
    if (i < 10)
        sb.append('0');
    sb.append(i);
    sb.append('-');
    i = cal.get(Calendar.DAY_OF_MONTH);
    if (i < 10)
        sb.append('0');
    sb.append(i);
    sb.append('T');
    i = cal.get(Calendar.HOUR_OF_DAY); // 24 hour time format
    if (i < 10)
        sb.append('0');
    sb.append(i);
    sb.append(':');
    i = cal.get(Calendar.MINUTE);
    if (i < 10)
        sb.append('0');
    sb.append(i);
    sb.append(':');
    i = cal.get(Calendar.SECOND);
    if (i < 10)
        sb.append('0');
    sb.append(i);
    i = cal.get(Calendar.MILLISECOND);
    if (i != 0) {
        sb.append('.');
        if (i < 100)
            sb.append('0');
        if (i < 10)
            sb.append('0');
        sb.append(i);

        // handle canonical format specifying fractional
        // seconds shall not end in '0'. Given the slowness of
        // integer div/mod, simply checking the last character
        // is probably the fastest way to check.
        int lastIdx = sb.length() - 1;
        if (sb.charAt(lastIdx) == '0') {
            lastIdx--;
            if (sb.charAt(lastIdx) == '0') {
                lastIdx--;
            }
            sb.setLength(lastIdx + 1);
        }

    }
    sb.append('Z');

    if (out != sb)
        out.append(sb);

    return cal;
}

From source file:de.itsvs.cwtrpc.controller.RemoteServiceControllerServlet.java

protected PreparedRemoteServiceConfig getServiceConfig(HttpServletRequest request) {
    final String contextPath;
    final StringBuilder uri;
    final PreparedRemoteServiceConfig serviceConfig;

    contextPath = request.getContextPath();
    uri = new StringBuilder(request.getRequestURI());
    if ((contextPath.length() > 0) && (uri.indexOf(contextPath) == 0)) {
        uri.delete(0, contextPath.length());
    }//from   w w  w  . j  a  v  a2 s  .  com
    if ((uri.length() > 0) || (uri.charAt(0) == '/')) {
        uri.deleteCharAt(0);
    }

    if (log.isDebugEnabled()) {
        log.debug("Service URI is '" + uri + "'");
    }
    serviceConfig = getServiceConfigsByUri().get(uri.toString());

    return serviceConfig;
}

From source file:com.legstar.pli2cob.util.CobolNameResolver.java

/**
 * Creates a new string built from each valid character from name.
 * @param name the proposed name with potentially invalid characters
 * @return a name that is guaranteed to contain only valid characters
 *///from   w w w .  j  a  v a  2  s  .com
private String switchCharacters(final String name) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < name.length(); i++) {
        boolean valid = false;
        for (int j = 0; j < mC.length; j++) {
            if (name.charAt(i) == mC[j]) {
                sb.append(name.charAt(i));
                valid = true;
                break;
            }
        }
        /* Ignore invalid characters unless it is an
         * underscore */
        if (!valid && name.charAt(i) == '_') {
            sb.append('-');
        }
    }

    /* Check first and last characters */
    while (sb.length() > 0 && !isValidFirst(sb.charAt(0))) {
        sb.deleteCharAt(0);
    }
    while (sb.length() > 0 && !isValidLast(sb.charAt(sb.length() - 1))) {
        sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
}

From source file:org.apache.pig.builtin.OrcStorage.java

private String getReqiredColumnNamesString(ResourceSchema schema) {
    StringBuilder sb = new StringBuilder();
    for (ResourceFieldSchema field : schema.getFields()) {
        sb.append(field.getName()).append(",");
    }//from  ww  w .j  a  v  a  2s  . com
    if (sb.charAt(sb.length() - 1) == ',') {
        sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
}

From source file:com.google.testing.pogen.generator.template.TemplateUpdaterWithClassAttribute.java

protected StringBuilder buildModifiedTag(String template, HtmlTagInfo tagInfo) {
    StringBuilder tag = new StringBuilder(template.substring(tagInfo.getStartIndex(), tagInfo.getEndIndex()));
    tagInfo.setAttributeValue(generateUniqueValue());
    if (tagInfo.hasAttributeValue()) {
        int space = StringUtils.indexOfAny(tag, ' ', '\t', '\r', '\n');
        int equal;
        while (space > 0 && (equal = StringUtils.indexOf(tag, '=', space + 1)) > 0) {
            String name = tag.substring(space + 1, equal).trim();
            int leftQuote = StringUtils.indexOfAny(tag.substring(space + 1), '"', '\'') + space + 1;
            if (name.equals("class")) {
                tag.insert(leftQuote + 1, tagInfo.getAttributeValue() + " ");
                return tag;
            }/*www . ja v a2s .c  o  m*/
            space = StringUtils.indexOf(tag, tag.charAt(leftQuote), leftQuote + 1) + 1;
        }
    }
    // Deal with closed tag such as <br />
    int insertIndex = tag.length() - 2;
    String tail = ">";
    if (tag.charAt(insertIndex) == '/') {
        --insertIndex;
        tail = " />";
    }
    // Remove redundant space
    while (tag.charAt(insertIndex) == ' ') {
        insertIndex--;
    }
    // Insert the generated id attribute
    tag.setLength(insertIndex + 1);
    tag.append(" class=\"" + tagInfo.getAttributeValue() + "\"" + tail);
    return tag;
}

From source file:com.evolveum.midpoint.task.quartzimpl.work.segmentation.StringWorkSegmentationStrategy.java

private String expand(String s) {
    StringBuilder sb = new StringBuilder();
    Scanner scanner = new Scanner(s);

    while (scanner.hasNext()) {
        if (scanner.isDash()) {
            if (sb.length() == 0) {
                throw new IllegalArgumentException("Boundary specification cannot start with '-': " + s);
            } else {
                scanner.next();/*from   ww w  . j av a2s.co  m*/
                if (!scanner.hasNext()) {
                    throw new IllegalArgumentException("Boundary specification cannot end with '-': " + s);
                } else {
                    appendFromTo(sb, sb.charAt(sb.length() - 1), scanner.next());
                }
            }
        } else {
            sb.append(scanner.next());
        }
    }
    String expanded = sb.toString();
    if (marking == INTERVAL) {
        checkBoundary(expanded);
    }
    return expanded;
}

From source file:org.beangle.struts2.convention.route.Profile.java

/**
 * ???.?/<br>/*from w  w w .  j  a v  a 2  s  . co m*/
 * ?/
 * 
 * @param clazz
 * @param profile
 * @return
 */
public String getInfix(String className) {
    String postfix = getActionSuffix();
    String simpleName = className.substring(className.lastIndexOf('.') + 1);
    if (StringUtils.contains(simpleName, postfix)) {
        simpleName = StringUtils.uncapitalize(simpleName.substring(0, simpleName.length() - postfix.length()));
    } else {
        simpleName = StringUtils.uncapitalize(simpleName);
    }

    MatchInfo match = getCtlMatchInfo(className);
    StringBuilder infix = new StringBuilder(match.getReserved().toString());
    if (infix.length() > 0) {
        infix.append('.');
    }
    String remainder = StringUtils.substring(StringUtils.substringBeforeLast(className, "."),
            match.getStartIndex() + 1);
    if (remainder.length() > 0) {
        infix.append(remainder).append('.');
    }
    if (infix.length() == 0)
        return simpleName;
    infix.append(simpleName);

    // .??/
    for (int i = 0; i < infix.length(); i++) {
        if (infix.charAt(i) == '.') {
            infix.setCharAt(i, '/');
        }
    }
    return infix.toString();
}

From source file:geogebra.common.kernel.implicit.GeoImplicitPoly.java

private static void appendMultiply(StringBuilder sb) {

    if (sb.length() == 0) {
        return;//from   www. ja  va  2  s .  c  om
    }

    char ch = sb.charAt(sb.length() - 1);

    if (ch != '*' && ch != ' ') {
        sb.append('*');
    }

}

From source file:de.micromata.genome.gwiki.page.gspt.ExtendedTemplate.java

/**
 * Replace el inline expressions.//from  www.j ava 2  s. c om
 *
 * @param elements the elements
 * @param elIdx the el idx
 * @return the int
 */
private int replaceElInlineExpressions(List<ParseElement> elements, int elIdx) {
    if (elements.get(elIdx).text.indexOf("${") == -1)
        return elIdx;

    StringBuilder sb = elements.get(elIdx).text;
    elements.remove(elIdx);

    for (int i = 0; i < sb.length(); ++i) {
        char c = sb.charAt(i);
        if (c == '$' && sb.length() > i + 1 && sb.charAt(i + 1) == '{') {
            int startIdx = i;
            int endIdx = -1;
            i += 2;
            for (; i < sb.length(); ++i) {
                if (sb.charAt(i) == '}') {
                    endIdx = i;
                    break;
                }
            }
            if (endIdx == -1)
                continue;
            String rt = sb.substring(0, startIdx);
            elements.add(elIdx++, new ParseElement(Type.ConstString, rt));

            String text = sb.substring(startIdx, endIdx + 1);

            String r = "TagSupport.printEvalInlineElExpression(pageContext, \"\\" + escapeLiteral(text)
                    + "\");";
            elements.add(elIdx++, new ParseElement(Type.Statement, r));
            sb.replace(0, endIdx + 1, "");
            i = 0;
        }
    }
    if (sb.length() > 0)
        elements.add(elIdx++, new ParseElement(Type.ConstString, sb.toString()));
    return elIdx;
}