Class<? extends Object> itemClass = item.getClass();
for (Field field : itemClass.getFields()) {
Class<?> fieldType = field.getType();
if (fieldType == PlatformLayerKey.class) {
PlatformLayerKey key;
try {
key = (PlatformLayerKey) field.get(item);
} catch (IllegalAccessException e) {
throw new IllegalStateException("Error getting field: " + field, e);
}
if (key != null) {
PlatformLayerKey newKey = resolveKey(key);
if (newKey != key) {
try {
field.set(item, newKey);
} catch (IllegalAccessException e) {
throw new IllegalStateException("Error setting field: " + field, e);
}
}
}
}
if (fieldType == List.class) {
Type genericFieldType = field.getGenericType();
if (genericFieldType instanceof ParameterizedType) {
ParameterizedType aType = (ParameterizedType) genericFieldType;
Type[] fieldArgTypes = aType.getActualTypeArguments();
if (fieldArgTypes.length == 1) {
Type fieldArgType = fieldArgTypes[0];
if (fieldArgType instanceof Class) {
Class fieldArg = (Class) fieldArgType;
if (fieldArg.equals(PlatformLayerKey.class)) {
List<PlatformLayerKey> list;
try {
list = (List<PlatformLayerKey>) field.get(item);
} catch (IllegalAccessException e) {
throw new IllegalStateException("Error getting field: " + field, e);
}
if (list != null) {
for (int i = 0; i < list.size(); i++) {
PlatformLayerKey key = list.get(i);
PlatformLayerKey newKey = resolveKey(key);
if (newKey != key) {
list.set(i, newKey);
}
}