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/isis.git
The following commit(s) were added to refs/heads/master by this push:
new 82d005dda2 ISIS-3049: allow Bookmarks to represent null (empty) objects
82d005dda2 is described below
commit 82d005dda2ae3da87600fa190a9265e6d7ba28d9
Author: Andi Huber <[email protected]>
AuthorDate: Thu Jun 2 07:56:49 2022 +0200
ISIS-3049: allow Bookmarks to represent null (empty) objects
---
.../isis/applib/services/bookmark/Bookmark.java | 30 +++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git
a/api/applib/src/main/java/org/apache/isis/applib/services/bookmark/Bookmark.java
b/api/applib/src/main/java/org/apache/isis/applib/services/bookmark/Bookmark.java
index 118f54c803..81ab96d2b9 100644
---
a/api/applib/src/main/java/org/apache/isis/applib/services/bookmark/Bookmark.java
+++
b/api/applib/src/main/java/org/apache/isis/applib/services/bookmark/Bookmark.java
@@ -58,6 +58,19 @@ public final class Bookmark implements Oid {
// -- FACTORIES
+ public static Bookmark empty(
+ final @NonNull LogicalType logicalType) {
+ return emptyForLogicalTypeName(logicalType.getLogicalTypeName());
+ }
+
+ public static Bookmark emptyForLogicalTypeName(
+ final @NonNull String logicalTypeName) {
+ return new Bookmark(
+ logicalTypeName,
+ /*identifier*/null,
+ /*hintId*/null);
+ }
+
public static Bookmark forLogicalTypeNameAndIdentifier(
final @NonNull String logicalTypeName,
final @NonNull String identifier) {
@@ -110,6 +123,10 @@ public final class Bookmark implements Oid {
}
val tokenizer = new StringTokenizer(str, SEPARATOR);
int tokenCount = tokenizer.countTokens();
+ if(tokenCount==1) {
+ return Optional.of(Bookmark.emptyForLogicalTypeName(
+ tokenizer.nextToken()));
+ }
if(tokenCount==2) {
return Optional.of(Bookmark.forLogicalTypeNameAndIdentifier(
tokenizer.nextToken(),
@@ -192,12 +209,19 @@ public final class Bookmark implements Oid {
: stringify(identifier);
}
+ /**
+ * Whether represents {@code null}.
+ */
+ public boolean isEmpty() {
+ return identifier==null;
+ }
+
// -- HELPER
private String stringify(final String id) {
- return logicalTypeName + SEPARATOR + id;
+ return !isEmpty()
+ ? logicalTypeName + SEPARATOR + id
+ : logicalTypeName;
}
-
-
}