Skip to content

Commit

Permalink
Merge branch 'master' into feature/support-completions-code
Browse files Browse the repository at this point in the history
  • Loading branch information
domko17 committed Nov 15, 2023
2 parents 16af38d + da13c28 commit b7e5b0b
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions infra/util/src/main/java/com/evolveum/midpoint/util/MiscUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,35 @@ public static <T> List<T> asListTreatingNull(T[] values) {
}
}

/**
* Fixed version of {@link #asListTreatingNull(Object[])} that returns "extends T" list, and filters out all non-null values.
*/
@Experimental
@SafeVarargs
public static <T> @NotNull List<? extends T> asListExceptForNull(T... values) {
if (values.length == 0) {
return List.of(); // please use this method directly
} else if (values.length == 1) {
// shortcut for better efficiency
return values[0] != null ? List.of(values[0]) : List.of();
} else {
return Arrays.stream(values)
.filter(Objects::nonNull)
.toList();
}
}

@Deprecated // please use List.of directly
public static <T> List<? extends T> asListExceptForNull() {
return List.of();
}

/** Separate method for efficiency */
@Experimental
public static <T> @NotNull List<? extends T> asListExceptForNull(T value) {
return value != null ? List.of(value) : List.of();
}

public static BigDecimal or0(BigDecimal value) {
return Objects.requireNonNullElse(value, BigDecimal.ZERO);
}
Expand Down

0 comments on commit b7e5b0b

Please sign in to comment.