Example usage for java.lang Character toString

List of usage examples for java.lang Character toString

Introduction

In this page you can find the example usage for java.lang Character toString.

Prototype

public static String toString(int codePoint) 

Source Link

Document

Returns a String object representing the specified character (Unicode code point).

Usage

From source file:io.coala.config.AbstractPropertyGetter.java

/**
 * @param defaultValue//from ww w  .j ava  2 s. com
 * @return
 */
public Character getChar(final Character defaultValue) {
    final String value = get(defaultValue == null ? null : Character.toString(defaultValue));
    return value == null ? null : value.charAt(0);
}

From source file:org.eclipse.packagedrone.utils.deb.build.DebianPackageWriter.java

@Override
public void addDirectory(String directory, final EntryInformation entryInformation) throws IOException {
    directory = cleanupPath(directory);/*from  w ww .  ja va  2 s.co m*/
    if (!directory.endsWith("/")) {
        directory += Character.toString('/');
    }
    checkCreateParents(directory);
    internalAddDirectory(directory, entryInformation);
}

From source file:com.spotify.docker.client.CompressedDirectory.java

@VisibleForTesting
static PathMatcher goPathMatcher(FileSystem fs, String pattern) {
    // Supposed to work the same way as Go's path.filepath.match.Match:
    // http://golang.org/src/path/filepath/match.go#L34

    final String notSeparatorPattern = getNotSeparatorPattern(fs.getSeparator());

    final String starPattern = String.format("%s*", notSeparatorPattern);

    final StringBuilder patternBuilder = new StringBuilder();

    boolean inCharRange = false;
    boolean inEscape = false;

    // This is of course hugely inefficient, but it passes most of the test suite, TDD ftw...
    for (int i = 0; i < pattern.length(); i++) {
        final char c = pattern.charAt(i);
        if (inCharRange) {
            if (inEscape) {
                patternBuilder.append(c);
                inEscape = false;/*from www.j  a v  a2s . com*/
            } else {
                switch (c) {
                case '\\':
                    patternBuilder.append('\\');
                    inEscape = true;
                    break;
                case ']':
                    patternBuilder.append(']');
                    inCharRange = false;
                    break;
                default:
                    patternBuilder.append(c);
                }
            }
        } else {
            if (inEscape) {
                patternBuilder.append(Pattern.quote(Character.toString(c)));
                inEscape = false;
            } else {
                switch (c) {
                case '*':
                    patternBuilder.append(starPattern);
                    break;
                case '?':
                    patternBuilder.append(notSeparatorPattern);
                    break;
                case '[':
                    patternBuilder.append("[");
                    inCharRange = true;
                    break;
                case '\\':
                    inEscape = true;
                    break;
                default:
                    patternBuilder.append(Pattern.quote(Character.toString(c)));
                }
            }
        }
    }

    return fs.getPathMatcher("regex:" + patternBuilder.toString());
}

From source file:org.codehaus.enunciate.modules.php.PHPDeploymentModule.java

protected String packageToModule(String pckg) {
    if (pckg == null) {
        return null;
    } else {/*  w w w.  j a va  2s  .  co m*/
        StringBuilder ns = new StringBuilder();
        for (StringTokenizer toks = new StringTokenizer(pckg, "."); toks.hasMoreTokens();) {
            String tok = toks.nextToken();
            ns.append(Character.toString(tok.charAt(0)).toUpperCase());
            if (tok.length() > 1) {
                ns.append(tok.substring(1));
            }
            if (toks.hasMoreTokens()) {
                ns.append("\\");
            }
        }
        return ns.toString();
    }
}

From source file:org.apache.hyracks.data.std.primitive.UTF8StringPointableTest.java

@Test
public void testSubstrAfter() throws Exception {
    UTF8StringBuilder builder = new UTF8StringBuilder();
    GrowableArray storage = new GrowableArray();

    STRING_LEN_128.substrAfter(STRING_LEN_127, builder, storage);
    UTF8StringPointable result = new UTF8StringPointable();
    result.set(storage.getByteArray(), 0, storage.getLength());

    UTF8StringPointable expect = generateUTF8Pointable(Character.toString(UTF8StringSample.ONE_ASCII_CHAR));
    assertEquals(0, expect.compareTo(result));

    storage.reset();//from w  ww. ja v a 2 s  .c  o m
    UTF8StringPointable testPtr = generateUTF8Pointable("Mix123");
    UTF8StringPointable pattern = generateUTF8Pointable("");
    expect = generateUTF8Pointable("123");
    testPtr.substrAfter(pattern, builder, storage);
    result.set(storage.getByteArray(), 0, storage.getLength());
    assertEquals(0, expect.compareTo(result));
}

From source file:com.aurel.track.lucene.util.StringUtil.java

public static String replace(String s, char oldSub, char newSub) {
    return replace(s, oldSub, Character.toString(newSub));
}

From source file:org.broad.igv.util.StringUtils.java

/**
 * Converts an input string, of any case, into a series
 * of capitalized words.//from  w w  w .  j a  v  a2  s  .c o m
 * toCapWords("BOB") -> "Bob"
 * toCapWords("bOb is MY FRiend") -> "Bob Is My Friend"
 *
 * @param text
 * @return
 */
public static String capWords(String text) {
    String res = "";
    boolean capNext = true;
    String s;

    for (char c : text.toLowerCase().toCharArray()) {
        s = Character.toString(c);
        if (capNext) {
            s = s.toUpperCase();
        }
        res += s;
        capNext = " ".equals(s);
    }
    return res;
}

From source file:org.ajax4jsf.javascript.ScriptUtils.java

public static String getValidJavascriptName(String s) {

    StringBuffer buf = null;/*from www  . j  a v a  2s.c  o m*/
    for (int i = 0, len = s.length(); i < len; i++) {
        char c = s.charAt(i);

        if (Character.isLetterOrDigit(c) || c == '_') {
            // allowed char
            if (buf != null)
                buf.append(c);
        } else {
            if (buf == null) {
                buf = new StringBuffer(s.length() + 10);
                buf.append(s.substring(0, i));
            }

            buf.append('_');
            if (c < 16) {
                // pad single hex digit values with '0' on the left
                buf.append('0');
            }

            if (c < 128) {
                // first 128 chars match their byte representation in UTF-8
                buf.append(Integer.toHexString(c).toUpperCase());
            } else {
                byte[] bytes;
                try {
                    bytes = Character.toString(c).getBytes("UTF-8");
                } catch (UnsupportedEncodingException e) {
                    throw new RuntimeException(e);
                }

                for (int j = 0; j < bytes.length; j++) {
                    int intVal = bytes[j];
                    if (intVal < 0) {
                        // intVal will be >= 128
                        intVal = 256 + intVal;
                    } else if (intVal < 16) {
                        // pad single hex digit values with '0' on the left
                        buf.append('0');
                    }
                    buf.append(Integer.toHexString(intVal).toUpperCase());
                }
            }
        }

    }

    return buf == null ? s : buf.toString();
}

From source file:com.fujitsu.dc.core.odata.DcExpressionParser.java

/**
 * tokenizer.//from  w w  w . ja  v  a  2s . co m
 * OData4j?tokenizer???'_'?????????
 * @param value value
 * @return 
 */
public static List<Token> tokenize(String value) {
    List<Token> rt = new ArrayList<Token>();
    int current = 0;
    int end = 0;

    while (true) {
        if (current == value.length()) {
            return rt;
        }
        char c = value.charAt(current);
        if (Character.isWhitespace(c)) {
            end = readWhitespace(value, current);
            rt.add(new Token(TokenType.WHITESPACE, value.substring(current, end)));
            current = end;
        } else if (c == '\'') {
            end = readQuotedString(value, current + 1);
            rt.add(new Token(TokenType.QUOTED_STRING, value.substring(current, end)));
            current = end;
        } else if (Character.isLetter(c)) {
            end = readWord(value, current + 1);
            rt.add(new Token(TokenType.WORD, value.substring(current, end)));
            current = end;
        } else if (c == '_') {
            end = readWord(value, current + 1);
            rt.add(new Token(TokenType.WORD, value.substring(current, end)));
            current = end;
        } else if (Character.isDigit(c)) {
            end = readDigits(value, current + 1);
            rt.add(new Token(TokenType.NUMBER, value.substring(current, end)));
            current = end;
        } else if (c == '(') {
            rt.add(new Token(TokenType.OPENPAREN, Character.toString(c)));
            current++;
        } else if (c == ')') {
            rt.add(new Token(TokenType.CLOSEPAREN, Character.toString(c)));
            current++;
        } else if (c == '-') {
            if (Character.isDigit(value.charAt(current + 1))) {
                end = readDigits(value, current + 1);
                rt.add(new Token(TokenType.NUMBER, value.substring(current, end)));
                current = end;
            } else {
                rt.add(new Token(TokenType.SYMBOL, Character.toString(c)));
                current++;
            }
        } else if (",.+=:".indexOf(c) > -1) {
            rt.add(new Token(TokenType.SYMBOL, Character.toString(c)));
            current++;
        } else {
            dumpTokens(rt);
            throw new RuntimeException("Unable to tokenize: " + value + " current: " + current + " rem: "
                    + value.substring(current));
        }
    }

}

From source file:org.apache.accumulo.test.YieldScannersIT.java

@Test
public void testBatchScan() throws Exception {
    // make a table
    final String tableName = getUniqueNames(1)[0];
    try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
        client.tableOperations().create(tableName);
        final BatchWriter writer = client.createBatchWriter(tableName, new BatchWriterConfig());
        for (int i = 0; i < 10; i++) {
            byte[] row = { (byte) (START_ROW + i) };
            Mutation m = new Mutation(new Text(row));
            m.put(new Text(), new Text(), new Value());
            writer.addMutation(m);//  w  w  w .  j  a  va2s.c o m
        }
        writer.flush();
        writer.close();

        log.info("Creating batch scanner");
        // make a scanner for a table with 10 keys
        try (BatchScanner scanner = client.createBatchScanner(tableName)) {
            final IteratorSetting cfg = new IteratorSetting(100, YieldingIterator.class);
            scanner.addScanIterator(cfg);
            scanner.setRanges(Collections.singleton(new Range()));

            log.info("iterating");
            Iterator<Map.Entry<Key, Value>> it = scanner.iterator();
            int keyCount = 0;
            int yieldNextCount = 0;
            int yieldSeekCount = 0;
            while (it.hasNext()) {
                Map.Entry<Key, Value> next = it.next();
                log.info(Integer.toString(keyCount) + ": Got key " + next.getKey() + " with value "
                        + next.getValue());

                // verify we got the expected key
                char expected = (char) (START_ROW + keyCount);
                assertEquals("Unexpected row", Character.toString(expected), next.getKey().getRow().toString());

                // determine whether we yielded on a next and seek
                if ((keyCount & 1) != 0) {
                    yieldNextCount++;
                    yieldSeekCount++;
                }
                String[] value = StringUtils.split(next.getValue().toString(), ',');
                assertEquals("Unexpected yield next count", Integer.toString(yieldNextCount), value[0]);
                assertEquals("Unexpected yield seek count", Integer.toString(yieldSeekCount), value[1]);
                assertEquals("Unexpected rebuild count", Integer.toString(yieldNextCount + yieldSeekCount),
                        value[2]);

                keyCount++;
            }
            assertEquals("Did not get the expected number of results", 10, keyCount);
        }
    }
}