#740: ListHelper.java

projectforge-business/src/main/java/org/projectforge/framework/utils/ListHelper.java Lines: 39 · Author: Kai Reinhard · Type: Java utility — 1 method 39 lines · 10 code · 26 comments · 3 blank

Purpose

A 1-method utility class — literally 39 lines (17 of which are the GPLv3 license header). Provides addAll(List<T> list, T... elements) — a varargs convenience for adding multiple elements to a list in a single call. Without this: list.addAll(Arrays.asList(a, b, c)). With this: ListHelper.addAll(list, a, b, c).

Why does this exist? Java's List.addAll() takes a Collection, not varargs. To add individual elements, you must first wrap them in Arrays.asList() — which is verbose when you have 3-4 inline elements. This method is pure syntactic sugar — it does exactly the same thing as list.addAll(Arrays.asList(elements)) with zero additional logic.

In Java 9+, the standard library added List.of(a, b, c) (which returns an immutable list), but since ProjectForge targets Java 17 and this code dates from the Java 8 era, the varargs pattern was a common custom addition. Modern code would use Stream API or List.copyOf() instead.

Design critique

A class with a single 1-line method is generally a code smell — it should either be removed (callers can use Arrays.asList directly) or expanded with more list utilities. However, this pattern (single-method helper classes) is common in ProjectForge's older code, reflecting a development culture where creating a new utility class was preferred over inline boilerplate. In modern ProjectForge Kotlin code, this would be a simple extension function: fun <T> MutableList<T>.addAll(vararg elements: T) — but the Java API doesn't support extension functions, so the class remains.