diff --git a/java/dev/enola/thing/PredicatesObjects.java b/java/dev/enola/thing/PredicatesObjects.java index 7f70da3c..827ec511 100644 --- a/java/dev/enola/thing/PredicatesObjects.java +++ b/java/dev/enola/thing/PredicatesObjects.java @@ -65,6 +65,11 @@ default boolean isIterable(String predicateIRI) { return value instanceof Iterable; } + default boolean isOrdered(String predicateIRI) { + var value = get(predicateIRI); + return value instanceof List; + } + default boolean isStruct(String predicateIRI) { var value = get(predicateIRI); return value instanceof PredicatesObjects; @@ -182,4 +187,36 @@ interface Builder // skipcq: JAVA-E0169 @Override B build(); } + + // TODO How to best name this, and the equivalent in Thing? + interface Builder2 extends PredicatesObjects.Builder { + + /** + * Adds one of possibly several value objects for the given predicate IRI. + * + *
This is UNORDERED! Insertion order may NOT be preserved. Duplicates are not allowed + * and cause an error. It is an error if this property has already been set to anything else + * than a {@link Set}. + */ + <@ImmutableTypeParameter T> PredicatesObjects.Builder2 add(String predicateIRI, T value); + + <@ImmutableTypeParameter T> PredicatesObjects.Builder2 add( + String predicateIRI, T value, @Nullable String datatypeIRI); + + /** + * Adds one of possibly several value objects for the given predicate IRI - and preserves + * order. + * + *
Duplicates ARE allowed. It is an error if this property has already been set to + * anything else than a {@link List}. + */ + <@ImmutableTypeParameter T> PredicatesObjects.Builder2 addOrdered( + String predicateIRI, T value); + + <@ImmutableTypeParameter T> PredicatesObjects.Builder2 addOrdered( + String predicateIRI, T value, @Nullable String datatypeIRI); + + @Override + B build(); + } } diff --git a/java/dev/enola/thing/Thing.java b/java/dev/enola/thing/Thing.java index ead6d9be..4b67b138 100644 --- a/java/dev/enola/thing/Thing.java +++ b/java/dev/enola/thing/Thing.java @@ -17,8 +17,12 @@ */ package dev.enola.thing; +import com.google.errorprone.annotations.ImmutableTypeParameter; + import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import org.jspecify.annotations.Nullable; + /** * Thing is the central data structure of Enola. * @@ -45,9 +49,24 @@ interface Builder extends PredicatesObjects.Builder { // ski Builder set(String predicateIRI, Object value); - Builder set(String predicateIRI, Object value, String datatypeIRI); + Builder set(String predicateIRI, Object value, @Nullable String datatypeIRI); @Override B build(); } + + // TODO How to best name this, and the equivalent in PredicatesObjects? + @SuppressFBWarnings("NM_SAME_SIMPLE_NAME_AS_INTERFACE") + interface Builder2 extends Thing.Builder, PredicatesObjects.Builder2 { + + <@ImmutableTypeParameter T> Thing.Builder2 add(String predicateIRI, T value); + + <@ImmutableTypeParameter T> Thing.Builder2 add( + String predicateIRI, T value, @Nullable String datatypeIRI); + + <@ImmutableTypeParameter T> Thing.Builder2 addOrdered(String predicateIRI, T value); + + <@ImmutableTypeParameter T> Thing.Builder2 addOrdered( + String predicateIRI, T value, @Nullable String datatypeIRI); + } }