Skip to content

Commit 4e84f97

Browse files
committed
chore: avoid use of list in RoCratePayload
1 parent 9bdaeab commit 4e84f97

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

src/main/java/edu/kit/datamanager/ro_crate/payload/RoCratePayload.java

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@
1010
import edu.kit.datamanager.ro_crate.objectmapper.MyObjectMapper;
1111
import edu.kit.datamanager.ro_crate.special.JsonUtilFunctions;
1212

13-
import java.util.ArrayList;
14-
import java.util.Collection;
15-
import java.util.HashMap;
16-
import java.util.HashSet;
17-
import java.util.List;
18-
import java.util.Set;
13+
import java.util.*;
14+
import java.util.stream.Collectors;
1915

2016
/**
2117
* The crate payload is the class containing all the entities in the crate.
@@ -143,22 +139,16 @@ public void removeEntityById(String id) {
143139
}
144140

145141
private void removeAllOccurrencesOf(String entityId) {
146-
for (var e : this.getAllEntitiesFromIds(this.associatedItems.get(entityId))) {
147-
JsonUtilFunctions.removeFieldsWith(entityId, e.getProperties());
148-
}
142+
this.getEntitiesByIds(this.associatedItems.get(entityId))
143+
.forEach(entity -> JsonUtilFunctions.removeFieldsWith(entityId, entity.getProperties()));
149144
}
150145

151-
private List<AbstractEntity> getAllEntitiesFromIds(Set<String> set) {
152-
List<AbstractEntity> list = new ArrayList<>();
153-
if (set != null) {
154-
for (var element : set) {
155-
var entity = this.getEntityById(element);
156-
if (entity != null) {
157-
list.add(entity);
158-
}
159-
}
160-
}
161-
return list;
146+
private Set<AbstractEntity> getEntitiesByIds(Collection<String> ids) {
147+
if (ids == null) { return new HashSet<>(); }
148+
return ids.stream()
149+
.map(this::getEntityById)
150+
.filter(Objects::nonNull)
151+
.collect(Collectors.toSet());
162152
}
163153

164154
}

0 commit comments

Comments
 (0)