Example usage for java.lang StringBuffer setCharAt

List of usage examples for java.lang StringBuffer setCharAt

Introduction

In this page you can find the example usage for java.lang StringBuffer setCharAt.

Prototype

@Override
public synchronized void setCharAt(int index, char ch) 

Source Link

Usage

From source file:com.xpn.xwiki.plugin.query.QueryPlugin.java

protected String getXPathName(String name) {
    int is = name.indexOf('['), ip = name.indexOf('.');
    if (ip > 0 && (is < 0 || ip < is)) {
        StringBuffer sb = new StringBuffer(name);
        sb.setCharAt(ip, '/');
        return sb.toString();
    } else// www.  j  av  a2 s  .c om
        return name;
}

From source file:com.pactera.edg.am.metamanager.extractor.dao.impl.SequenceDaoImpl.java

public String getUuid() {
    StringBuffer uuid = new StringBuffer();
    try {/*w ww . j a v  a  2  s  . co m*/
        uuid.append(UUID.randomUUID().toString());
    } catch (Exception e) {
        this.createUUIDGen();
        uuid.append(uuidGen.nextUUID());
    }
    if (uuid.length() == 0) {
        throw new RuntimeException("UUID generate fail");
    }
    uuid.setCharAt(0, shiftHex(uuid.charAt(0))); //hibernateuuid.hex??
    return uuid.toString().replaceAll("-", "");
}

From source file:org.archive.util.SURT.java

/**
 * Utility method for creating the SURT form of the URI in the
 * given String.//from w  w  w. jav a  2 s .co m
 * 
 * If it appears a bit convoluted in its approach, note that it was
 * optimized to minimize object-creation after allocation-sites profiling 
 * indicated this method was a top source of garbage in long-running crawls.
 * 
 * Assumes that the String URI has already been cleaned/fixed (eg
 * by UURI fixup) in ways that put it in its crawlable form for 
 * evaluation.
 * 
 * @param s String URI to be converted to SURT form
 * @param preserveCase whether original case should be preserved
 * @return SURT form 
 */
public static String fromURI(String s, boolean preserveCase) {
    Matcher m = TextUtils.getMatcher(URI_SPLITTER, s);
    if (!m.matches()) {
        // not an authority-based URI scheme; return unchanged
        TextUtils.recycleMatcher(m);
        return s;
    }
    // preallocate enough space for SURT form, which includes
    // 3 extra characters ('(', ')', and one more ',' than '.'s
    // in original)
    StringBuffer builder = new StringBuffer(s.length() + 3);
    append(builder, s, m.start(1), m.end(1)); // scheme://
    builder.append(BEGIN_TRANSFORMED_AUTHORITY); // '('

    if (m.start(4) > -1) {
        // dotted-quad ip match: don't reverse
        append(builder, s, m.start(4), m.end(4));
    } else {
        // other hostname match: do reverse
        int hostSegEnd = m.end(5);
        int hostStart = m.start(5);
        for (int i = m.end(5) - 1; i >= hostStart; i--) {
            if (s.charAt(i - 1) != DOT && i > hostStart) {
                continue;
            }
            append(builder, s, i, hostSegEnd); // rev host segment
            builder.append(TRANSFORMED_HOST_DELIM); // ','
            hostSegEnd = i - 1;
        }
    }

    append(builder, s, m.start(6), m.end(6)); // :port
    append(builder, s, m.start(3), m.end(3)); // at
    append(builder, s, m.start(2), m.end(2)); // userinfo
    builder.append(END_TRANSFORMED_AUTHORITY); // ')'
    append(builder, s, m.start(7), m.end(7)); // path
    if (!preserveCase) {
        for (int i = 0; i < builder.length(); i++) {
            builder.setCharAt(i, Character.toLowerCase(builder.charAt((i))));
        }
    }
    TextUtils.recycleMatcher(m);
    return builder.toString();
}

From source file:com.cloudera.crunch.type.writable.TupleWritable.java

/**
 * Convert Tuple to String as in the following.
 * <tt>[<child1>,<child2>,...,<childn>]</tt>
 */// www  .j ava 2 s  .  c  o  m
public String toString() {
    StringBuffer buf = new StringBuffer("[");
    for (int i = 0; i < values.length; ++i) {
        buf.append(has(i) ? values[i].toString() : "");
        buf.append(",");
    }
    if (values.length != 0)
        buf.setCharAt(buf.length() - 1, ']');
    else
        buf.append(']');
    return buf.toString();
}

From source file:GIST.IzbirkomExtractor.AbbrList.java

/**
 * Creates a list of all possible expansions of a given streetName.
 * stretName itself will be the first element of the expansion list.
 * //from  w  ww  . j  a  v a  2  s  .c  om
 * @param streetName
 * @return
 */
public ArrayList<String> createAllExpansions(String streetName) {

    ArrayList<String> expansions = new ArrayList<String>();
    expansions.add(streetName);

    Matcher mat = getAbbreviationsPattern().matcher(streetName);
    if (mat.find()) {
        for (String exp : abbrevs.get(mat.group(1)).getExpansions()) {
            StringBuffer str = new StringBuffer(mat.replaceFirst(exp));

            /* get rid of abbreviations with dash */
            if (streetName.length() > mat.start(1) + 1 && streetName.charAt(mat.start(1) + 1) == '-') {
                str.setCharAt(mat.start(1) + exp.length(), ' ');
            }

            if (exp.endsWith("-")) { // support for ?-, ?-, -; remove space, downcase following letter

                /* skip replacement and the end of string */
                if (str.toString().endsWith(exp))
                    continue;

                str.delete(mat.start(1) + exp.length() - 1, mat.start(1) + exp.length() + 1);
                char upcase = str.charAt(mat.start(1) + exp.length() - 1);
                str.setCharAt(mat.start(1) + exp.length() - 1, Character.toLowerCase(upcase));
            }

            expansions.add(str.toString());
        }
    }

    return expansions;
}

From source file:org.jannocessor.service.imports.ImportOrganizerImpl.java

private List<ParsedTypeNameParam> extractParams(String params) {
    List<ParsedTypeNameParam> parts = new ArrayList<ParsedTypeNameParam>();

    if (StringUtils.isNotEmpty(params)) {

        StringBuffer sb = new StringBuffer(params);
        Pattern pattern = Pattern.compile("<[^<>]+?>");

        Matcher m = pattern.matcher(sb.toString());
        while (m.find()) {
            for (int i = m.start(); i < m.end(); i++) {
                sb.setCharAt(i, ' ');
            }//from   w w w . j a  v  a2  s  .c o m
            m = pattern.matcher(sb.toString());
        }
        String projection = sb.toString();

        int from = 0;
        int pos = projection.indexOf(',');

        while (pos > 0) {
            String part = params.substring(from, pos).trim();
            parts.add(typeParam(part));

            from = pos + 1;
            pos = projection.indexOf(',', pos + 1);
        }

        String part = params.substring(from).trim();
        parts.add(typeParam(part));
    }

    return parts;
}

From source file:DummyAppletContext.java

private String filenameFromURL(URL url) {
    String filename = url.getFile();
    if (filename.charAt(1) == '|') {
        StringBuffer buf = new StringBuffer(filename);
        buf.setCharAt(1, ':');
        filename = buf.toString();//from  ww  w.  j a  va 2 s.c o m
    } else if (filename.charAt(2) == '|') {
        StringBuffer buf = new StringBuffer(filename);
        buf.setCharAt(2, ':');
        filename = buf.toString();
    }
    return filename;
}

From source file:DummyAppletContext.java

public void connect() throws IOException {
    if (!connected) {
        String filename = url.getFile();
        if (filename.charAt(1) == '|') {
            StringBuffer buf = new StringBuffer(filename);
            buf.setCharAt(1, ':');
            filename = buf.toString();/*w  ww . jav  a2  s.  c  o m*/
        } else if (filename.charAt(2) == '|') {
            StringBuffer buf = new StringBuffer(filename);
            buf.setCharAt(2, ':');
            filename = buf.toString();
        }
        instream = new FileInputStream(filename);
    }
}

From source file:org.lockss.util.UrlUtil.java

public static String normalizeUrlEncodingCase(String str) {
    if (!normalizeUrlEncodingCase) {
        return str;
    }/*  w  w w.jav a 2s .com*/
    int pos = str.indexOf('%');
    if (pos < 0) {
        return str;
    }
    StringBuffer sb = new StringBuffer(str);
    int len = str.length();
    do {
        if (len < pos + 3) {
            break;
        }
        char ch;
        if (Character.isLowerCase(ch = sb.charAt(pos + 1))) {
            sb.setCharAt(pos + 1, Character.toUpperCase(ch));
        }
        if (Character.isLowerCase(ch = sb.charAt(pos + 2))) {
            sb.setCharAt(pos + 2, Character.toUpperCase(ch));
        }
    } while ((pos = str.indexOf('%', pos + 3)) >= 0);
    return sb.toString();
}

From source file:org.apache.velocity.runtime.parser.node.PropertyExecutor.java

/**
 * @param clazz// w w w.ja va 2s.  co m
 * @param property
 */
protected void discover(final Class clazz, final String property) {
    /*
     *  this is gross and linear, but it keeps it straightforward.
     */

    try {
        Object[] params = {};

        StringBuffer sb = new StringBuffer("get");
        sb.append(property);

        setMethod(introspector.getMethod(clazz, sb.toString(), params));

        if (!isAlive()) {
            /*
             *  now the convenience, flip the 1st character
             */

            char c = sb.charAt(3);

            if (Character.isLowerCase(c)) {
                sb.setCharAt(3, Character.toUpperCase(c));
            } else {
                sb.setCharAt(3, Character.toLowerCase(c));
            }

            setMethod(introspector.getMethod(clazz, sb.toString(), params));
        }
    }
    /**
     * pass through application level runtime exceptions
     */
    catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        String msg = "Exception while looking for property getter for '" + property;
        Logger.error(this, msg, e);
        throw new VelocityException(msg, e);
    }
}