What this does?:
Interactions
is an Enum whereas Interactable
is an interface (not @Functional Interface). Every Interactable
has a list of Interactions
that it can do. The below code snippet, filters out all the objects that contains any of the provided Interactions
. It does not check for all Interactions
, so if any of the given Interactions
found, it adds the object in interactableList
. Once done iterative over the List
, sends it back to the caller for further processing.
public List<Interactable> getObjectsByInteractions (final Interactions[] interactions) {
final List<Interactable> interactableList = new ArrayList<>();
for (Interactable object : objects) {
List<Interactions> objectInteractions = object.getInteractions();
for (Interactions interactions1 : interactions) {
if (objectInteractions.contains(interactions1)) {
interactableList.add(object);
break;
}
}
}
return interactableList;
}
Concern:
Right now, I am using pre Java 8 code style to achieve the results. Since, it's the time of Java 8, I would request the reviewers to suggest Java 8 style.