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

/**
 * Ensures an arc's label is indeed printable (dot uses US-ASCII). 
 *///from  w w  w .ja  v  a 2 s . c o  m
private static String printableLabel(int label) {
    if (label >= 0x20 && label <= 0x7d) {
        return Character.toString((char) label);
    } else {
        return "0x" + Integer.toHexString(label);
    }
}

From source file:Main.java

/** Join the specified string with the specified separator.
 * Any other instances of pSeparator are doubled.
 *
 * @param pArgs the strings to be quoted
 * @param pSeparator the character to use as a separator
 *
 * @return the joined string, with quoting.
 *//*from w  w w  . jav a2s.  c o  m*/
public static String joinStringsWithQuoting(String[] pStrings, char pSeparator) {
    if ((pStrings == null) || (pStrings.length == 0)) {
        return "";
    }
    String strSingle = Character.toString(pSeparator);
    String strDouble = strSingle + strSingle;
    StringBuilder sb = new StringBuilder();
    boolean bFirstTime = false;
    for (String strCur : pStrings) {
        sb.append(strCur.replace(strSingle, strDouble));
        if (!bFirstTime) {
            sb.append(strSingle);
        } else {
            bFirstTime = false;
        }
    }

    return sb.toString();
}

From source file:Main.java

/**
 * This method adds underscore in between the words (eg: converts GeneHomolog
 * to Gene_Homolog)// w w w.  ja  v a2  s. c o m
 *
 * @param name
 */
public static void evaluateString(String name, List<String> options, List<String> words) {
    if (options == null || words == null)
        throw new IllegalArgumentException("Options or Words is not initialized");

    //remove package name if the name is a class name
    if (name != null) {
        int index = name.lastIndexOf(".");
        name = name.substring(index + 1);
    }
    //Set optionSet = new HashSet();
    options.add(name);

    char firstChar = name.charAt(0);

    firstChar = Character.toUpperCase(firstChar);

    if (name.indexOf("_") > 0) {
        String temp = Character.toString(firstChar) + name.substring(1);
        options.add(temp);
    }
    String temp = firstChar + name.substring(1).toLowerCase();
    options.add(temp);

    String evaluatedString = null;
    ;

    StringBuffer wholeWords = new StringBuffer();

    StringBuffer tempSeparateWord = new StringBuffer();

    char[] chars = name.toCharArray();

    StringBuffer sb = new StringBuffer();

    boolean first = true;

    int index = 0;

    for (int i = 0; i < chars.length; i++) {
        //Character c = new Character(chars[i]);
        //System.out.println("inside loop i = " +i);
        if (Character.isUpperCase(chars[i])) {
            if ((i > 1) && ((i - index) > 1)) {
                //System.out.println("Inside capital if");
                first = false;

                sb.append("_").append(chars[i]);

                words.add(tempSeparateWord.toString());

                tempSeparateWord = new StringBuffer();

                tempSeparateWord.append(chars[i]);

                wholeWords.append(" ").append(chars[i]);
            }

            else {
                wholeWords.append(chars[i]);

                tempSeparateWord.append(chars[i]);

                sb.append(chars[i]);
            }

            index = i;
        }

        else {
            if (chars[i] != '_') {
                sb.append(chars[i]);

                wholeWords.append(chars[i]);

                tempSeparateWord.append(chars[i]);
            }
        }
    }

    //System.out.println("Converted string: "+sb.toString());
    //if the string contains "_", then make the first character uppercase
    if (!first) {
        char c = Character.toUpperCase(sb.charAt(0));

        sb.deleteCharAt(0);

        sb.insert(0, c);

        char c1 = Character.toUpperCase(wholeWords.charAt(0));

        wholeWords.deleteCharAt(0);

        wholeWords.insert(0, c1);
    }

    options.add(sb.toString());
    options.add(wholeWords.toString());

    if (words.size() > 0) {
        /*
           StringBuffer tmp = (StringBuffer)separateWords.get(0);
           char c2 = Character.toUpperCase(tmp.charAt(0));
                    
           tmp.deleteCharAt(0);
           tmp.insert(0, c2);
                    
           separateWords.remove(0);
           separateWords.add(0, tmp);
         */
        String temp2 = words.get(words.size() - 1).toString();

        if (tempSeparateWord != null) {
            temp = tempSeparateWord.toString();

            if (temp2.compareToIgnoreCase(temp) != 0) {
                words.add(temp);
            }
        }
    }
    List possibleOptions = new ArrayList(options);
    options = null;//garbage collection ready

    //testing
    for (int i = 0; i < possibleOptions.size(); i++) {
        System.out.println("options[" + i + "]=" + possibleOptions.get(i));
    }
    for (int i = 0; i < words.size(); i++) {
        System.out.println("separateWords[" + i + "]=" + words.get(i));
    }
    return;
}

From source file:Main.java

private static StringBuilder escape(char c, StringBuilder builder) {
    String encoded = encodingMap.get(c);
    return builder.append(encoded == null ? Character.toString(c) : encoded);
}

From source file:Main.java

private static StringBuffer escape(char c, StringBuffer buffer) {
    String encoded = encodingMap.get(c);
    return buffer.append(encoded == null ? Character.toString(c) : encoded);
}

From source file:Main.java

public static String cigarStringFromArray(final char[] cigar) {
    String result = "";
    int length = cigar.length;
    char lastOp = 0;
    int lastLen = 0;
    for (int i = 0; i < length; i++) {
        if (cigar[i] == lastOp) {
            lastLen++;/*from www.j  a va  2s  .c o  m*/
        } else if (cigar[i] == '-') {
            ; // nothing - just ignore '-'
        } else {
            if (lastOp != 0)
                result = result + Integer.toString(lastLen) + Character.toString(lastOp);
            lastLen = 1;
            lastOp = cigar[i];
        }
    }
    return result + Integer.toString(lastLen) + Character.toString(lastOp);
}

From source file:gov.nih.nci.ispy.util.MoreStringUtils.java

/**
 * This method will take a string of characters that you do not want to
 * appear in your string.  It will remove the unallowed characters and then
 * return to you the string as it would be without those characters.  For
 * instance if you passed ":" as the unallowed characters, and "I a:m ::Cle:an"
 * is the string you passed, you would end up with "I am Clean".  It does 
 * not replace the characters it removes them.
 * /*from ww  w  . j av  a2  s.com*/
 * @param unallowableCharString --give me a string of all the chars you don't want in your
 * final string.
 * @param stringToClean  --this is the string that you want cleaned
 * @return  your new string
 */
public static String cleanString(String unallowableCharacters, String stringToClean) {
    if (unallowableCharacters != null && stringToClean != null) {
        char[] filterString = unallowableCharacters.toCharArray();
        filterString = stringToClean.toCharArray();
        stringToClean = "";
        for (int i = 0; i < filterString.length; i++) {
            if (unallowableCharacters.indexOf(filterString[i]) == -1) {
                stringToClean = stringToClean.concat(Character.toString(filterString[i]));
            }
        }
    }
    return stringToClean;
}

From source file:org.evosuite.utils.NumberFormatter.java

/**
 * <p>/*from w ww  . j  a v  a2 s.  com*/
 * getNumberString
 * </p>
 * 
 * @param value
 *            a {@link java.lang.Object} object.
 * @return a {@link java.lang.String} object.
 */
public static String getNumberString(Object value) {
    if (value == null)
        return "null";
    else if (value.getClass().equals(char.class) || value.getClass().equals(Character.class)) {
        // StringEscapeUtils fails to escape a single quote char
        if (Character.valueOf('\'').equals(value)) {
            return "'\\\''";
        } else {
            return "'" + StringEscapeUtils.escapeJava(Character.toString((Character) value)) + "'";
        }
    } else if (value.getClass().equals(String.class)) {
        return "\"" + StringEscapeUtils.escapeJava((String) value) + "\"";
    } else if (value.getClass().equals(float.class) || value.getClass().equals(Float.class)) {
        if (value.toString().equals("" + Float.NaN))
            return "Float.NaN";
        else if (value.toString().equals("" + Float.NEGATIVE_INFINITY))
            return "Float.NEGATIVE_INFINITY";
        else if (value.toString().equals("" + Float.POSITIVE_INFINITY))
            return "Float.POSITIVE_INFINITY";
        else if (((Float) value) < 0F)
            return "(" + value + "F)";
        else
            return value + "F";
    } else if (value.getClass().equals(double.class) || value.getClass().equals(Double.class)) {
        if (value.toString().equals("" + Double.NaN))
            return "Double.NaN";
        else if (value.toString().equals("" + Double.NEGATIVE_INFINITY))
            return "Double.NEGATIVE_INFINITY";
        else if (value.toString().equals("" + Double.POSITIVE_INFINITY))
            return "Double.POSITIVE_INFINITY";
        else if (((Double) value) < 0.0)
            return "(" + value + ")";
        else
            return value.toString();
    } else if (value.getClass().equals(long.class) || value.getClass().equals(Long.class)) {
        if (((Long) value) < 0)
            return "(" + value + "L)";
        else
            return value + "L";
    } else if (value.getClass().equals(byte.class) || value.getClass().equals(Byte.class)) {
        if (((Byte) value) < 0)
            return "(byte) (" + value + ")";
        else
            return "(byte)" + value;
    } else if (value.getClass().equals(short.class) || value.getClass().equals(Short.class)) {
        if (((Short) value) < 0)
            return "(short) (" + value + ")";
        else
            return "(short)" + value;
    } else if (value.getClass().equals(int.class) || value.getClass().equals(Integer.class)) {
        int val = ((Integer) value).intValue();
        if (val == Integer.MAX_VALUE)
            return "Integer.MAX_VALUE";
        else if (val == Integer.MIN_VALUE)
            return "Integer.MIN_VALUE";
        else if (((Integer) value) < 0)
            return "(" + value + ")";
        else
            return "" + val;
    } else if (value.getClass().isEnum() || value instanceof Enum) {
        // java.util.concurrent.TimeUnit is an example where the enum
        // elements are anonymous inner classes, and then isEnum does
        // not return true apparently? So we check using instanceof as well.

        Class<?> clazz = value.getClass();
        String className = clazz.getSimpleName();
        while (clazz.getEnclosingClass() != null) {
            String enclosingName = clazz.getEnclosingClass().getSimpleName();
            className = enclosingName + "." + className;
            clazz = clazz.getEnclosingClass();
        }

        // We have to do this here to avoid a double colon in the TimeUnit example
        if (!className.endsWith("."))
            className += ".";
        try {
            if (value.getClass().getField(value.toString()) != null)
                return className + value;
            else if (((Enum<?>) value).name() != null)
                return className + ((Enum<?>) value).name();
            else
                return "Enum.valueOf(" + className + "class, \"" + value + "\")";
        } catch (Exception e) {
            if (((Enum<?>) value).name() != null)
                return className + ((Enum<?>) value).name();
            else
                return "Enum.valueOf(" + className + "class /* " + e + " */, \"" + value + "\")";
            // return className + "valueOf(\"" + value + "\")";
        }
    } else if (value.getClass().equals(Boolean.class)) {
        return value.toString();
    } else {
        // This should not happen
        assert (false);
        return value.toString();
    }
}

From source file:net.udidb.server.api.results.ExpressionValueSerializer.java

@Override
public void serialize(ExpressionValue value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonProcessingException {
    switch (value.getType()) {
    case CHAR://from  w w  w . j ava2  s  .  com
        jgen.writeString(Character.toString(value.getCharValue()));
        break;
    case STRING:
        jgen.writeString(value.getStringValue());
        break;
    case ADDRESS:
        jgen.writeString("0x" + Long.toHexString(value.getAddressValue()));
        break;
    case NUMBER:
        jgen.writeString(value.toString());
        break;
    }
}

From source file:gov.nih.nci.calims2.business.inventory.container.CoordinateHelper.java

private static String convertValue(char firstCharacter, int maximum, int value) {
    int length = (int) Math.floor(Math.log(maximum) / Math.log(LETTER_BASE)) + 1;
    if (value == 0) {
        return StringUtils.repeat(Character.toString(firstCharacter), length);
    }/*  ww w.j  av a  2s. c  om*/
    String result = "";
    int remaining = value;
    while (remaining > 0) {
        result = Character.toString((char) (firstCharacter + remaining % LETTER_BASE)) + result;
        remaining /= LETTER_BASE;
    }
    while (result.length() < length) {
        result = firstCharacter + result;
    }
    return result;
}