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:hjow.hgtable.util.DataUtil.java

/**
 * <p>??  ? ??     ? .</p>/*from  www . j  ava2s  .  c om*/
 * 
 * @param target : ?? ?
 * @return    ? ?
 */
public static String remove65279(String target) {
    char[] targetChar = target.toCharArray();

    List<Character> resultChars = new Vector<Character>();
    for (int i = 0; i < targetChar.length; i++) {
        if (((int) targetChar[i]) != 65279)
            resultChars.add(new Character(targetChar[i]));
    }

    char[] newChar = new char[resultChars.size()];
    for (int i = 0; i < newChar.length; i++) {
        newChar[i] = resultChars.get(i);
    }
    return new String(newChar);
}

From source file:com.sun.faces.config.ManagedBeanFactory.java

private Object getConvertedValueConsideringPrimitives(Object value, Class valueType) throws FacesException {
    if (null != value && null != valueType) {
        if (valueType == Boolean.TYPE || valueType == java.lang.Boolean.class) {
            value = Boolean.valueOf(value.toString().toLowerCase());
        } else if (valueType == Byte.TYPE || valueType == java.lang.Byte.class) {
            value = new Byte(value.toString());
        } else if (valueType == Double.TYPE || valueType == java.lang.Double.class) {
            value = new Double(value.toString());
        } else if (valueType == Float.TYPE || valueType == java.lang.Float.class) {
            value = new Float(value.toString());
        } else if (valueType == Integer.TYPE || valueType == java.lang.Integer.class) {
            value = new Integer(value.toString());
        } else if (valueType == Character.TYPE || valueType == java.lang.Character.class) {
            value = new Character(value.toString().charAt(0));
        } else if (valueType == Short.TYPE || valueType == java.lang.Short.class) {
            value = new Short(value.toString());
        } else if (valueType == Long.TYPE || valueType == java.lang.Long.class) {
            value = new Long(value.toString());
        } else if (valueType == String.class) {
        } else if (!valueType.isAssignableFrom(value.getClass())) {
            throw new FacesException(
                    Util.getExceptionMessageString(Util.MANAGED_BEAN_TYPE_CONVERSION_ERROR_ID, new Object[] {
                            value.toString(), value.getClass(), valueType, managedBean.getManagedBeanName() }));

        }//from   w  w  w .j a  va 2  s.  c  om
    }
    return value;
}

From source file:com.xwtec.xwserver.util.json.JSONArray.java

/**
 * Construct a JSONArray from an char[].<br>
 *
 * @param array An char[] array./*ww w. j a  v  a  2s .c  o m*/
 */
private static JSONArray _fromArray(char[] array, JsonConfig jsonConfig) {
    if (!addInstance(array)) {
        try {
            return jsonConfig.getCycleDetectionStrategy().handleRepeatedReferenceAsArray(array);
        } catch (JSONException jsone) {
            removeInstance(array);
            fireErrorEvent(jsone, jsonConfig);
            throw jsone;
        } catch (RuntimeException e) {
            removeInstance(array);
            JSONException jsone = new JSONException(e);
            fireErrorEvent(jsone, jsonConfig);
            throw jsone;
        }
    }
    fireArrayStartEvent(jsonConfig);
    JSONArray jsonArray = new JSONArray();
    for (int i = 0; i < array.length; i++) {
        Character c = new Character(array[i]);
        jsonArray.addValue(c, jsonConfig);
        fireElementAddedEvent(i, c, jsonConfig);
    }

    removeInstance(array);
    fireArrayEndEvent(jsonConfig);
    return jsonArray;
}

From source file:org.skyscreamer.nevado.jms.message.NevadoStreamMessage.java

/**
 * Reads an object from the stream message. <p/>
 * <P>/*from   w  w  w.  j ava 2s.c  om*/
 * This method can be used to return, in objectified format, an object in
 * the Java programming language ("Java object") that has been written to
 * the stream with the equivalent <CODE>writeObject</CODE> method call, or
 * its equivalent primitive <CODE>write<I>type</I></CODE> method. <p/>
 * <P>
 * Note that byte values are returned as <CODE>byte[]</CODE>, not <CODE>Byte[]</CODE>.
 * <p/>
 * <P>
 * An attempt to call <CODE>readObject</CODE> to read a byte field value
 * into a new <CODE>byte[]</CODE> object before the full value of the byte
 * field has been read will throw a <CODE>MessageFormatException</CODE>.
 *
 * @return a Java object from the stream message, in objectified format (for
 *         example, if the object was written as an <CODE>int</CODE>, an
 *         <CODE>Integer</CODE> is returned)
 * @throws JMSException
 *             if the JMS provider fails to read the message due to some
 *             internal error.
 * @throws MessageEOFException
 *             if unexpected end of message stream has been reached.
 * @throws MessageFormatException
 *             if this type conversion is invalid.
 * @throws MessageNotReadableException
 *             if the message is in write-only mode.
 * @see #readBytes(byte[] value)
 */

public Object readObject() throws JMSException {
    initializeReading();
    try {
        this.dataIn.mark(65);
        int type = this.dataIn.read();
        if (type == -1) {
            throw new MessageEOFException("reached end of data");
        }
        if (type == MarshallingSupport.NULL) {
            return null;
        }
        if (type == MarshallingSupport.BIG_STRING_TYPE) {
            return MarshallingSupport.readUTF8(dataIn);
        }
        if (type == MarshallingSupport.STRING_TYPE) {
            return this.dataIn.readUTF();
        }
        if (type == MarshallingSupport.LONG_TYPE) {
            return new Long(this.dataIn.readLong());
        }
        if (type == MarshallingSupport.INTEGER_TYPE) {
            return new Integer(this.dataIn.readInt());
        }
        if (type == MarshallingSupport.SHORT_TYPE) {
            return new Short(this.dataIn.readShort());
        }
        if (type == MarshallingSupport.BYTE_TYPE) {
            return new Byte(this.dataIn.readByte());
        }
        if (type == MarshallingSupport.FLOAT_TYPE) {
            return new Float(this.dataIn.readFloat());
        }
        if (type == MarshallingSupport.DOUBLE_TYPE) {
            return new Double(this.dataIn.readDouble());
        }
        if (type == MarshallingSupport.BOOLEAN_TYPE) {
            return this.dataIn.readBoolean() ? Boolean.TRUE : Boolean.FALSE;
        }
        if (type == MarshallingSupport.CHAR_TYPE) {
            return new Character(this.dataIn.readChar());
        }
        if (type == MarshallingSupport.BYTE_ARRAY_TYPE) {
            int len = this.dataIn.readInt();
            byte[] value = new byte[len];
            this.dataIn.readFully(value);
            return value;
        } else {
            this.dataIn.reset();
            throw new MessageFormatException("unknown type");
        }
    } catch (NumberFormatException mfe) {
        try {
            this.dataIn.reset();
        } catch (IOException ioe) {
            JMSException jmsEx = new MessageFormatException(ioe.getMessage());
            jmsEx.setLinkedException(ioe);
            throw jmsEx;
        }
        throw mfe;

    } catch (EOFException e) {
        JMSException jmsEx = new MessageEOFException(e.getMessage());
        jmsEx.setLinkedException(e);
        throw jmsEx;
    } catch (IOException e) {
        JMSException jmsEx = new MessageFormatException(e.getMessage());
        jmsEx.setLinkedException(e);
        throw jmsEx;
    }
}

From source file:eionet.util.Util.java

/**
 * XML-escape one character in a string. Does not do it if it looks like
 * the string is already escaped. Also doesn't escape if the content is
 * a numeric entity.//www . j av  a  2  s.co  m
 *
 * @param pos the position of the character
 * @param text the string.
 * @return the escaped character.
 */
public static String escapeXML(int pos, String text) {

    if (xmlEscapes == null) {
        setXmlEscapes();
    }
    Character c = new Character(text.charAt(pos));
    for (Enumeration e = xmlEscapes.elements(); e.hasMoreElements();) {
        String esc = (String) e.nextElement();
        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 = (String) xmlEscapes.get(c);
    if (esc != null) {
        return esc;
    } else {
        return c.toString();
    }
}

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

public void testFromObject_use_wrappers() {
    JSONObject json = JSONObject.fromObject(Boolean.TRUE);
    assertTrue(json.isEmpty());//from  w  w  w.j  a  v a 2  s  .  c  o m
    json = JSONObject.fromObject(new Byte(Byte.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Short(Short.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Integer(Integer.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Long(Long.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Float(Float.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Double(Double.MIN_VALUE));
    assertTrue(json.isEmpty());
    json = JSONObject.fromObject(new Character('A'));
    assertTrue(json.isEmpty());
}

From source file:org.eclipse.kapua.app.console.server.GwtDeviceManagementServiceImpl.java

private Object[] getObjectValue(GwtConfigParameter gwtConfigParam, String[] defaultValues) {
    List<Object> values = new ArrayList<Object>();
    GwtConfigParameterType type = gwtConfigParam.getType();
    switch (type) {
    case BOOLEAN:
        for (String value : defaultValues) {
            values.add(Boolean.valueOf(value));
        }//from   w  w  w  .  j  ava 2 s . co m
        return values.toArray(new Boolean[] {});

    case BYTE:
        for (String value : defaultValues) {
            values.add(Byte.valueOf(value));
        }
        return values.toArray(new Byte[] {});

    case CHAR:
        for (String value : defaultValues) {
            values.add(new Character(value.charAt(0)));
        }
        return values.toArray(new Character[] {});

    case DOUBLE:
        for (String value : defaultValues) {
            values.add(Double.valueOf(value));
        }
        return values.toArray(new Double[] {});

    case FLOAT:
        for (String value : defaultValues) {
            values.add(Float.valueOf(value));
        }
        return values.toArray(new Float[] {});

    case INTEGER:
        for (String value : defaultValues) {
            values.add(Integer.valueOf(value));
        }
        return values.toArray(new Integer[] {});

    case LONG:
        for (String value : defaultValues) {
            values.add(Long.valueOf(value));
        }
        return values.toArray(new Long[] {});

    case SHORT:
        for (String value : defaultValues) {
            values.add(Short.valueOf(value));
        }
        return values.toArray(new Short[] {});

    case PASSWORD:
        for (String value : defaultValues) {
            values.add(new Password(value));
        }
        return values.toArray(new Password[] {});

    case STRING:
    default:
        return defaultValues;
    }
}

From source file:org.apache.axis2.corba.receivers.CorbaUtil.java

public static Object getEmptyValue(DataType type) {
    switch (type.getTypeCode().kind().value()) {
    case TCKind._tk_long:
        return new Integer(0);
    case TCKind._tk_ulong:
        return new Integer(0);
    case TCKind._tk_longlong:
        return new Long(0);
    case TCKind._tk_ulonglong:
        return new Long(0);
    case TCKind._tk_short:
        return new Short("0");
    case TCKind._tk_ushort:
        return new Short("0");
    case TCKind._tk_float:
        return new Float(0f);
    case TCKind._tk_double:
        return new Double(0d);
    case TCKind._tk_char:
        return new Character('0');
    case TCKind._tk_wchar:
        return new Character('0');
    case TCKind._tk_boolean:
        return Boolean.FALSE;
    case TCKind._tk_octet:
        return new Byte("0");
    case TCKind._tk_string:
        return "";
    case TCKind._tk_wstring:
        return "";
    //case TCKind._tk_any: return new Any();
    case TCKind._tk_value:
        return "";
    //case TCKind._tk_objref: return new org.omg.CORBA.Object();
    case TCKind._tk_struct:
        Struct struct = (Struct) type;
        StructValue value = new StructValue(struct);
        Member[] members = struct.getMembers();
        Object[] memberValues = new Object[members.length];
        for (int i = 0; i < members.length; i++) {
            memberValues[i] = getEmptyValue(members[i].getDataType());
        }/*w  ww  . ja  v  a  2s  .c  o  m*/
        value.setMemberValues(memberValues);
        return value;
    case TCKind._tk_enum:
        return new EnumValue((EnumType) type);
    case TCKind._tk_union:
        UnionType unionType = (UnionType) type;
        UnionValue unionValue = new UnionValue(unionType);
        members = unionType.getMembers();
        unionValue.setMemberName(members[0].getName());
        unionValue.setMemberType(members[0].getDataType());
        unionValue.setMemberValue(getEmptyValue(members[0].getDataType()));
        return unionValue;
    case TCKind._tk_alias:
        Typedef typedef = (Typedef) type;
        AliasValue aliasValue = new AliasValue(typedef);
        aliasValue.setValue(getEmptyValue(typedef.getDataType()));
        return aliasValue;
    case TCKind._tk_sequence:
        SequenceType sequenceType = (SequenceType) type;
        SequenceValue sequenceValue = new SequenceValue(sequenceType);
        sequenceValue.setValues(new Object[0]);
        return sequenceValue;
    case TCKind._tk_array:
        ArrayType arrayType = (ArrayType) type;
        ArrayValue arrayValue = new ArrayValue(arrayType);
        Object[] objects = new Object[arrayType.getElementCount()];
        DataType arrayDataType = arrayType.getDataType();
        for (int i = 0; i < objects.length; i++) {
            objects[i] = getEmptyValue(arrayDataType);
        }
        arrayValue.setValues(objects);
        return arrayValue;
    default:
        log.error("ERROR! Invalid dataType");
    }
    return null;
}

From source file:eionet.util.Util.java

private static void setXmlEscapes() {
    xmlEscapes = new Hashtable();
    xmlEscapes.put(new Character('&'), "&amp;");
    xmlEscapes.put(new Character('<'), "&lt;");
    xmlEscapes.put(new Character('>'), "&gt;");
    xmlEscapes.put(new Character('"'), "&quot;");
    xmlEscapes.put(new Character('\''), "&apos;");
}

From source file:org.apache.axis2.databinding.utils.ConverterUtil.java

public static Object convertToObject(char i) {
    return new Character(i);
}