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.naryx.tagfusion.cfm.document.cfDOCUMENT.java

private static String escapeHtmlChars(String content) {
    char[] old = new char[] { '&', '<', '>', '\"' };
    String[] replacements = new String[] { "&amp;", "&lt;", "&gt;", "&quot;" };

    int strLen = content.length();
    int charsLen = old.length;
    StringBuilder buffer = new StringBuilder(content);
    StringBuilder writer = new StringBuilder(strLen);
    char nextChar;
    boolean foundCh;

    for (int i = 0; i < strLen; i++) {
        nextChar = buffer.charAt(i);
        foundCh = false;/*w ww  . ja v a 2 s.  c  o m*/

        for (int j = 0; j < charsLen; j++) {
            if (nextChar == old[j]) {
                writer.append(replacements[j]);
                foundCh = true;
            }
        }
        if (!foundCh) {
            writer.append(nextChar);
        }
    }

    return writer.toString();//.Replace("\n", "<br>");
}

From source file:com.openteach.diamond.network.waverider.master.MasterState.java

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("{id:");
    sb.append(id);/*from   ww w.ja va2s .com*/
    sb.append(", ip:");
    sb.append(ip);
    sb.append(", port:");
    sb.append(port);
    sb.append(", sessionStateList:{");
    for (SessionState sessionState : sessionStateList) {
        sb.append("sessionState:");
        sb.append(sessionState);
        sb.append(",");
    }
    if (sb.charAt(sb.length() - 1) == ',') {
        sb.deleteCharAt(sb.length() - 1);
    }
    sb.append("}");
    sb.append("}");

    return sb.toString();
}

From source file:net.sourceforge.fenixedu.domain.accounting.PaymentCode.java

public String getFormattedCode() {
    final StringBuilder result = new StringBuilder();
    int i = 1;/*from  w w  w.jav a2  s  .c  om*/
    for (char character : getCode().toCharArray()) {
        result.append(character);
        if (i % 3 == 0) {
            result.append(" ");
        }
        i++;
    }

    return result.charAt(result.length() - 1) == ' ' ? result.deleteCharAt(result.length() - 1).toString()
            : result.toString();
}

From source file:de.tudarmstadt.ukp.clarin.webanno.conllu.ConllUReader.java

public void convert(JCas aJCas, BufferedReader aReader) throws IOException {
    if (readPos) {
        try {//w ww.  j  a  v a  2s  .  c  o  m
            posMappingProvider.configure(aJCas.getCas());
        } catch (AnalysisEngineProcessException e) {
            throw new IOException(e);
        }
    }

    JCasBuilder doc = new JCasBuilder(aJCas);

    List<String[]> words;
    while ((words = readSentence(aReader)) != null) {
        if (words.isEmpty()) {
            // Ignore empty sentences. This can happen when there are multiple end-of-sentence
            // markers following each other.
            continue;
        }

        int sentenceBegin = doc.getPosition();
        int sentenceEnd = sentenceBegin;

        int surfaceBegin = -1;
        int surfaceEnd = -1;
        String surfaceString = null;

        // Tokens, Lemma, POS
        Int2ObjectMap<Token> tokens = new Int2ObjectOpenHashMap<>();
        for (String[] word : words) {
            if (word[ID].contains("-")) {
                String[] fragments = word[ID].split("-");
                surfaceBegin = Integer.valueOf(fragments[0]);
                surfaceEnd = Integer.valueOf(fragments[1]);
                surfaceString = word[FORM];
                continue;
            }

            // Read token
            int tokenIdx = Integer.valueOf(word[ID]);
            Token token = doc.add(word[FORM], Token.class);
            tokens.put(tokenIdx, token);
            if (!StringUtils.contains(word[MISC], "SpaceAfter=No")) {
                doc.add(" ");
            }

            // Read lemma
            if (!UNUSED.equals(word[LEMMA]) && readLemma) {
                Lemma lemma = new Lemma(aJCas, token.getBegin(), token.getEnd());
                lemma.setValue(word[LEMMA]);
                lemma.addToIndexes();
                token.setLemma(lemma);
            }

            // Read part-of-speech tag
            if (!UNUSED.equals(word[POSTAG]) && readPos) {
                Type posTag = posMappingProvider.getTagType(word[POSTAG]);
                POS pos = (POS) aJCas.getCas().createAnnotation(posTag, token.getBegin(), token.getEnd());
                pos.setPosValue(word[POSTAG]);
                pos.addToIndexes();
                token.setPos(pos);
            }

            // Read morphological features
            if (!UNUSED.equals(word[FEATS]) && readMorph) {
                MorphologicalFeatures morphtag = new MorphologicalFeatures(aJCas, token.getBegin(),
                        token.getEnd());
                morphtag.setValue(word[FEATS]);
                morphtag.addToIndexes();
                token.setMorph(morphtag);

                // Try parsing out individual feature values. Since the DKPro Core
                // MorphologicalFeatures type is based on the definition from the UD project,
                // we can do this rather straightforwardly.
                Type morphType = morphtag.getType();
                String[] items = word[FEATS].split("\\|");
                for (String item : items) {
                    String[] keyValue = item.split("=");
                    StringBuilder key = new StringBuilder(keyValue[0]);
                    key.setCharAt(0, Character.toLowerCase(key.charAt(0)));
                    String value = keyValue[1];

                    Feature feat = morphType.getFeatureByBaseName(key.toString());
                    if (feat != null) {
                        morphtag.setStringValue(feat, value);
                    }
                }
            }

            // Read surface form
            if (tokenIdx == surfaceEnd) {
                int begin = tokens.get(surfaceBegin).getBegin();
                int end = tokens.get(surfaceEnd).getEnd();
                SurfaceForm surfaceForm = new SurfaceForm(aJCas, begin, end);
                surfaceForm.setValue(surfaceString);
                surfaceForm.addToIndexes();
                surfaceBegin = -1;
                surfaceEnd = -1;
                surfaceString = null;
            }

            sentenceEnd = token.getEnd();
        }

        // Dependencies
        if (readDependency) {
            for (String[] word : words) {
                if (!UNUSED.equals(word[DEPREL])) {
                    int depId = Integer.valueOf(word[ID]);
                    int govId = Integer.valueOf(word[HEAD]);

                    // Model the root as a loop onto itself
                    makeDependency(aJCas, govId, depId, word[DEPREL], DependencyFlavor.BASIC, tokens, word);
                }

                if (!UNUSED.equals(word[DEPS])) {
                    // list items separated by vertical bar
                    String[] items = word[DEPS].split("\\|");
                    for (String item : items) {
                        String[] sItem = item.split(":");

                        int depId = Integer.valueOf(word[ID]);
                        int govId = Integer.valueOf(sItem[0]);

                        makeDependency(aJCas, govId, depId, sItem[1], DependencyFlavor.ENHANCED, tokens, word);
                    }
                }
            }
        }

        // Sentence
        Sentence sentence = new Sentence(aJCas, sentenceBegin, sentenceEnd);
        sentence.addToIndexes();

        // Once sentence per line.
        doc.add("\n");
    }

    doc.close();
}

From source file:com.hardincoding.sonar.subsonic.service.SubsonicMusicService.java

public String getRestUrl(String method) {
    StringBuilder builder = new StringBuilder();
    String serverUrl = mServerAddress;
    builder.append(serverUrl);/*  w  w  w  . j a  v  a2  s .com*/
    if (builder.charAt(builder.length() - 1) != '/') {
        builder.append("/");
    }
    builder.append("rest/").append(method).append(".view");
    builder.append("?u=").append(mUsername);
    String password = "enc:" + Util.utf8HexEncode(mPassword);
    builder.append("&p=").append(password);
    builder.append("&v=").append(REST_PROTOCOL_VERSION);
    builder.append("&c=").append(REST_CLIENT_ID);
    return builder.toString();
}

From source file:au.org.ala.delta.directives.DirectiveParser.java

private String readWord(StringBuilder buf, int start, boolean ignoreLeadingSpace) {
    int i = start;
    StringBuilder b = new StringBuilder();

    if (ignoreLeadingSpace) {
        while (i < buf.length()) {
            char ch = buf.charAt(i++);
            if (_blank.indexOf(ch) < 0) {
                --i;/*from   ww w .j  a v  a  2  s .c o m*/
                break;
            }
        }
    }

    while (i < buf.length()) {
        char ch = buf.charAt(i++);
        if (_blank.indexOf(ch) >= 0) {
            return b.toString();
        } else {
            b.append(ch);
        }
    }
    return b.toString();
}

From source file:de.itsvs.cwtrpc.security.AbstractRpcProcessingFilter.java

protected boolean matchesFilterProcessesUrl(HttpServletRequest request) throws IOException, ServletException {
    final String contextPath;
    final StringBuilder sb;
    final String uri;

    contextPath = request.getContextPath();
    sb = new StringBuilder(request.getRequestURI());
    if ((contextPath.length() > 0) && (sb.indexOf(contextPath) == 0)) {
        sb.delete(0, contextPath.length());
    }// w  w w  . j a v  a  2 s  . c  o  m
    if ((sb.length() == 0) || (sb.charAt(0) != '/')) {
        sb.insert(0, '/');
    }
    uri = sb.toString();

    if (log.isDebugEnabled()) {
        log.debug(
                "Checking received URI '" + uri + "' against configured URI '" + getFilterProcessesUrl() + "'");
    }
    return getFilterProcessesUrl().equals(uri);
}

From source file:com.intuit.tank.http.BaseRequestHandler.java

public static String getQueryString(Map<String, String> urlVariables) {

    StringBuilder queryString = new StringBuilder();

    // Set the query string
    if (urlVariables != null) {
        if (!urlVariables.isEmpty()) {

            queryString.append("?");

            // Set<Map.Entry<String, String>> set = urlVariables.entrySet();
            // Iterator<Map.Entry<String, String>> iterator =
            // set.iterator();
            for (Entry<String, String> entry : urlVariables.entrySet()) {
                try {
                    StringBuilder nvp = new StringBuilder();
                    nvp.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
                    if (entry.getValue() != null) {
                        nvp.append("=");
                        nvp.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
                    }/*  www  . j av a  2  s  .  c o m*/
                    nvp.append("&");
                    queryString.append(nvp.toString());

                } catch (Exception ex) {
                    logger.warn(LogUtil.getLogMessage("Unable to set query string value: " + ex.getMessage(),
                            LogEventType.System));
                }
            }
        }
    }

    // Remove the last &
    String reqQueryString = "";
    if (queryString.length() > 0) {
        if (queryString.charAt(queryString.length() - 1) == '&')
            reqQueryString = queryString.deleteCharAt(queryString.length() - 1).toString();
        else
            reqQueryString = queryString.toString();
    }

    return reqQueryString;
}

From source file:nl.nn.ibistesttool.tibet2.Storage.java

private void addExpression(StringBuilder query, String expression) {
    if (query.charAt(query.length() - 1) == ' ') {
        query.append("and " + expression + " ");
    } else {// w ww  . j av a 2 s  .co m
        query.append(" where " + expression + " ");
    }
}