I have designed a generic method to convert list of array of Objects to result into single map. This is working fine, but I want to check weather a key object is valid key (whether it is overriding equals and hashcode method or immutable instance). Am I missing anything else in my code?
/**
@parms
objects : list of array of object generally result of HQL select
keyIndx : index of key object in the array
valueIndex: index of value object in the array
*/
public static Map<? extends Object, ? extends Object> getSingleMapFromLisOfArrayOfObject(List<? extends Object[]> Objects, int keyIdex, int valueIndex)
throws Exception
{
Map<Object, Object> map = null;
if (Objects != null) {
map = new HashMap<Object, Object>(Objects.size());
for (Object[] array : Objects) {
if (Math.max(keyIdex, valueIndex) > (array.length - 1)) {
throw new IndexOutOfBoundsException(keyIdex + " OR " + valueIndex + " out of bound for array");
}
if (array[keyIdex] != null) {
map.put(array[keyIdex], array[valueIndex]);
}
}
}
return (map == null ? Collections.EMPTY_MAP : map);
}