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.fenixedu.domain.candidacyProcess.erasmus.StorkAttributesList.java

private String convertToString(Set<StorkAttributeType> types) {
    final StringBuilder result = new StringBuilder();

    for (StorkAttributeType each : types) {
        result.append(each.name()).append(",");
    }/*  w w  w  . j  a v a 2  s  .  c om*/

    if (result.length() > 0 && result.charAt(result.length() - 1) == ',') {
        result.deleteCharAt(result.length() - 1);
    }

    return result.toString();
}

From source file:com.github.lightdocs.ModelBuilder.java

/**
 * @param p/* www.  j a v a  2  s.  c  o  m*/
 * @return the value of the path annotation, removing slash characters at
 *         the beginning and end, if any. If the annotation is empty or null, returns "".
 */
@VisibleForTesting
String standardizePathAnnotationValue(Path p) {

    if (p == null || p.value() == null || StringUtils.isBlank(p.value())) {
        return "";
    }

    StringBuilder sb = new StringBuilder(p.value().trim());

    if ((sb.length() > 1) && (sb.charAt(0) == '/')) {
        sb.deleteCharAt(0);
    }
    if ((sb.length() > 1) && (sb.charAt(sb.length() - 1) == '/')) {
        sb.deleteCharAt(sb.length() - 1);
    }

    return sb.toString();
}

From source file:com.haulmont.cuba.desktop.sys.vcl.DatePicker.DatePicker.java

protected String getMask(String format) {
    StringBuilder mask = new StringBuilder(format);
    for (int i = 0; i < mask.length(); i++) {
        char current = mask.charAt(i);
        current = Character.toLowerCase(current);
        if (current == 'd' || current == 'm' || current == 'y') {
            mask.setCharAt(i, PLACE_HOLDER);
        }/*from ww  w .  j a  v  a  2 s . c  o m*/
    }
    return mask.toString();
}

From source file:org.ambraproject.wombat.service.CommentFormatting.java

/**
 * Given a string, and the index to start looking at, find the index of the start of the scheme. Eg.
 * <pre>/*from  ww w  .  j a va 2s . c  o m*/
 * getSchemeIndex("notes://abc", 0) -> 0
 * getSchemeIndex("abc notes://abc", 0) -> 4
 * </pre>
 *
 * @param str        The string to search for
 * @param startIndex Where to start looking at
 * @return The location the string was found, ot -1 if the string was not found.
 */
private static int getSchemeIndex(StringBuilder str, int startIndex) {
    int schemeIndex = str.indexOf(SCHEME_URL, startIndex + 1);

    //if it was not found, or found at the start of the string, then return 'not found'
    if (schemeIndex <= 0) {
        return -1;
    }

    //walk backwards through the scheme until we find the first non valid character
    int schemeStart;

    for (schemeStart = schemeIndex - 1; schemeStart >= 0; schemeStart--) {
        char currentChar = str.charAt(schemeStart);

        if (!isValidSchemeChar(currentChar)) {
            break;
        }
    }

    //reset the scheme to the starting character
    schemeStart++;

    /*
         we don't want to do this, otherwise an invalid scheme would ruin the linking for later schemes
        if (isValidScheme(str.substring(schemeStart, schemeIndex)))
            return schemeStart;
        else
            return -1;
    */
    return schemeStart;
}

From source file:au.org.ala.delta.intkey.directives.IntkeyDirectiveParser.java

@Override
protected void processTrailing(StringBuilder data, IntkeyContext context) throws DirectiveException {
    if (data.length() > 0) {
        char ch = data.charAt(0);
        if (Character.isDigit(ch)) {
            DirectiveSearchResult r = getDirectiveRegistry()
                    .findDirective(new ArrayList<String>(Arrays.asList("use")));
            IntkeyDirective useDirective = (IntkeyDirective) r.getMatches().get(0);
            try {
                useDirective.parseAndProcess(context, data.toString());
            } catch (Exception ex) {
                handleDirectiveProcessingException(context, useDirective, ex);
            }/*from w ww . j a v a2 s  .  c o  m*/
        } else {
            super.processTrailing(data, context);
        }
    }
}

From source file:acromusashi.kafka.log.producer.util.StrftimeFormatMapper.java

/**
 * StrfTime?Java?DateFormat???????/*from   w w  w . j  av a2  s  . c  o m*/
 * 
 * @param strfFormat StrfTime?
 * @return Java?DateFormat????
 */
protected static String convertStrfToDateFormatStr(String strfFormat) {
    boolean inside = false;
    boolean mark = false;
    boolean modifiedCommand = false;

    StringBuilder builder = new StringBuilder();

    for (int i = 0; i < strfFormat.length(); i++) {
        char c = strfFormat.charAt(i);

        if (c == '%' && !mark) {
            mark = true;
        } else {
            if (mark) {
                if (modifiedCommand) {
                    modifiedCommand = false;
                    mark = false;
                } else {
                    inside = translateCommand(builder, strfFormat, i, inside);
                    if (c == 'O' || c == 'E') {
                        modifiedCommand = true;
                    } else {
                        mark = false;
                    }
                }
            } else {
                if (!inside && c != ' ') {
                    builder.append("'");
                    inside = true;
                }

                builder.append(c);
            }
        }
    }

    if (builder.length() > 0) {
        char lastChar = builder.charAt(builder.length() - 1);

        if (lastChar != '\'' && inside) {
            builder.append('\'');
        }
    }
    return builder.toString();
}

From source file:com.stratio.ingestion.serializer.elasticsearch.ElasticSearchSerializerWithMappingTest.java

private String trimAllWhitespace(String str) {
    if (!hasLength(str)) {
        return str;
    }/*from   w  ww .j ava 2s .c  om*/
    StringBuilder sb = new StringBuilder(str);
    int index = 0;
    while (sb.length() > index) {
        if (Character.isWhitespace(sb.charAt(index))) {
            sb.deleteCharAt(index);
        } else {
            index++;
        }
    }
    return sb.toString();
}

From source file:org.apache.hadoop.hbase.regionserver.AnnotationReadingPriorityFunction.java

private String capitalize(final String s) {
    StringBuilder strBuilder = new StringBuilder(s);
    strBuilder.setCharAt(0, Character.toUpperCase(strBuilder.charAt(0)));
    return strBuilder.toString();
}

From source file:android.syncml.pim.VDataBuilder.java

private String listToString(Collection<String> list) {
    StringBuilder typeListB = new StringBuilder();
    for (String type : list) {
        typeListB.append(type).append(";");
    }/*from   w  w w .  j  a  va 2s .com*/
    int len = typeListB.length();
    if (len > 0 && typeListB.charAt(len - 1) == ';') {
        return typeListB.substring(0, len - 1);
    }
    return typeListB.toString();
}

From source file:HashTagSegmenter.java

List<String> segmentWordsInHashTaggedToken(String text) {

    // holds crude segments from number split
    List<String> crudeSegments = new ArrayList<String>();

    // holds completely segmented tokens
    List<String> tempSegments = new ArrayList<String>();
    List<String> finalSegments = new ArrayList<String>();

    // sets the token to lower case
    StringBuilder tokenText = new StringBuilder(text.toLowerCase());

    // checks for hashtag
    if (tokenText.charAt(0) == '#') {

        // deletes the hashtag
        tokenText = tokenText.deleteCharAt(0);

        // splits the token text into crude segments when a number exists
        // eg: "iwant2eatfood" -> ['iwant', '2', 'eatfood']
        Matcher m = Pattern.compile("[\\d.]+|\\D+").matcher(tokenText);
        while (m.find()) {
            crudeSegments.add(m.group());
        }//from  w  ww .  java  2  s .  co  m

        // segments items from crude segments list
        // eg: temp[0] = ['iwant'] ->
        // segments = ['i','want']
        for (int i = 0; i < crudeSegments.size(); i++) {

            // if crude item is a number, add it to the segments list
            if (NumberUtils.isNumber(crudeSegments.get(i))) {
                finalSegments.add(crudeSegments.get(i));
            } else {

                // if crude item is not a number, segment and add each
                // new item to the segments list
                tempSegments = getSegments(crudeSegments.get(i));

                // adds new segments list to final segments
                if (tempSegments != null) {
                    for (int j = 0; j < tempSegments.size(); j++) {
                        finalSegments.add(tempSegments.get(j));
                    }
                } else {
                    // adds crude segment to list if it cannot be segmented
                    finalSegments.add(crudeSegments.get(i));
                }
            }
        }

    }

    return finalSegments;
}