Example usage for java.lang Character Character

List of usage examples for java.lang Character Character

Introduction

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

Prototype

@Deprecated(since = "9")
public Character(char value) 

Source Link

Document

Constructs a newly allocated Character object that represents the specified char value.

Usage

From source file:org.opencms.util.CmsDataTypeUtil.java

/**
 * Parses the given data as a char.<p>
 * //from w  ww .j  a v  a2s . c  o m
 * @param data the data to parse
 * 
 * @return the converted data value
 */
public static Character parseChar(String data) {

    return new Character(data.charAt(0));
}

From source file:org.apache.cocoon.taglib.core.ForEachSupport.java

protected ForEachIterator toForEachIterator(char[] a) {
    Character[] wrapped = new Character[a.length];
    for (int i = 0; i < a.length; i++)
        wrapped[i] = new Character(a[i]);
    return new SimpleForEachIterator(Arrays.asList(wrapped).iterator());
}

From source file:es.caib.zkib.jxpath.util.BasicTypeConverter.java

/**
 * Convert a string to a primitive type.
 * @param object String/*from  www .  j  a va 2s  .  co m*/
 * @param toType destination class
 * @return wrapper
 */
protected Object convertStringToPrimitive(Object object, Class toType) {
    toType = TypeUtils.wrapPrimitive(toType);
    if (toType == Boolean.class) {
        return Boolean.valueOf((String) object);
    }
    if (toType == Character.class) {
        return new Character(((String) object).charAt(0));
    }
    if (toType == Byte.class) {
        return new Byte((String) object);
    }
    if (toType == Short.class) {
        if ("".equals(object))
            return null;
        else
            return new Short((String) object);
    }
    if (toType == Integer.class) {
        if ("".equals(object))
            return null;
        else
            return new Integer((String) object);
    }
    if (toType == Long.class) {
        if ("".equals(object))
            return null;
        else
            return new Long((String) object);
    }
    if (toType == Float.class) {
        if ("".equals(object))
            return null;
        else
            return new Float((String) object);
    }
    if (toType == Double.class) {
        if ("".equals(object))
            return null;
        else
            return new Double((String) object);
    }
    return null;
}

From source file:com.meiah.core.util.StringUtil.java

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

From source file:org.fourthline.cling.osgi.test.data.OSGiUPnPStringConverter.java

private static Character toCharacter(String string, Character value) {
    return string != null ? Character.valueOf(string.charAt(0)) : value != null ? value : new Character('A');
}

From source file:eionet.gdem.utils.Utils.java

/**
 * Escape single character in text. If the character is already escaped, then avoid double escaping.
 *
 * @param pos// w  w w .j a  v  a 2s. c om
 *            Character position in text.
 * @param text
 *            Text to be escaped.
 * @return Return escaped character.
 */
public static String escapeXML(int pos, String text) {

    if (xmlEscapes == null) {
        setXmlEscapes();
    }
    Character c = new Character(text.charAt(pos));

    for (String esc : xmlEscapes.values()) {
        if (pos + esc.length() < text.length()) {
            String sub = text.substring(pos, pos + esc.length());
            if (sub.equals(esc)) {
                return c.toString();
            }
        }
    }

    if (pos + 1 < text.length() && text.charAt(pos + 1) == '#') {
        int semicolonPos = text.indexOf(';', pos + 1);
        if (semicolonPos != -1) {
            String sub = text.substring(pos + 2, semicolonPos);
            if (sub != null) {
                try {
                    // if the string between # and ; is a number then return
                    // true,
                    // because it is most probably an escape sequence
                    if (Integer.parseInt(sub) >= 0) {
                        return c.toString();
                    }
                } catch (NumberFormatException nfe) {
                }
            }
        }
    }

    String esc = xmlEscapes.get(c);
    if (esc != null) {
        return esc;
    } else if ((int) c > 10000) {
        return "&#" + (int) c + ";";
    } else {
        return c.toString();
    }
}

From source file:net.sf.json.JSONUtils.java

/**
 * Converts an array of primitive chars to objects.<br>
 * <p>//w  w w .ja v a 2s .co  m
 * <strong>This method is not in ArrayUtils. (commons-lang 2.1)</strong>
 * </p>
 * <p>
 * This method returns <code>null</code> for a <code>null</code> input
 * array.
 * </p>
 *
 * @param array a <code>char</code> array
 * @return a <code>Character</code> array, <code>null</code> if null
 *         array input
 */
public static Object[] toObject(char[] array) {
    if (array == null) {
        return null;
    } else if (array.length == 0) {
        return ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY;
    }

    final Character[] result = new Character[array.length];

    for (int i = 0; i < array.length; i++) {
        result[i] = new Character(array[i]);
    }

    return result;
}

From source file:gov.nih.nci.system.web.struts.action.CreateAction.java

public Object convertValue(Class klass, Object value) throws NumberFormatException, Exception {

    String fieldType = klass.getName();
    if (value == null)
        return null;

    Object convertedValue = null;
    try {/*from   w  w  w.j a  v  a 2s  . co  m*/
        if (fieldType.equals("java.lang.Long")) {
            convertedValue = new Long((String) value);
        } else if (fieldType.equals("java.lang.Integer")) {
            convertedValue = new Integer((String) value);
        } else if (fieldType.equals("java.lang.String")) {
            convertedValue = value;
        } else if (fieldType.equals("java.lang.Float")) {
            convertedValue = new Float((String) value);
        } else if (fieldType.equals("java.lang.Double")) {
            convertedValue = new Double((String) value);
        } else if (fieldType.equals("java.lang.Boolean")) {
            convertedValue = new Boolean((String) value);
        } else if (fieldType.equals("java.util.Date")) {
            SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy");
            convertedValue = format.parse((String) value);
        } else if (fieldType.equals("java.net.URI")) {
            convertedValue = new URI((String) value);
        } else if (fieldType.equals("java.lang.Character")) {
            convertedValue = new Character(((String) value).charAt(0));
        } else if (klass.isEnum()) {
            Class enumKlass = Class.forName(fieldType);
            convertedValue = Enum.valueOf(enumKlass, (String) value);
        } else {
            throw new Exception("type mismatch - " + fieldType);
        }

    } catch (NumberFormatException e) {
        e.printStackTrace();
        log.error("ERROR : " + e.getMessage());
        throw e;
    } catch (Exception ex) {
        ex.printStackTrace();
        log.error("ERROR : " + ex.getMessage());
        throw ex;
    }
    return convertedValue;
}

From source file:com.espertech.esper.regression.expr.TestCaseExpr.java

public void testCaseSyntax2StringsNBranches() {
    // Test of the various coercion user cases.
    String caseExpr = "select case intPrimitive" + " when 1 then Boolean.toString(boolPrimitive) "
            + " when 2 then Boolean.toString(boolBoxed) " + " when 3 then Integer.toString(intPrimitive) "
            + " when 4 then Integer.toString(intBoxed)" + " when 5 then Long.toString(longPrimitive) "
            + " when 6 then Long.toString(longBoxed) " + " when 7 then Character.toString(charPrimitive) "
            + " when 8 then Character.toString(charBoxed) " + " when 9 then Short.toString(shortPrimitive) "
            + " when 10 then Short.toString(shortBoxed) " + " when 11 then Byte.toString(bytePrimitive) "
            + " when 12 then Byte.toString(byteBoxed) " + " when 13 then Float.toString(floatPrimitive) "
            + " when 14 then Float.toString(floatBoxed) " + " when 15 then Double.toString(doublePrimitive) "
            + " when 16 then Double.toString(doubleBoxed) " + " when 17 then theString "
            + " else 'x' end as p1 " + " from " + SupportBean.class.getName() + ".win:length(1)";

    EPStatement selectTestCase = epService.getEPAdministrator().createEPL(caseExpr);
    selectTestCase.addListener(testListener);
    assertEquals(String.class, selectTestCase.getEventType().getPropertyType("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 1, new Integer(0), 0L, new Long(0L), '0', new Character('a'),
            (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0,
            new Double(0.0), null, SupportEnum.ENUM_VALUE_1);
    EventBean theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("true", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 2, new Integer(0), 0L, new Long(0L), '0', new Character('a'),
            (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0,
            new Double(0.0), null, SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("false", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 3, new Integer(0), 0L, new Long(0L), '0', new Character('a'),
            (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0,
            new Double(0.0), null, SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("3", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 4, new Integer(4), 0L, new Long(0L), '0', new Character('a'),
            (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0,
            new Double(0.0), null, SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("4", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 5, new Integer(0), 5L, new Long(0L), '0', new Character('a'),
            (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0,
            new Double(0.0), null, SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("5", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 6, new Integer(0), 0L, new Long(6L), '0', new Character('a'),
            (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0,
            new Double(0.0), null, SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("6", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 7, new Integer(0), 0L, new Long(0L), 'A', new Character('a'),
            (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0,
            new Double(0.0), null, SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("A", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 8, new Integer(0), 0L, new Long(0L), 'A', new Character('a'),
            (short) 0, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0,
            new Double(0.0), null, SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("a", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 9, new Integer(0), 0L, new Long(0L), 'A', new Character('a'),
            (short) 9, new Short((short) 0), (byte) 0, new Byte((byte) 0), 0.0f, new Float((float) 0), 0.0,
            new Double(0.0), null, SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("9", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 10, new Integer(0), 0L, new Long(0L), 'A',
            new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f,
            new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("10", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 11, new Integer(0), 0L, new Long(0L), 'A',
            new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f,
            new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("11", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 12, new Integer(0), 0L, new Long(0L), 'A',
            new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f,
            new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("12", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 13, new Integer(0), 0L, new Long(0L), 'A',
            new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f,
            new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("13.0", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 14, new Integer(0), 0L, new Long(0L), 'A',
            new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f,
            new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("14.0", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 15, new Integer(0), 0L, new Long(0L), 'A',
            new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f,
            new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("15.0", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 16, new Integer(0), 0L, new Long(0L), 'A',
            new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f,
            new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("16.0", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), 17, new Integer(0), 0L, new Long(0L), 'A',
            new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f,
            new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("testCoercion", theEvent.get("p1"));

    sendSupportBeanEvent(true, new Boolean(false), -1, new Integer(0), 0L, new Long(0L), 'A',
            new Character('a'), (short) 9, new Short((short) 10), (byte) 11, new Byte((byte) 12), 13.0f,
            new Float((float) 14), 15.0, new Double(16.0), "testCoercion", SupportEnum.ENUM_VALUE_1);
    theEvent = testListener.getAndResetLastNewData()[0];
    assertEquals("x", theEvent.get("p1"));
}

From source file:org.regenstrief.util.Util.java

/**
 * parses String txt into a Vector of String objects by breaking it at every occurrence of a
 * delimiter character/*w ww .j a v a2 s.  c o  m*/
 * 
 * @param txtValue text to be parsed
 * @param dlmChar delimiter character at which to split the <code>txtValue</code>
 * @return list of text values parsed out of <code>txtValue</code>; <br>
 *         <code>dlmChar</code> will not be included in any of the returned text values; <br>
 *         if <code>dlmChar</code> appears N times in <code>txtValue</code>, N+1 values will be
 *         returned
 **/
public final static Vector<String> parseString(final String txtValue, final char dlmChar) {
    return parseString(txtValue, (new Character(dlmChar)).toString());
}