File tree Expand file tree Collapse file tree 1 file changed +10
-20
lines changed
src/main/java/edu/kit/datamanager/ro_crate/payload Expand file tree Collapse file tree 1 file changed +10
-20
lines changed Original file line number Diff line number Diff line change 10
10
import edu .kit .datamanager .ro_crate .objectmapper .MyObjectMapper ;
11
11
import edu .kit .datamanager .ro_crate .special .JsonUtilFunctions ;
12
12
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 ;
19
15
20
16
/**
21
17
* The crate payload is the class containing all the entities in the crate.
@@ -143,22 +139,16 @@ public void removeEntityById(String id) {
143
139
}
144
140
145
141
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 ()));
149
144
}
150
145
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 ());
162
152
}
163
153
164
154
}
You can’t perform that action at this time.
0 commit comments