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.joinedminds.masserr.Functions.java

public static String constructPath(String... items) {
    StringBuilder str = new StringBuilder();
    for (String it : items) {
        if (!isEmpty(it)) {
            if (str.length() > 0 && str.charAt(str.length() - 1) != '/') {
                str.append('/');
            }//w  w w  .  j a v  a 2 s .  c o  m
            str.append(it.trim());
        }
    }
    return str.toString();
}

From source file:com.indoqa.lang.util.StringUtils.java

public static String escapeSolr(String value) {
    StringBuilder stringBuilder = new StringBuilder(value);

    for (int i = 0; i < stringBuilder.length(); i++) {
        boolean isCharacterToBeEscaped = Arrays.binarySearch(CHARACTERS_TO_BE_ESCAPED_FOR_SOLR,
                stringBuilder.charAt(i)) >= 0;
        if (isCharacterToBeEscaped) {
            stringBuilder.insert(i, '\\');
            i++;/* w  w w  .  j  av  a  2 s  .  c  om*/
        }
    }

    return stringBuilder.toString();
}

From source file:com.google.gitiles.doc.TocFormatter.java

private static String idFromTitle(String title) {
    StringBuilder b = new StringBuilder(title.length());
    for (char c : StringUtils.stripAccents(title).toCharArray()) {
        if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9')) {
            b.append(c);/*  ww  w  . j  ava 2s. c o  m*/
        } else if (c == ' ') {
            if (b.length() > 0 && b.charAt(b.length() - 1) != '-' && b.charAt(b.length() - 1) != '_') {
                b.append('-');
            }
        } else if (b.length() > 0 && b.charAt(b.length() - 1) != '-' && b.charAt(b.length() - 1) != '_') {
            b.append('_');
        }
    }
    while (b.length() > 0) {
        char c = b.charAt(b.length() - 1);
        if (c == '-' || c == '_') {
            b.setLength(b.length() - 1);
            continue;
        }
        break;
    }
    return b.toString();
}

From source file:Main.java

protected static void writeXMLwalkTree(Node node, int indent, PrintWriter out) {
    if (node == null)
        throw new NullPointerException("Null node passed to writeXMLwalkTree()");
    if (node.hasChildNodes()) {
        if (node instanceof Element) {
            Element elem = (Element) node;
            //elem.normalize();
            out.print("\n");
            for (int j = 0; j < indent; j++) {
                out.print(" ");
            }//w ww.  j  av a  2  s  .  c  om
            out.print("<" + elem.getTagName());
            NamedNodeMap attrs = elem.getAttributes();
            for (int i = 0; i < attrs.getLength(); i++) {
                Attr a = (Attr) attrs.item(i);
                out.print(" " + a.getName() + "=\"" + a.getValue() + "\"");
            }
            out.print(">");
            NodeList nl = node.getChildNodes();
            for (int i = 0; i < nl.getLength(); i++) {
                writeXMLwalkTree(nl.item(i), indent + 2, out);
            }
            //              for(int j=0;j<indent;j++) {
            //                  out.print(" ");
            //              }
            out.println("</" + elem.getTagName() + ">");
        }
    } else {
        if (node instanceof Element) {
            Element elem = (Element) node;
            out.print("\n");
            for (int j = 0; j < indent; j++) {
                out.print(" ");
            }
            out.print("<" + elem.getTagName());
            NamedNodeMap attrs = elem.getAttributes();
            for (int i = 0; i < attrs.getLength(); i++) {
                Attr a = (Attr) attrs.item(i);
                out.print(" " + a.getName() + "=\"" + a.getValue() + "\"");
            }
            out.println("/>");
        } else if (node instanceof CDATASection) {
            CDATASection cdata = (CDATASection) node;
            //              for(int j=0;j<indent;j++) {
            //                  out.print(" ");
            //              }
            out.print("<![CDATA[" + cdata.getData() + "]]>");
        } else if (node instanceof Text) {
            Text text = (Text) node;
            StringBuilder buf = new StringBuilder(text.getData().length());
            for (int i = 0; i < text.getData().length(); i++) {
                if (text.getData().charAt(i) == '\n' || text.getData().charAt(i) == '\r'
                        || text.getData().charAt(i) == ' ' || text.getData().charAt(i) == '\t') {
                    if (buf.length() > 0 && buf.charAt(buf.length() - 1) != ' ') {
                        buf.append(' ');
                    }
                } else {
                    buf.append(text.getData().charAt(i));
                }
            }
            if (buf.length() > 0 && !buf.toString().equals(" ")) {
                StringBuilder buf2 = new StringBuilder(buf.length() + indent);
                //                  for(int j=0;j<indent;j++) {
                //                      buf2.append(' ');
                //                  }
                buf2.append(buf.toString());
                out.print(buf2);
            }
        }
    }
}

From source file:com.aurel.track.exchange.docx.exporter.PreprocessImage.java

private static Integer parseNumber(String imgSrc, String tag) {
    int workItemIndex = imgSrc.indexOf(tag);
    if (workItemIndex != -1) {
        String workItemString = imgSrc.substring(workItemIndex);
        StringBuilder stringBuilder = new StringBuilder(workItemString);
        stringBuilder.replace(0, tag.length(), "");
        int i = 0;
        char charValue;
        StringBuilder numberString = new StringBuilder();
        do {//from w w  w.  ja  v a2s .c  o  m
            charValue = stringBuilder.charAt(i++);
            if (Character.isDigit(charValue)) {
                numberString.append(charValue);
            }
        } while (stringBuilder.length() > i && Character.isDigit(charValue));
        return Integer.decode(numberString.toString());
    }
    return null;
}

From source file:net.certiv.json.util.Strings.java

/**
 * Returns the lines of the block prefixed with the indent string. Ensures a leading EOL
 * sequence and no trailing whitespace.//from  w w  w  .  j  av  a 2  s .  co  m
 *
 * @param ci
 * @param block
 * @return
 */
public static String indentBlock(String ci, String block) {
    if (block == null)
        return "<Error: indent include block is null>";
    StringReader sr = new StringReader(block);
    BufferedReader buf = new BufferedReader(sr);
    StringBuilder sb = new StringBuilder();
    String s;
    try {
        while ((s = buf.readLine()) != null) {
            sb.append(ci + s + Strings.eol);
        }
        char c = sb.charAt(0);
        if (c != '\n' && c != '\r') {
            sb.insert(0, eol);
        }
        return trimRight(sb.toString());
    } catch (IOException e) {
        sb.append("<Error indenting block: " + e.getMessage() + ">");
    }
    return sb.toString();
}

From source file:com.beligum.core.utils.Toolkit.java

public static String buildBackendUrlString(String actionConfigKey) {
    StringBuilder url = new StringBuilder();
    url.append(play.Play.application().configuration().getString("cindi.fileServer"));

    String actionUrl = play.Play.application().configuration().getString(actionConfigKey);
    if (actionUrl.charAt(0) != '/' && url.charAt(url.length() - 1) != '/') {
        url.append("/");
    }//from w w  w .j a v a 2s .c  o m
    url.append(actionUrl);

    return url.toString();
}

From source file:org.apache.hadoop.gateway.config.impl.DefaultConfigurationInjector.java

private static String getConfigName(Method method) {
    String methodName = method.getName();
    if (methodName != null) {
        StringBuilder name = new StringBuilder(methodName.length());
        if (methodName.length() > 3 && methodName.startsWith("set")
                && Character.isUpperCase(methodName.charAt(3))) {
            name.append(methodName.substring(3));
            name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
        } else {//from   w  w  w.  j  a  v  a2  s . c  o m
            name.append(name);
        }
        return name.toString();
    }
    return null;
}

From source file:net.minder.config.impl.DefaultConfigurationInjector.java

private static String getConfigName(Method method) {
    String methodName = method.getName();
    StringBuilder name = new StringBuilder(methodName.length());
    if (methodName != null && methodName.length() > 3 && methodName.startsWith("set")
            && Character.isUpperCase(methodName.charAt(3))) {
        name.append(methodName.substring(3));
        name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
    } else {/* w w  w  .  j  av a  2  s.c  om*/
        name.append(name);
    }
    return name.toString();
}

From source file:org.apache.axis2.transport.http.HTTPTransportUtils.java

public static EndpointReference[] getEPRsForService(ConfigurationContext configurationContext,
        TransportInDescription trpInDesc, String serviceName, String ip, int port) throws AxisFault {

    AxisConfiguration axisConfiguration = configurationContext.getAxisConfiguration();
    Parameter param = axisConfiguration.getParameter(Constants.HTTP_FRONTEND_HOST_URL);
    StringBuilder epr = new StringBuilder();
    if (param != null) {
        epr.append(param.getValue());/*  w w  w.j  ava  2  s .c o m*/
        String servicePath = configurationContext.getServicePath();
        if (epr.charAt(epr.length() - 1) != '/' && !servicePath.startsWith("/")) {
            epr.append('/');
        }
        epr.append(servicePath);
    } else {
        param = trpInDesc.getParameter(TransportListener.HOST_ADDRESS);
        if (param != null) {
            // TODO: Need to decide if we really want to deprecate this parameter.
            //       Reason to deprecate it is that it has a misleading name ("hostname"
            //       while it is actually a URL), that its role overlaps with that
            //       of the "httpFrontendHostUrl" parameter in the Axis configuration and
            //       that there might be a confusion with the "hostname" parameter in the
            //       Axis configuration (which has a different meaning).
            //       If we deprecate it, we need to remove it from all the axis2.xml sample
            //       files. Note that the same parameter seems to be used by the TCP transport,
            //       but it's role is not very clear (since TCP has no concept of request URI).
            log.warn("Transport '" + trpInDesc.getName() + "' is configured with deprecated parameter '"
                    + TransportListener.HOST_ADDRESS + "'. Please set '" + Constants.HTTP_FRONTEND_HOST_URL
                    + "' in the Axis configuration instead.");
            epr.append(param.getValue());
        } else {
            if (ip == null) {
                try {
                    ip = Utils.getIpAddress(configurationContext.getAxisConfiguration());
                } catch (SocketException ex) {
                    AxisFault.makeFault(ex);
                }
            }
            String scheme = trpInDesc.getName();
            epr.append(scheme);
            epr.append("://");
            epr.append(ip);
            if (!(scheme.equals("http") && port == 80 || scheme.equals("https") && port == 443)) {
                epr.append(':');
                epr.append(port);
            }
        }
        String serviceContextPath = configurationContext.getServiceContextPath();
        if (epr.charAt(epr.length() - 1) != '/' && !serviceContextPath.startsWith("/")) {
            epr.append('/');
        }
        epr.append(serviceContextPath);
    }
    epr.append('/');
    epr.append(serviceName);
    epr.append('/');
    return new EndpointReference[] { new EndpointReference(epr.toString()) };
}