I've an ArrayList
of Object
that could contain String
, Date
and Long
. The Object list is nearly mandatory. (I obtain this list through reflection, reading all the member variables of an unknown class.)
ArrayList <Object> values = new ArrayList<Object>();
I build dynamically a query for Alfresco cmis from it:
addObjectToQueryStatement(qs, i+1, values.get(i));
I came only with this idea:
private void addObjectToQueryStatement(QueryStatement qs, int parameterIndex, Object value)
{
if (value instanceof String)
{
qs.setString(parameterIndex, (String) value);
}
else if (value instanceof Date)
{
qs.setDateTime(parameterIndex, (Date)value);
}
else if (value instanceof Long)
{
qs.setNumber(parameterIndex, (Long)value);
}
}
Does it exist a better and more elegant implementation?