This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/causeway.git
The following commit(s) were added to refs/heads/master by this push:
new 5426a2bd7d CAUSEWAY-3630: quality of life: adds DataTable factory
method
5426a2bd7d is described below
commit 5426a2bd7db10ea8a3472718a6a1ba784915f59b
Author: Andi Huber <[email protected]>
AuthorDate: Tue Mar 5 08:05:00 2024 +0100
CAUSEWAY-3630: quality of life: adds DataTable factory method
- one that accepts a column filter
---
.../core/metamodel/tabular/simple/DataTable.java | 31 ++++++++++++++++++----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git
a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/tabular/simple/DataTable.java
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/tabular/simple/DataTable.java
index 9bb9e6e333..49c36943b7 100644
---
a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/tabular/simple/DataTable.java
+++
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/tabular/simple/DataTable.java
@@ -21,6 +21,7 @@ package org.apache.causeway.core.metamodel.tabular.simple;
import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.Serializable;
+import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;
@@ -63,16 +64,35 @@ public class DataTable implements Serializable {
@Getter private @NonNull String tableFriendlyName;
/**
- * Returns an empty {@link DataTable} for given domain object type.
+ * Returns an empty {@link DataTable} for given domain object type,
+ * with all properties as columns, excluding mixed-in ones.
+ * (For more control on which columns to include,
+ * consider {@link #forDomainType(Class, Predicate)} or a constructor that
fits.)
* <p>
* The table can be populated later on using {@link
DataTable#setDataElements(Iterable)} or
* {@link #setDataElementPojos(Iterable)}.
*/
- public static DataTable forDomainType(final Class<?> domainType) {
+ public static DataTable forDomainType(
+ final @NonNull Class<?> domainType) {
val elementType =
MetaModelContext.instanceElseFail().specForTypeElseFail(domainType);
return new DataTable(elementType);
}
+ /**
+ * Returns an empty {@link DataTable} for given domain object type,
+ * with all (including mixed-in) associations as columns,
+ * that pass given {@code columnFilter}. If the filter is {@code null} it
acts as a pass-through.
+ * <p>
+ * The table can be populated later on using {@link
DataTable#setDataElements(Iterable)} or
+ * {@link #setDataElementPojos(Iterable)}.
+ */
+ public static DataTable forDomainType(
+ final @NonNull Class<?> domainType,
+ final @Nullable Predicate<ObjectAssociation> columnFilter) {
+ val elementType =
MetaModelContext.instanceElseFail().specForTypeElseFail(domainType);
+ return new DataTable(elementType, columnFilter);
+ }
+
/**
* Returns an empty {@link DataTable} for given domain object type,
* with all properties as columns, excluding mixed-in ones.
@@ -94,18 +114,19 @@ public class DataTable implements Serializable {
/**
* Returns an empty {@link DataTable} for given domain object type,
* with all (including mixed-in) associations as columns,
- * that pass given {@code columnFilter}.
+ * that pass given {@code columnFilter}. If the filter is {@code null} it
acts as a pass-through.
* <p>
* The table can be populated later on using {@link
DataTable#setDataElements(Iterable)} or
* {@link #setDataElementPojos(Iterable)}.
*/
public DataTable(
- final @NonNull ObjectSpecification elementType, final
Predicate<ObjectAssociation> columnFilter) {
+ final @NonNull ObjectSpecification elementType,
+ final @Nullable Predicate<ObjectAssociation> columnFilter) {
this(elementType,
elementType.getSingularName(),
elementType
.streamAssociations(MixedIn.INCLUDED)
- .filter(columnFilter)
+
.filter(Optional.ofNullable(columnFilter).orElseGet(_Predicates::alwaysTrue))
.collect(Can.toCan()),
Can.empty());
}