public static final <E,T> Map<E, T> fetchPropertyValueMap(List<T> list, String propertyName, Class<E> type) {
Map<E, T> result = new HashMap<E, T>();
if (CollectionUtils.isEmpty(list)) {
return result;
}
Object obj;
Field field;
try {
for (int i = 0, l = list.size(); i < l; i++) {
obj = list.get(i);
field = obj.getClass().getDeclaredField(propertyName);
field.setAccessible(true);
result.put((E) field.get(obj), (T)obj);
}
} catch (Exception e) {
throw new UnsupportedOperationException(e);
}
return result;
}