Let's say we have some entities, every entity has a list of searchable fields and a type. Is there a better (read more efficient way) to map those field in a list for every different type of entity.
Currently what I am doing is :
final Collection<IndexedField> indexedFields = new ArrayList<>();
for (String type : types) {
final Class<? extends IndexedEntity> targetClass = indexedEntities.getClassByType(type);
indexedFields.addAll(indexedEntities.getSearchFieldsFor(targetClass));
}
This works, but is there some better way to achieve this ? Maybe something with stream api.