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:KeyListenerExample.java

KeyListenerExample() {

    d = new Display();
    s = new Shell(d);

    s.setSize(250, 200);/*  w  w  w. j  a  v a 2 s .  c  o m*/

    s.setText("A KeyListener Example");
    s.setLayout(new RowLayout());

    final Combo c = new Combo(s, SWT.DROP_DOWN | SWT.BORDER);
    c.add("Lions");
    c.add("Tigers");
    c.add("Bears");
    c.add("Oh My!");

    c.addKeyListener(new KeyListener() {
        String selectedItem = "";

        public void keyPressed(KeyEvent e) {
            if (c.getText().length() > 0) {
                return;
            }
            String key = Character.toString(e.character);
            String[] items = c.getItems();
            for (int i = 0; i < items.length; i++) {
                if (items[i].toLowerCase().startsWith(key.toLowerCase())) {
                    c.select(i);
                    selectedItem = items[i];
                    return;
                }
            }
        }

        public void keyReleased(KeyEvent e) {
            if (selectedItem.length() > 0)
                c.setText(selectedItem);
            selectedItem = "";
        }
    });
    s.open();
    while (!s.isDisposed()) {
        if (!d.readAndDispatch())
            d.sleep();
    }
    d.dispose();
}

From source file:org.esigate.util.UriUtils.java

private static String encode(char character) {
    return Character.toString(character);
}

From source file:edu.uci.ics.jung.algorithms.importance.TestWeightedNIPaths.java

@Override
protected void setUp() {
    vertexFactory = new Factory<String>() {
        char a = 'A';

        public String create() {
            return Character.toString(a++);
        }/* w w w  .  ja v a2  s.c o m*/
    };
    edgeFactory = new Factory<Number>() {
        int count;

        public Number create() {
            return count++;
        }
    };
}

From source file:org.amanzi.neo.loader.core.parser.impl.CSVUtils.java

private static Map<Character, Integer> defineDelimeters(final File file) {
    BufferedReader read = null;/*w  w  w.  java2s .  c om*/
    Map<Character, Integer> seaprators = new HashMap<Character, Integer>();
    String line;
    try {
        read = new BufferedReader(new FileReader(file));
        while ((line = read.readLine()) != null) {
            int maxMatch = 0;
            for (char regex : POSSIBLE_SEPARATORS) {
                String[] fields = line.split(Character.toString(regex));
                if (fields.length > maxMatch) {
                    maxMatch = fields.length;
                    seaprators.put(regex, maxMatch);
                }
            }
            if (maxMatch >= MINIMAL_HEADERS_SIZE) {
                break;
            }
        }
    } catch (IOException e) {
        LOGGER.error("Can't define delimeters", e);
    } finally {
        IOUtils.closeQuietly(read);
    }
    return seaprators;
}

From source file:com.omnigon.aem.common.utils.StringUtils.java

public static String shortenString(String src, int length, boolean addEllipses) {
    if (isNotBlank(src) && src.length() > length) {
        if (addEllipses) {
            String sub = src.substring(0, length);
            char last = sub.charAt(sub.length() - 1);

            return PUNCTUATION.contains(Character.toString(last)) ? sub : sub + ELLIPSES;
        } else {/*from  ww w  . j  a v  a  2s  . c  o  m*/

            return src.substring(0, length);
        }
    }

    return src;
}

From source file:net.certiv.antlr.project.util.Strings.java

public static String tokenCase(String in) {
    if (isAllUpperCase(in)) {
        return Character.toString(in.charAt(0)) + in.substring(1).toLowerCase();
    }// ww  w.j  a  va 2s.c  o m
    return in;
}

From source file:ai.grakn.migration.csv.Main.java

public static void runCSV(MigrationCLI cli) {
    String csvDataFileName = cli.getRequiredOption("input", "Data file missing (-i)");
    String csvTemplateName = cli.getRequiredOption("template", "Template file missing (-t)");
    int batchSize = cli.hasOption("b") ? Integer.valueOf(cli.getOption("b")) : AbstractMigrator.BATCH_SIZE;
    String delimiterString = cli.hasOption("s") ? cli.getOption("s")
            : Character.toString(CSVMigrator.SEPARATOR);

    if (delimiterString.toCharArray().length != 1) {
        cli.die("Wrong number of characters in delimiter " + delimiterString);
    }/* w w w.  j a va  2s. com*/

    char csvDelimiter = delimiterString.toCharArray()[0];

    // get files
    File csvDataFile = new File(csvDataFileName);
    File csvTemplate = new File(csvTemplateName);

    if (!csvTemplate.exists()) {
        cli.die("Cannot find file: " + csvTemplateName);
    }

    if (!csvDataFile.exists()) {
        cli.die("Cannot find file: " + csvDataFileName);
    }

    cli.printInitMessage(csvDataFile.getPath());

    String template = cli.fileAsString(csvTemplate);
    try (CSVMigrator csvMigrator = new CSVMigrator(template, csvDataFile).setSeparator(csvDelimiter)) {

        if (cli.hasOption("n")) {
            cli.writeToSout(csvMigrator.migrate());
        } else {
            MigrationLoader.load(cli.getLoader(), batchSize, csvMigrator);
            cli.printWholeCompletionMessage();
        }
    } catch (Throwable throwable) {
        cli.die(throwable);
    }

    cli.initiateShutdown();
}

From source file:edu.eci.arsw.pacm.services.PacmServicesStub.java

@Override
public void registrarJugadorAtacante(int salanum, Player p) throws ServicesException {
    if (!salasData.containsKey(salanum)) {
        throw new ServicesException("Sala " + salanum + " no ha sido registrada en el servidor.");
    } else {//from ww  w  .  j  a v  a  2 s. co  m
        CopyOnWriteArrayList tmp = salasData.get(salanum).getAtacantes();
        int a = 64 + tmp.size();
        identifacadores.put(p.getNombre(), Character.toString((char) a));
        tmp.add(p);
        salasData.get(salanum).setAtacantes(tmp);
    }
}

From source file:Main.java

/**
 * takes an escape'd XML string and converts it back to orginal text contents
 * //w ww  .  ja  v  a  2 s. c  o  m
 * @param chars XML contents
 * @return String translation of XML contents
 **/
public static final String unescape(final String chars) {
    if (chars == null) {
        return "";
    }

    final StringBuilder res = new StringBuilder(chars);
    int i = res.indexOf("&");

    while (i != -1) {
        final int j = res.indexOf(";", i + 1);
        if (j == -1) {
            break;
        }
        final String entity = res.substring(i + 1, j);
        if (entity.startsWith("#")) {
            if ((entity.length() == 3) && (entity.charAt(1) == 'x')) {
                // http://www.w3.org/TR/1999/WD-xml-c14n-19991109.html
                // 5.2 Character Escaping
                switch (entity.charAt(2)) {
                case '9':
                    res.replace(i, j + 1, "\t");
                    break;
                case 'D':
                    res.replace(i, j + 1, "\r");
                    break;
                case 'A':
                    res.replace(i, j + 1, "\n");
                    break;
                }
            } else {
                try {
                    final int charCode = Integer.parseInt(entity.substring(1));
                    final char c = (char) charCode;
                    res.replace(i, j + 1, Character.toString(c));
                    i = i + 1;
                } catch (final NumberFormatException e) {
                    res.delete(i, j + 1);
                }
            }
        } else {
            final String textEntity = XML_ENTITY_MAP.get(entity);
            if (textEntity != null) {
                res.replace(i, j + 1, textEntity);
                i = i + textEntity.length();
            } else {
                res.delete(i, j + 1);
            }
        }
        i = res.indexOf("&", i);
    }

    return res.toString();
}

From source file:org.coury.jfilehelpers.helpers.StringHelper.java

public static void createQuotedString(final StringBuffer sb, String source, final char quoteChar) {
    if (source == null) {
        source = "";
    }/*www .j  a va  2  s.c o  m*/

    String quotedCharStr = Character.toString(quoteChar);
    String escapedString = source.replace(quotedCharStr, quotedCharStr + quotedCharStr);

    sb.append(quoteChar);
    sb.append(escapedString);
    sb.append(quoteChar);
}