Skip to content

Commit bb1146b

Browse files
committed
Add eager iterators for collections
Eager iterator uses `List.copyOf()` to avoid concurrent modification exception since the iterated collection could have new members added to it.
1 parent 7db8b73 commit bb1146b

File tree

1 file changed

+11
-0
lines changed
  • gradleutils-shared/src/main/java/net/minecraftforge/gradleutils/shared

1 file changed

+11
-0
lines changed

gradleutils-shared/src/main/java/net/minecraftforge/gradleutils/shared/SharedUtil.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,13 @@ public static void forEachClasspath(ConfigurationContainer configurations, Sourc
312312
|| name.equals(sourceSet.getRuntimeClasspathConfigurationName())
313313
), action);
314314
}
315+
316+
public static void forEachClasspathEagerly(ConfigurationContainer configurations, SourceSet sourceSet, Action<? super Configuration> action) {
317+
forEachEagerly(configurations.named(
318+
name -> name.equals(sourceSet.getCompileClasspathConfigurationName())
319+
|| name.equals(sourceSet.getRuntimeClasspathConfigurationName())
320+
), action);
321+
}
315322
//endregion
316323

317324
//region Domain Object Handling
@@ -329,6 +336,10 @@ public static <T> void forEach(DomainObjectCollection<T> collection, Action<? su
329336
collection.configureEach(action);
330337
}
331338
}
339+
340+
public static <T> void forEachEagerly(DomainObjectCollection<T> collection, Action<? super T> action) {
341+
List.copyOf(collection).forEach(action::execute);
342+
}
332343
//endregion
333344

334345
//region Action Logging

0 commit comments

Comments
 (0)