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.joda.primitives.list.impl.AbstractTestCharList.java

public void testLast_notEmpty() {
    if (isAddSupported() == false) {
        return;//from   ww  w  . j ava  2  s .  com
    }
    resetEmpty();
    CharList plist = (CharList) collection;
    plist.add((char) 0);
    plist.add('A');
    assertEquals(new Character('A'), plist.last());
}

From source file:pe.com.mmh.sisgap.utils.BasicDynaBean.java

/**
 * Return the value of a simple property with the specified name.
 *
 * @param name Name of the property whose value is to be retrieved
 *
 * @exception IllegalArgumentException if there is no property
 *  of the specified name/*from   www .j  a va 2s  .  co m*/
 */
public Object get(String name) {

    // Return any non-null value for the specified property
    Object value = values.get(name);
    if (value != null) {
        return (value);
    }

    // Return a null value for a non-primitive property
    Class type = getDynaProperty(name).getType();
    if (!type.isPrimitive()) {
        return (value);
    }

    // Manufacture default values for primitive properties
    if (type == Boolean.TYPE) {
        return (Boolean.FALSE);
    } else if (type == Byte.TYPE) {
        return (new Byte((byte) 0));
    } else if (type == Character.TYPE) {
        return (new Character((char) 0));
    } else if (type == Double.TYPE) {
        return (new Double((double) 0.0));
    } else if (type == Float.TYPE) {
        return (new Float((float) 0.0));
    } else if (type == Integer.TYPE) {
        return (new Integer((int) 0));
    } else if (type == Long.TYPE) {
        return (new Long((int) 0));
    } else if (type == Short.TYPE) {
        return (new Short((short) 0));
    } else {
        return (null);
    }

}

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

/**
 * Checks if a given name is composed only of the characters <code>a...z,A...Z,0...9</code>
 * and the provided <code>constraints</code>.<p> 
 * //from   ww  w.  jav a2s . c o m
 * If the check fails, an Exception is generated. The provided bundle and key is
 * used to generate the Exception. 4 parameters are passed to the Exception:<ol>
 * <li>The <code>name</code>
 * <li>The first illegal character found
 * <li>The position where the illegal character was found
 * <li>The <code>constraints</code></ol>
 * 
 * @param name the name to check
 * @param contraints the additional character constraints
 * @param key the key to use for generating the Exception (if required)
 * @param bundle the bundle to use for generating the Exception (if required)
 * 
 * @throws CmsIllegalArgumentException if the check fails (generated from the given key and bundle)
 */
public static void checkName(String name, String contraints, String key, I_CmsMessageBundle bundle)
        throws CmsIllegalArgumentException {

    int l = name.length();
    for (int i = 0; i < l; i++) {
        char c = name.charAt(i);
        if (((c < 'a') || (c > 'z')) && ((c < '0') || (c > '9')) && ((c < 'A') || (c > 'Z'))
                && (contraints.indexOf(c) < 0)) {

            throw new CmsIllegalArgumentException(
                    bundle.container(key, new Object[] { name, new Character(c), new Integer(i), contraints }));
        }
    }
}

From source file:net.lightbody.bmp.proxy.jetty.util.TestCase.java

/** Check a a pair of chars for equality.
 *  @param c1       First char to compare
 *  @param c2       Second char to compare
 *  @param check    Description of this check
 *///from w  w w . j a v  a  2s  .c  om
public void checkEquals(char c1, char c2, String check) {
    commonCheckEquals(new Character(c1), new Character(c2), check);
}

From source file:Main.java

private static void addEntity(String entity, int value) {
    decoder.put(entity, (new Character((char) value)).toString());
    if (value < 0x100)
        encoder[value] = entity;/*  w  ww.j a  v a  2  s  .c  o  m*/
}

From source file:org.romaframework.core.schema.SchemaField.java

protected Object convertValue(Object iFieldValue) {
    if (type == null || isArray())
        return iFieldValue;

    SchemaClass typeClass = getType().getSchemaClass();
    if (typeClass.equals(Roma.schema().getSchemaClass(iFieldValue)))
        return iFieldValue;

    String textValue = null;/*from w w w  .j av a2  s .  c o  m*/
    if (iFieldValue instanceof String) {
        textValue = (String) iFieldValue;
    } else if (iFieldValue != null) {
        textValue = iFieldValue.toString();
    }

    Object value = null;

    if (textValue != null) {
        // TRY A SOFT CONVERSION
        if (typeClass.isOfType(Integer.class) || typeClass.isOfType(Integer.TYPE)) {
            try {
                value = textValue.equals("") ? null : Integer.parseInt(textValue);
            } catch (Exception e) {
                value = textValue.equals("") ? null : Double.valueOf(textValue).intValue();
            }
        } else if (typeClass.isOfType(Long.class) || typeClass.isOfType(Long.TYPE)) {
            value = textValue.equals("") ? null : Long.parseLong(textValue);
        } else if (typeClass.isOfType(Short.class) || typeClass.isOfType(Short.TYPE)) {
            value = textValue.equals("") ? null : Short.parseShort(textValue);
        } else if (typeClass.isOfType(Byte.class) || typeClass.isOfType(Byte.TYPE)) {
            value = textValue.equals("") ? null : Byte.parseByte(textValue);
        } else if (typeClass.isOfType(Character.class) || typeClass.isOfType(Character.TYPE)) {
            if (textValue.length() > 0) {
                value = new Character(textValue.charAt(0));
            }
        } else if (typeClass.isOfType(Float.class) || typeClass.isOfType(Float.TYPE)) {
            value = textValue.equals("") ? null : Float.parseFloat(textValue);
        } else if (typeClass.isOfType(Double.class) || typeClass.isOfType(Double.TYPE)) {
            value = textValue.equals("") ? null : Double.parseDouble(textValue);
        } else if (typeClass.isOfType(BigDecimal.class)) {
            value = textValue.equals("") ? null : new BigDecimal(textValue);
        } else if (iFieldValue != null && !typeClass.isArray() && iFieldValue.getClass().isArray()) {
            // DESTINATION VALUE IS NOT AN ARRAY: ASSIGN THE FIRST ONE ELEMENT
            value = ((Object[]) iFieldValue)[0];
        } else {
            value = iFieldValue;
        }
    }

    if (value != null) {
        // TODO is this the right place to do this...?
        Class<?> valueClass = value.getClass();
        // SUCH A MONSTER!!! MOVE THIS LOGIC IN SchemaClass.isAssignableFrom...
        if (value instanceof VirtualObject
                && !(typeClass.getLanguageType() instanceof Class<?>
                        && ((Class<?>) typeClass.getLanguageType()).isAssignableFrom(VirtualObject.class))
                && ((VirtualObject) value).getSuperClassObject() != null) {
            if (ComposedEntity.class
                    .isAssignableFrom(((VirtualObject) value).getSuperClassObject().getClass())) {
                value = ((VirtualObject) value).getSuperClassObject();
                valueClass = value.getClass();
            }
        }

        if (value instanceof ComposedEntity<?> && !typeClass.isAssignableFrom(valueClass)) {
            value = ((ComposedEntity<?>) value).getEntity();
        }
    }

    if (value == null && typeClass.isPrimitive()) {
        log.warn("Cannot set the field value to null for primitive types! Field: " + getEntity() + "." + name
                + " of class " + getType().getName() + ". Setting value to 0.");
        // SET THE VALUE TO 0
        value = SchemaHelper.assignDefaultValueToLiteral(typeClass);
    }
    return value;
}

From source file:Main.java

private static void addXmlEntity(String entity, int value) {
    decoderXml.put(entity, (new Character((char) value)).toString());
    if (value < 0x100)
        encoderXml[value] = entity;//from   www.  j a  v  a 2s  .  c om
}

From source file:org.bedework.util.security.pki.PkiUtil.java

private static String toHex(final byte b) {
    int i = (b >> 4) & 0x0F;
    String tmp;//from   w  w  w .  j  ava 2  s  .  com

    if (i < 10) {
        tmp = Integer.toString(i);
    } else {
        tmp = new Character((char) (('A' + i) - 10)).toString();
    }

    i = b & 0x0F;

    if (i < 10) {
        tmp += Integer.toString(i);
    } else {
        tmp += new Character((char) ('A' + (i - 10))).toString();
    }

    return tmp;
}

From source file:org.jboss.dashboard.factory.PropertyChangeProcessingInstruction.java

protected Object getValueForParameter(String paramValue, Class expectedClass) throws Exception {
    if (log.isDebugEnabled())
        log.debug("Getting value with class " + expectedClass + ", parsing " + paramValue);
    Object object = null;//from w  ww . j ava  2s. c o  m
    if (expectedClass.isArray()) {
        Class componentClass = expectedClass.getComponentType();
        if (componentClass.isArray())
            throw new Exception("Nested array properties are not supported.");
        List objectValue = new ArrayList();
        StringTokenizer stk = new StringTokenizer(paramValue, ARRAYS_DELIMITER, true);
        while (stk.hasMoreTokens()) {
            String token = stk.nextToken();
            int delimiterCount = 0;
            boolean addTrailingToken = true;
            while (ARRAYS_DELIMITER.equals(token)) {
                addTrailingToken = false;
                delimiterCount++;
                if (delimiterCount % 2 == 0) {
                    String lastToken = (String) objectValue.get(objectValue.size() - 1);
                    objectValue.set(objectValue.size() - 1, lastToken + ARRAYS_DELIMITER);
                    if (stk.hasMoreTokens()) {
                        token = stk.nextToken();
                        if (!ARRAYS_DELIMITER.equals(token)) {
                            lastToken = (String) objectValue.get(objectValue.size() - 1);
                            objectValue.remove(objectValue.size() - 1);
                            objectValue.add(lastToken + token);
                        }
                    } else {
                        addTrailingToken = false;
                        break;
                    }
                } else if (delimiterCount % 2 == 1 && !stk.hasMoreTokens()) {
                    objectValue.add("");
                } else if (stk.hasMoreTokens()) {
                    token = stk.nextToken();
                    addTrailingToken = true;
                }
            }
            if (addTrailingToken) {
                objectValue.add(token);
            }
        }
        for (int i = 0; i < objectValue.size(); i++) {
            String s = (String) objectValue.get(i);
            objectValue.set(i, getValueForParameter(s, componentClass));
        }

        Object baseObjectArray = getBaseArray(componentClass, objectValue.size());
        object = objectValue.toArray((Object[]) baseObjectArray);
    } else {
        if (String.class.equals(expectedClass)) {
            object = paramValue;
        } else if (expectedClass.equals(int.class)) {
            object = new Integer(toInt(paramValue));
        } else if (expectedClass.equals(boolean.class)) {
            object = (toBoolean(paramValue)) ? Boolean.TRUE : Boolean.FALSE;
        } else if (expectedClass.equals(long.class)) {
            object = new Long(toLong(paramValue));
        } else if (expectedClass.equals(char.class)) {
            object = new Character(toChar(paramValue));
        } else if (expectedClass.equals(double.class)) {
            object = new Double(toDouble(paramValue));
        } else if (expectedClass.equals(float.class)) {
            object = new Float(toFloat(paramValue));
        } else if (expectedClass.equals(byte.class)) {
            object = new Byte(toByte(paramValue));
        } else if (expectedClass.equals(short.class)) {
            object = new Short(toShort(paramValue));
        } else if (expectedClass.equals(File.class)) {
            object = toFile(paramValue);
        } else if (expectedClass.equals(Integer.class)) {
            object = new Integer(toInt(paramValue));
        } else if (expectedClass.equals(Boolean.class)) {
            object = (toBoolean(paramValue)) ? Boolean.TRUE : Boolean.FALSE;
        } else if (expectedClass.equals(Long.class)) {
            object = new Long(toLong(paramValue));
        } else if (expectedClass.equals(Character.class)) {
            object = new Character(toChar(paramValue));
        } else if (expectedClass.equals(Double.class)) {
            object = new Double(toDouble(paramValue));
        } else if (expectedClass.equals(Float.class)) {
            object = new Float(toFloat(paramValue));
        } else if (expectedClass.equals(Byte.class)) {
            object = new Byte(toByte(paramValue));
        } else if (expectedClass.equals(Short.class)) {
            object = new Short(toShort(paramValue));
        } else { //It will be a component
            object = toComponent(paramValue);
        }
    }
    return object;
}

From source file:com.skelril.ShivtrAuth.AuthenticationCore.java

public synchronized void loadCharacters(JSONObject[] characters) {

    // Remove Old Characters
    this.characters.clear();

    // Add all new Characters
    for (JSONObject aCharacter : characters) {
        this.characters.put(aCharacter.get("name").toString().trim().toLowerCase(),
                new Character(aCharacter.get("name").toString()));
    }//from w w  w.  j ava 2  s. c o m
}