Search in sources :

Example 1 with SetterShort

use of org.apache.apex.malhar.lib.util.PojoUtils.SetterShort in project apex-malhar by apache.

the class RedisPOJOInputOperator method convertMapToObject.

@SuppressWarnings("unchecked")
private Object convertMapToObject(Map<String, String> tuple) {
    try {
        Object mappedObject = objectClass.newInstance();
        for (int i = 0; i < dataColumns.size(); i++) {
            final SupportType type = dataColumns.get(i).getType();
            final String columnName = dataColumns.get(i).getColumnName();
            if (i < setters.size()) {
                String value = tuple.get(columnName);
                switch(type) {
                    case STRING:
                        ((Setter<Object, String>) setters.get(i)).set(mappedObject, value);
                        break;
                    case BOOLEAN:
                        ((SetterBoolean) setters.get(i)).set(mappedObject, Boolean.parseBoolean(value));
                        break;
                    case SHORT:
                        ((SetterShort) setters.get(i)).set(mappedObject, Short.parseShort(value));
                        break;
                    case INTEGER:
                        ((SetterInt) setters.get(i)).set(mappedObject, Integer.parseInt(value));
                        break;
                    case LONG:
                        ((SetterLong) setters.get(i)).set(mappedObject, Long.parseLong(value));
                        break;
                    case FLOAT:
                        ((SetterFloat) setters.get(i)).set(mappedObject, Float.parseFloat(value));
                        break;
                    case DOUBLE:
                        ((SetterDouble) setters.get(i)).set(mappedObject, Double.parseDouble(value));
                        break;
                    default:
                        break;
                }
            }
        }
        return mappedObject;
    } catch (Exception e) {
        DTThrowable.wrapIfChecked(e);
    }
    return null;
}
Also used : SetterLong(org.apache.apex.malhar.lib.util.PojoUtils.SetterLong) SetterDouble(org.apache.apex.malhar.lib.util.PojoUtils.SetterDouble) SetterShort(org.apache.apex.malhar.lib.util.PojoUtils.SetterShort) SupportType(org.apache.apex.malhar.lib.util.FieldInfo.SupportType) Setter(org.apache.apex.malhar.lib.util.PojoUtils.Setter) SetterFloat(org.apache.apex.malhar.lib.util.PojoUtils.SetterFloat) SetterBoolean(org.apache.apex.malhar.lib.util.PojoUtils.SetterBoolean) SetterInt(org.apache.apex.malhar.lib.util.PojoUtils.SetterInt)

Aggregations

SupportType (org.apache.apex.malhar.lib.util.FieldInfo.SupportType)1 Setter (org.apache.apex.malhar.lib.util.PojoUtils.Setter)1 SetterBoolean (org.apache.apex.malhar.lib.util.PojoUtils.SetterBoolean)1 SetterDouble (org.apache.apex.malhar.lib.util.PojoUtils.SetterDouble)1 SetterFloat (org.apache.apex.malhar.lib.util.PojoUtils.SetterFloat)1 SetterInt (org.apache.apex.malhar.lib.util.PojoUtils.SetterInt)1 SetterLong (org.apache.apex.malhar.lib.util.PojoUtils.SetterLong)1 SetterShort (org.apache.apex.malhar.lib.util.PojoUtils.SetterShort)1