#742: ObjectHelper.java

projectforge-business/src/main/java/org/projectforge/framework/utils/ObjectHelper.java Lines: 52 · Author: Kai Reinhard · Type: Java utility 52 lines · 27 code · 22 comments · 3 blank

Purpose

Polymorphic "isEmpty" check that handles both strings and numbers. 52 lines with one method — isEmpty(Object... values). Takes varargs of any type, returns true if ALL values are effectively empty. The logic per value:

Used in form validation and data processing to check if a form field has meaningful content. Example: ObjectHelper.isEmpty(user.getFirstName(), user.getLastName()) — returns false if either name has content.

Design critique

The method returns true (empty) when a non-String, non-BigDecimal object is present — this is counterintuitive for booleans, dates, or any type with a meaningful "empty" representation. A Boolean.FALSE value would cause isEmpty(falseObj) to return false (the non-null branch), which semantically means "not empty" even though false is often considered an "empty" boolean. The method is specialized for String and BigDecimal because those are the two main form field types in ProjectForge — text fields and currency fields. A more general approach would have used a Map<Class, Predicate> for extensible type-specific empty checks.