public <InfoType> void processExisting(Task task, InfoType[] existing) { if (operation == null) { if (key != null) { InfoType found = null; if (existing != null) { for (InfoType info : existing) { try { Method getKey = info.getClass().getMethod("getKey"); Object infoKey = getKey.invoke(info); if (key.equals(infoKey)) { found = info; } } catch (Exception ex) { throw new RuntimeException("Error getting key from info object", ex); } } } operation = found == null ? ArrayUpdateOperation.add : ArrayUpdateOperation.edit; } else { operation = ArrayUpdateOperation.add; } task.log( "Auto set " + operation + " array operation for " + spec.getClass().getSimpleName() + " key " + key); spec.setOperation(operation); } }