Example usage for java.lang Character valueOf

List of usage examples for java.lang Character valueOf

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static Character valueOf(char c) 

Source Link

Document

Returns a Character instance representing the specified char value.

Usage

From source file:org.apache.openjpa.meta.FieldMetaData.java

/**
 * Return the string value converted to the given type code. The string
 * must be non-null and trimmed./*from  w  ww.  j  av a  2  s .c om*/
 */
private Object transform(String val, int typeCode) {
    if ("null".equals(val))
        return null;

    switch (typeCode) {
    case JavaTypes.BOOLEAN:
    case JavaTypes.BOOLEAN_OBJ:
        return Boolean.valueOf(val);
    case JavaTypes.BYTE:
    case JavaTypes.BYTE_OBJ:
        return Byte.valueOf(val);
    case JavaTypes.INT:
    case JavaTypes.INT_OBJ:
        return Integer.valueOf(val);
    case JavaTypes.LONG:
    case JavaTypes.LONG_OBJ:
        return Long.valueOf(val);
    case JavaTypes.SHORT:
    case JavaTypes.SHORT_OBJ:
        return Short.valueOf(val);
    case JavaTypes.DOUBLE:
    case JavaTypes.DOUBLE_OBJ:
        return Double.valueOf(val);
    case JavaTypes.FLOAT:
    case JavaTypes.FLOAT_OBJ:
        return Float.valueOf(val);
    case JavaTypes.CHAR:
    case JavaTypes.CHAR_OBJ:
        return Character.valueOf(val.charAt(0));
    case JavaTypes.STRING:
        return val;
    case JavaTypes.ENUM:
        return Enum.valueOf((Class<? extends Enum>) getDeclaredType(), val);
    }
    throw new MetaDataException(_loc.get("bad-external-type", this));
}

From source file:org.eclipse.swt.examples.controlexample.Tab.java

void setValue() {
    /* The parameter type must be the same as the get method's return type */
    String methodRoot = nameCombo.getText();
    Class<?> returnType = getReturnType(methodRoot);
    String methodName = setMethodName(methodRoot);
    String value = setText.getText();
    Widget[] widgets = getExampleWidgets();
    for (Widget widget : widgets) {
        try {/*from w w  w  .ja va  2 s  .  c o  m*/
            if (widget == null) {
                continue;
            }
            java.lang.reflect.Method method = widget.getClass().getMethod(methodName, returnType);
            String typeName = returnType.getName();
            Object[] parameter = null;
            if (value.equals("null")) {
                parameter = new Object[] { null };
            } else if (typeName.equals("int")) {
                parameter = new Object[] { Integer.valueOf(value) };
            } else if (typeName.equals("long")) {
                parameter = new Object[] { Long.valueOf(value) };
            } else if (typeName.equals("char")) {
                parameter = new Object[] {
                        value.length() == 1 ? Character.valueOf(value.charAt(0)) : Character.valueOf('\0') };
            } else if (typeName.equals("boolean")) {
                parameter = new Object[] { Boolean.valueOf(value) };
            } else if (typeName.equals("java.lang.String")) {
                parameter = new Object[] { value };
            } else if (typeName.equals("org.eclipse.swt.graphics.Point")) {
                String xy[] = split(value, ',');
                parameter = new Object[] { new Point(Integer.parseInt(xy[0]), Integer.parseInt(xy[1])) };
            } else if (typeName.equals("org.eclipse.swt.graphics.Rectangle")) {
                String xywh[] = split(value, ',');
                parameter = new Object[] { new Rectangle(Integer.parseInt(xywh[0]), Integer.parseInt(xywh[1]),
                        Integer.parseInt(xywh[2]), Integer.parseInt(xywh[3])) };
            } else if (typeName.equals("[I")) {
                String strings[] = split(value, ',');
                int[] ints = new int[strings.length];
                for (int j = 0; j < strings.length; j++) {
                    ints[j] = Integer.valueOf(strings[j]).intValue();
                }
                parameter = new Object[] { ints };
            } else if (typeName.equals("[C")) {
                String strings[] = split(value, ',');
                char[] chars = new char[strings.length];
                for (int j = 0; j < strings.length; j++) {
                    chars[j] = strings[j].charAt(0);
                }
                parameter = new Object[] { chars };
            } else if (typeName.equals("[Ljava.lang.String;")) {
                parameter = new Object[] { split(value, ',') };
            } else {
                parameter = parameterForType(typeName, value, widget);
            }
            method.invoke(widget, parameter);
        } catch (Exception e) {
            Throwable cause = e.getCause();
            String message = e.getMessage();
            getText.setText(e.toString());
            if (cause != null)
                getText.append(", cause=\n" + cause.toString());
            if (message != null)
                getText.append(", message=\n" + message);
        }
    }
}

From source file:org.plasma.sdo.helper.DataConverter.java

/**
 * Converts the given string value to an object appropriate
 * for the target type. If java.util.Arrays formatting
 * is detected for the given string value, the formatting is
 * removed and the arrays converted into a list
 * of elements appropriate for the target type.
 * @param targetType the target data type
 * @param value the value//from w  ww . j av  a 2  s. c  o m
 * @return the converted value
 */
public Object fromString(Type targetType, String value) {
    DataType targetDataType = DataType.valueOf(targetType.getName());
    switch (targetDataType) {
    case String:
        if (!value.startsWith("[")) {
            return value;
        } else {
            String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
            List<String> list = new ArrayList<String>();
            for (String arrayValue : strings)
                list.add(arrayValue);
            return list;
        }
    case Decimal:
        if (!value.startsWith("[")) {
            return new BigDecimal(value);
        } else {
            String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
            List<BigDecimal> list = new ArrayList<BigDecimal>();
            for (String arrayValue : strings)
                list.add(new BigDecimal(arrayValue));
            return list;
        }
    case Bytes:
        if (!value.startsWith("[")) {
            return value.getBytes(); // FIXME: charset?
        } else {
            String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
            List<byte[]> list = new ArrayList<byte[]>();
            for (String arrayValue : strings)
                list.add(value.getBytes()); // FIXME: charset?
            return list;
        }
    case Byte:
        if (!value.startsWith("[")) {
            byte[] byteArray = value.getBytes(); // FIXME: charset?
            return new Byte(byteArray[0]); //TODO: truncation warning?
        } else {
            String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
            List<Byte> list = new ArrayList<Byte>();
            byte[] byteArray = null;
            for (String arrayValue : strings) {
                byteArray = arrayValue.getBytes();
                list.add(new Byte(byteArray[0]));
            }
            return list;
        }
    case Boolean:
        if (!value.startsWith("[")) {
            return Boolean.valueOf(value);
        } else {
            String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
            List<Boolean> list = new ArrayList<Boolean>();
            for (String arrayValue : strings)
                list.add(Boolean.valueOf(arrayValue));
            return list;
        }
    case Character:
        if (!value.startsWith("[")) {
            return Character.valueOf(value.charAt(0)); // TODO: truncation warning?
        } else {
            String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
            List<Character> list = new ArrayList<Character>();
            for (String arrayValue : strings)
                list.add(Character.valueOf(arrayValue.charAt(0)));
            return list;
        }
    case Double:
        if (!value.startsWith("[")) {
            return Double.valueOf(value);
        } else {
            String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
            List<Double> list = new ArrayList<Double>();
            for (String arrayValue : strings)
                list.add(Double.valueOf(arrayValue));
            return list;
        }
    case Float:
        if (!value.startsWith("[")) {
            return Float.valueOf(value);
        } else {
            String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
            List<Float> list = new ArrayList<Float>();
            for (String arrayValue : strings)
                list.add(Float.valueOf(arrayValue));
            return list;
        }
    case Int:
        if (!value.startsWith("[")) {
            return Integer.valueOf(value);
        } else {
            String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
            List<Integer> list = new ArrayList<Integer>();
            for (String arrayValue : strings)
                list.add(Integer.valueOf(arrayValue));
            return list;
        }
    case Integer:
        if (!value.startsWith("[")) {
            return new BigInteger(value);
        } else {
            String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
            List<BigInteger> list = new ArrayList<BigInteger>();
            for (String arrayValue : strings)
                list.add(new BigInteger(arrayValue));
            return list;
        }
    case Long:
        if (!value.startsWith("[")) {
            return Long.valueOf(value);
        } else {
            String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
            List<Long> list = new ArrayList<Long>();
            for (String arrayValue : strings)
                list.add(Long.valueOf(arrayValue));
            return list;
        }
    case Short:
        if (!value.startsWith("[")) {
            return Short.valueOf(value);
        } else {
            String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
            List<Short> list = new ArrayList<Short>();
            for (String arrayValue : strings)
                list.add(Short.valueOf(arrayValue));
            return list;
        }
    case Strings:
        if (!value.startsWith("[")) {
            String[] values = value.split("\\s");
            List<String> list = new ArrayList<String>(values.length);
            for (int i = 0; i < values.length; i++)
                list.add(values[i]);
            return list;
        } else {
            // don't replace whitespace internal to individual 'strings' value
            String tempValue = value.replaceAll("[\\[\\]]", "");
            tempValue.trim(); // just trim Arrays formatting
            String[] strings = tempValue.split(",");
            List<List<String>> list = new ArrayList<List<String>>();
            for (String arrayValue : strings) {
                String[] values = arrayValue.split("\\s");
                List<String> subList = new ArrayList<String>(values.length);
                for (int i = 0; i < values.length; i++)
                    subList.add(values[i]);
                list.add(subList);
            }
            return list;
        }
    case Date:
        try {
            if (!value.startsWith("[")) {
                return getDateFormat().parse(value);
            } else {
                String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
                List<Date> list = new ArrayList<Date>();
                for (String arrayValue : strings)
                    list.add(getDateFormat().parse(arrayValue));
                return list;
            }
        } catch (ParseException e) {
            throw new PlasmaDataObjectException(e);
        }
    case DateTime:
    case Month:
    case MonthDay:
    case URI:
    case Day:
    case Duration:
    case Time:
    case Year:
    case YearMonth:
    case YearMonthDay:
        // TODO: See lexical XML Schema string representation for these types
        if (!value.startsWith("[")) {
            return value;
        } else {
            String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
            List<String> list = new ArrayList<String>();
            for (String arrayValue : strings)
                list.add(arrayValue);
            return list;
        }
    default:
        throw new InvalidDataConversionException(targetDataType, DataType.String, value);
    }
}

From source file:org.egov.pims.service.EmployeeServiceImpl.java

public boolean checkPos(Integer posId, Date fromDate, Date toDate, Integer empId, String isPrimary) {

    boolean b = false;

    try {/*from   ww w . j  a v a 2 s  .c o m*/
        Query qry = null;

        if (fromDate != null && toDate != null) {
            String main = "from Assignment ev  where ev.isPrimary =:isPrimary and ev.position.id = :posId and ";
            if (empId != null) {
                main += "ev.employee.idPersonalInformation <>:empId and ";
            }
            main += "((ev.toDate is null ) or " + " (ev.fromDate <= :fromDate and ev.toDate >= :toDate) or "
                    + " (ev.toDate <= :toDate and ev.toDate >= :fromDate) or "
                    + " (ev.fromDate >= :fromDate and ev.fromDate <= :toDate))  ";

            qry = getCurrentSession().createQuery(main);

        } else if (fromDate != null && toDate == null) {
            qry = getCurrentSession().createQuery(
                    "from Assignment ev  where ev.position.id = :posId and ((ev.toDate is null ) or (ev.fromDate <= :fromDate AND ev.toDate >= :fromDate))");

        }
        if (posId != null) {
            qry.setInteger("posId", posId);

        }
        if (empId != null) {
            qry.setInteger("empId", empId);

        }
        if (isPrimary != null) {
            qry.setCharacter("isPrimary", Character.valueOf(isPrimary.charAt(0)));
        }
        if (fromDate != null && toDate != null) {
            qry.setDate("fromDate", new java.sql.Date(fromDate.getTime()));
            qry.setDate("toDate", new java.sql.Date(toDate.getTime()));

        } else if (fromDate != null && toDate == null) {
            qry.setDate("fromDate", new java.sql.Date(fromDate.getTime()));
        }

        if (qry.list() != null && !qry.list().isEmpty()) {
            b = true;
        }

    } catch (HibernateException he) {
        LOGGER.error(he);
        throw new ApplicationRuntimeException("Exception:" + he.getMessage(), he);
    } catch (Exception he) {
        LOGGER.error(he);
        throw new ApplicationRuntimeException("Exception:" + he.getMessage(), he);

    }
    return b;

}

From source file:org.plasma.sdo.helper.DataConverter.java

/**
 * Converts the given string value to an object appropriate
 * for the target property and its type. If the given property is a 'many' property,
 * java.util.Arrays formatting is expected.
 * Any java.util.Arrays formatting is/*w w w. ja v a 2  s.  c o  m*/
 * removed and the arrays converted into a list
 * of elements appropriate for the target type.
 * @param targetType the target data type
 * @param value the value to convert from string
 * @return the converted value
 * @throws IllegalArgumentException if the given property is a 'many' property and no  
 * java.util.Arrays formatting is detected for the given value.
 */
public Object fromString(Property targetProperty, String value) {
    DataType targetDataType = DataType.valueOf(targetProperty.getType().getName());
    switch (targetDataType) {
    case String:
        if (!targetProperty.isMany()) {
            if (!value.startsWith("[")) {
                return value;
            } else { // ignore arrays formatting for singular properties as these are allowed to contain '['
                return value;
            }
        } else {
            if (value.startsWith("[")) {
                String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
                List<String> list = new ArrayList<String>();
                for (String arrayValue : strings)
                    list.add(arrayValue);
                return list;
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting detected for the given value, for the given 'many' property, "
                                + targetProperty.toString());
            }
        }
    case Decimal:
        if (!targetProperty.isMany()) {
            if (!value.startsWith("[")) {
                return new BigDecimal(value);
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting expected for the given value, for the given singular property, "
                                + targetProperty.toString());
            }
        } else {
            if (value.startsWith("[")) {
                String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
                List<BigDecimal> list = new ArrayList<BigDecimal>();
                for (String arrayValue : strings)
                    list.add(new BigDecimal(arrayValue));
                return list;
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting detected for the given value, for the given 'many' property, "
                                + targetProperty.toString());
            }
        }
    case Bytes:
        if (!targetProperty.isMany()) {
            return value.getBytes(); // FIXME: charset?
        } else {
            if (value.startsWith("[")) {
                String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
                List<byte[]> list = new ArrayList<byte[]>();
                for (String arrayValue : strings)
                    list.add(value.getBytes()); // FIXME: charset?
                return list;
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting detected for the given value, for the given 'many' property, "
                                + targetProperty.toString());
            }
        }
    case Byte:
        if (!targetProperty.isMany()) {
            byte[] byteArray = value.getBytes(); // FIXME: charset?
            return new Byte(byteArray[0]); //TODO: truncation warning?
        } else {
            if (value.startsWith("[")) {
                String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
                List<Byte> list = new ArrayList<Byte>();
                byte[] byteArray = null;
                for (String arrayValue : strings) {
                    byteArray = arrayValue.getBytes();
                    list.add(new Byte(byteArray[0]));
                }
                return list;
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting detected for the given value, for the given 'many' property, "
                                + targetProperty.toString());
            }
        }
    case Boolean:
        if (!targetProperty.isMany()) {
            if (!value.startsWith("[")) {
                return Boolean.valueOf(value);
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting expected for the given value, for the given singular property, "
                                + targetProperty.toString());
            }
        } else {
            if (value.startsWith("[")) {
                String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
                List<Boolean> list = new ArrayList<Boolean>();
                for (String arrayValue : strings)
                    list.add(Boolean.valueOf(arrayValue));
                return list;
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting detected for the given value, for the given 'many' property, "
                                + targetProperty.toString());
            }
        }
    case Character:
        if (!targetProperty.isMany()) {
            return Character.valueOf(value.charAt(0)); // TODO: truncation warning?
        } else {
            if (value.startsWith("[")) {
                String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
                List<Character> list = new ArrayList<Character>();
                for (String arrayValue : strings)
                    list.add(Character.valueOf(arrayValue.charAt(0)));
                return list;
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting detected for the given value, for the given 'many' property, "
                                + targetProperty.toString());
            }
        }
    case Double:
        if (!targetProperty.isMany()) {
            if (!value.startsWith("[")) {
                return Double.valueOf(value);
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting expected for the given value, for the given singular property, "
                                + targetProperty.toString());
            }
        } else {
            if (value.startsWith("[")) {
                String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
                List<Double> list = new ArrayList<Double>();
                for (String arrayValue : strings)
                    list.add(Double.valueOf(arrayValue));
                return list;
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting detected for the given value, for the given 'many' property, "
                                + targetProperty.toString());
            }
        }
    case Float:
        if (!targetProperty.isMany()) {
            if (!value.startsWith("[")) {
                return Float.valueOf(value);
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting expected for the given value, for the given singular property, "
                                + targetProperty.toString());
            }
        } else {
            if (value.startsWith("[")) {
                String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
                List<Float> list = new ArrayList<Float>();
                for (String arrayValue : strings)
                    list.add(Float.valueOf(arrayValue));
                return list;
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting detected for the given value, for the given 'many' property, "
                                + targetProperty.toString());
            }
        }
    case Int:
        if (!targetProperty.isMany()) {
            if (!value.startsWith("[")) {
                return Integer.valueOf(value);
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting expected for the given value, for the given singular property, "
                                + targetProperty.toString());
            }
        } else {
            if (value.startsWith("[")) {
                String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
                List<Integer> list = new ArrayList<Integer>();
                for (String arrayValue : strings)
                    list.add(Integer.valueOf(arrayValue));
                return list;
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting detected for the given value, for the given 'many' property, "
                                + targetProperty.toString());
            }
        }
    case Integer:
        if (!targetProperty.isMany()) {
            if (!value.startsWith("[")) {
                return new BigInteger(value);
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting expected for the given value, for the given singular property, "
                                + targetProperty.toString());
            }
        } else {
            if (value.startsWith("[")) {
                String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
                List<BigInteger> list = new ArrayList<BigInteger>();
                for (String arrayValue : strings)
                    list.add(new BigInteger(arrayValue));
                return list;
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting detected for the given value, for the given 'many' property, "
                                + targetProperty.toString());
            }
        }
    case Long:
        if (!targetProperty.isMany()) {
            if (!value.startsWith("[")) {
                return Long.valueOf(value);
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting expected for the given value, for the given singular property, "
                                + targetProperty.toString());
            }
        } else {
            if (value.startsWith("[")) {
                String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
                List<Long> list = new ArrayList<Long>();
                for (String arrayValue : strings)
                    list.add(Long.valueOf(arrayValue));
                return list;
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting detected for the given value, for the given 'many' property, "
                                + targetProperty.toString());
            }
        }
    case Short:
        if (!targetProperty.isMany()) {
            if (!value.startsWith("[")) {
                return Short.valueOf(value);
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting expected for the given value, for the given singular property, "
                                + targetProperty.toString());
            }
        } else {
            if (value.startsWith("[")) {
                String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
                List<Short> list = new ArrayList<Short>();
                for (String arrayValue : strings)
                    list.add(Short.valueOf(arrayValue));
                return list;
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting detected for the given value, for the given 'many' property, "
                                + targetProperty.toString());
            }
        }
    case Strings:
        if (!targetProperty.isMany()) {
            String[] values = value.split("\\s");
            List<String> list = new ArrayList<String>(values.length);
            for (int i = 0; i < values.length; i++)
                list.add(values[i]);
            return list;
        } else {
            if (value.startsWith("[")) {
                // don't replace whitespace internal to individual 'strings' value
                String tempValue = value.replaceAll("[\\[\\]]", "");
                tempValue.trim(); // just trim Arrays formatting
                String[] strings = tempValue.split(",");
                List<List<String>> list = new ArrayList<List<String>>();
                for (String arrayValue : strings) {
                    String[] values = arrayValue.split("\\s");
                    List<String> subList = new ArrayList<String>(values.length);
                    for (int i = 0; i < values.length; i++)
                        subList.add(values[i]);
                    list.add(subList);
                }
                return list;
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting detected for the given value, for the given 'many' property, "
                                + targetProperty.toString());
            }
        }
    case Date:
        try {
            if (!targetProperty.isMany()) {
                return getDateFormat().parse(value);
            } else {
                if (value.startsWith("[")) {
                    String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
                    List<Date> list = new ArrayList<Date>();
                    for (String arrayValue : strings)
                        list.add(getDateFormat().parse(arrayValue));
                    return list;
                } else {
                    throw new IllegalArgumentException(
                            "no java.util.Arrays formatting detected for the given value, for the given 'many' property, "
                                    + targetProperty.toString());
                }
            }
        } catch (ParseException e) {
            throw new PlasmaDataObjectException(e);
        }
    case DateTime:
    case Month:
    case MonthDay:
    case URI:
    case Day:
    case Duration:
    case Time:
    case Year:
    case YearMonth:
    case YearMonthDay:
        if (!targetProperty.isMany()) {
            if (!value.startsWith("[")) {
                // TODO: See lexical XML Schema string representation for these types
                return value;
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting expected for the given value, for the given singular property, "
                                + targetProperty.toString());
            }
        } else {
            if (value.startsWith("[")) {
                String[] strings = value.replaceAll("[\\[\\]\\s]", "").split(",");
                List<String> list = new ArrayList<String>();
                for (String arrayValue : strings)
                    list.add(arrayValue);
                return list;
            } else {
                throw new IllegalArgumentException(
                        "no java.util.Arrays formatting detected for the given value, for the given 'many' property, "
                                + targetProperty.toString());
            }
        }
    default:
        throw new InvalidDataConversionException(targetDataType, DataType.String, value);
    }
}

From source file:org.eclipse.wb.tests.designer.core.util.reflect.ReflectionUtilsTest.java

/**
 * Test for {@link ReflectionUtils#isAssignableFrom(Class, Object)}.
 *//*from  w w  w  .  j a  va 2s . c o m*/
public void test_isAssignableFrom() throws Exception {
    assertTrue(ReflectionUtils.isAssignableFrom(Object.class, new Object()));
    assertTrue(ReflectionUtils.isAssignableFrom(Object.class, "string"));
    assertTrue(ReflectionUtils.isAssignableFrom(String.class, "string"));
    assertFalse(ReflectionUtils.isAssignableFrom(Integer.class, "string"));
    assertFalse(ReflectionUtils.isAssignableFrom(String.class, new Object()));
    // 'null'
    assertTrue(ReflectionUtils.isAssignableFrom(String.class, null));
    assertTrue(ReflectionUtils.isAssignableFrom(Integer.class, null));
    assertFalse(ReflectionUtils.isAssignableFrom(int.class, null));
    // primitives
    assertFalse(ReflectionUtils.isAssignableFrom(int.class, "string"));
    assertTrue(ReflectionUtils.isAssignableFrom(byte.class, Byte.valueOf((byte) 0)));
    assertTrue(ReflectionUtils.isAssignableFrom(char.class, Character.valueOf('0')));
    assertTrue(ReflectionUtils.isAssignableFrom(short.class, Short.valueOf((short) 0)));
    assertTrue(ReflectionUtils.isAssignableFrom(int.class, Integer.valueOf(0)));
    assertTrue(ReflectionUtils.isAssignableFrom(long.class, Long.valueOf(0)));
    assertTrue(ReflectionUtils.isAssignableFrom(float.class, Float.valueOf(0.0f)));
    assertTrue(ReflectionUtils.isAssignableFrom(double.class, Double.valueOf(0.0)));
}

From source file:com.glaf.core.util.DBUtils.java

public static boolean isTableColumn(String columnName) {
    if (columnName == null || columnName.trim().length() < 2 || columnName.trim().length() > 26) {
        return false;
    }/*from   w ww.ja  v  a2  s.co m*/
    char[] sourceChrs = columnName.toCharArray();
    Character chr = Character.valueOf(sourceChrs[0]);
    if (!((chr.charValue() == 95) || (65 <= chr.charValue() && chr.charValue() <= 90)
            || (97 <= chr.charValue() && chr.charValue() <= 122))) {
        return false;
    }
    for (int i = 1; i < sourceChrs.length; i++) {
        chr = Character.valueOf(sourceChrs[i]);
        if (!((chr.charValue() == 95) || (47 <= chr.charValue() && chr.charValue() <= 57)
                || (65 <= chr.charValue() && chr.charValue() <= 90)
                || (97 <= chr.charValue() && chr.charValue() <= 122))) {
            return false;
        }
    }
    return true;
}

From source file:com.glaf.core.util.DBUtils.java

public static boolean isTableName(String sourceString) {
    if (sourceString == null || sourceString.trim().length() < 2 || sourceString.trim().length() > 25) {
        return false;
    }/*  w  w w . j a v  a 2s .c  o  m*/
    char[] sourceChrs = sourceString.toCharArray();
    Character chr = Character.valueOf(sourceChrs[0]);
    if (!((chr.charValue() == 95) || (65 <= chr.charValue() && chr.charValue() <= 90)
            || (97 <= chr.charValue() && chr.charValue() <= 122))) {
        return false;
    }
    for (int i = 1; i < sourceChrs.length; i++) {
        chr = Character.valueOf(sourceChrs[i]);
        if (!((chr.charValue() == 95) || (47 <= chr.charValue() && chr.charValue() <= 57)
                || (65 <= chr.charValue() && chr.charValue() <= 90)
                || (97 <= chr.charValue() && chr.charValue() <= 122))) {
            return false;
        }
    }
    return true;
}

From source file:org.apache.openjpa.kernel.StateManagerImpl.java

public void storeChar(int field, char externalVal) {
    FieldMetaData fmd = _meta.getField(field);
    if (!fmd.isExternalized())
        storeCharField(field, externalVal);
    else//from   w w w .  ja v a  2s  .  c om
        storeField(field, fmd.getFieldValue(Character.valueOf(externalVal), _broker));
}

From source file:com.mawujun.util.ArrayUtils.java

/**
 * <p>Removes occurrences of specified elements, in specified quantities,
 * from the specified array. All subsequent elements are shifted left.
 * For any element-to-be-removed specified in greater quantities than
 * contained in the original array, no change occurs beyond the
 * removal of the existing matching items.</p>
 *
 * <p>This method returns a new array with the same elements of the input
 * array except for the earliest-encountered occurrences of the specified
 * elements. The component type of the returned array is always the same
 * as that of the input array.</p>
 *
 * <pre>/* w  ww. ja  va 2s  .c o m*/
 * ArrayUtils.removeElements(null, 1, 2)      = null
 * ArrayUtils.removeElements([], 1, 2)        = []
 * ArrayUtils.removeElements([1], 2, 3)       = [1]
 * ArrayUtils.removeElements([1, 3], 1, 2)    = [3]
 * ArrayUtils.removeElements([1, 3, 1], 1)    = [3, 1]
 * ArrayUtils.removeElements([1, 3, 1], 1, 1) = [3]
 * </pre>
 *
 * @param array  the array to remove the element from, may be {@code null}
 * @param values the elements to be removed
 * @return A new array containing the existing elements except the
 *         earliest-encountered occurrences of the specified elements.
 * @since 3.0.1
 */
public static char[] removeElements(char[] array, char... values) {
    if (isEmpty(array) || isEmpty(values)) {
        return clone(array);
    }
    HashMap<Character, MutableInt> occurrences = new HashMap<Character, MutableInt>(values.length);
    for (char v : values) {
        Character boxed = Character.valueOf(v);
        MutableInt count = occurrences.get(boxed);
        if (count == null) {
            occurrences.put(boxed, new MutableInt(1));
        } else {
            count.increment();
        }
    }
    HashSet<Integer> toRemove = new HashSet<Integer>();
    for (Map.Entry<Character, MutableInt> e : occurrences.entrySet()) {
        Character v = e.getKey();
        int found = 0;
        for (int i = 0, ct = e.getValue().intValue(); i < ct; i++) {
            found = indexOf(array, v.charValue(), found);
            if (found < 0) {
                break;
            }
            toRemove.add(found++);
        }
    }
    return removeAll(array, extractIndices(toRemove));
}