List of usage examples for org.apache.commons.lang3.reflect FieldUtils readField
public static Object readField(final Object target, final String fieldName, final boolean forceAccess) throws IllegalAccessException
From source file:ubic.gemma.persistence.util.EntityUtils.java
/** * @param methodName accessor e.g. "getId" * @param <T> the type//from ww w . j ava2 s . c o m * @param entities entities * @param nestedProperty nested property * @return the created map */ public static <T> Map<Long, T> getNestedIdMap(Collection<? extends T> entities, String nestedProperty, String methodName) { Map<Long, T> result = new HashMap<>(); for (T object : entities) { try { result.put(EntityUtils.getId(FieldUtils.readField(object, nestedProperty, true), methodName), object); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } return result; }