Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thing.Builder2 with add() & addOrdered() methods #896

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions java/dev/enola/thing/PredicatesObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -182,4 +187,36 @@ interface Builder<B extends PredicatesObjects> // skipcq: JAVA-E0169
@Override
B build();
}

// TODO How to best name this, and the equivalent in Thing?
interface Builder2<B extends PredicatesObjects> extends PredicatesObjects.Builder<B> {

/**
* Adds one of possibly several value objects for the given predicate IRI.
*
* <p>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<B> add(String predicateIRI, T value);

<@ImmutableTypeParameter T> PredicatesObjects.Builder2<B> add(
String predicateIRI, T value, @Nullable String datatypeIRI);

/**
* Adds one of possibly several value objects for the given predicate IRI - and preserves
* order.
*
* <p>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<B> addOrdered(
String predicateIRI, T value);

<@ImmutableTypeParameter T> PredicatesObjects.Builder2<B> addOrdered(
String predicateIRI, T value, @Nullable String datatypeIRI);

@Override
B build();
}
}
22 changes: 21 additions & 1 deletion java/dev/enola/thing/Thing.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -45,9 +49,25 @@ interface Builder<B extends Thing> extends PredicatesObjects.Builder<B> { // ski

Builder<B> set(String predicateIRI, Object value);

Builder<B> set(String predicateIRI, Object value, String datatypeIRI);
Builder<B> 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<B extends Thing> // skipcq: JAVA-E0169
extends Thing.Builder<B>, PredicatesObjects.Builder2<B> {

<@ImmutableTypeParameter T> Thing.Builder2<B> add(String predicateIRI, T value);

<@ImmutableTypeParameter T> Thing.Builder2<B> add(
String predicateIRI, T value, @Nullable String datatypeIRI);

<@ImmutableTypeParameter T> Thing.Builder2<B> addOrdered(String predicateIRI, T value);

<@ImmutableTypeParameter T> Thing.Builder2<B> addOrdered(
String predicateIRI, T value, @Nullable String datatypeIRI);
}
}
1 change: 1 addition & 0 deletions java/dev/enola/web/netty/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ junit_tests(
"//java/dev/enola/common/io",
"//java/dev/enola/web",
"//java/dev/enola/web/testlib",
"@maven//:com_github_spotbugs_spotbugs_annotations",
],
)
5 changes: 4 additions & 1 deletion java/dev/enola/web/netty/NettyHttpServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import dev.enola.web.WebServer;
import dev.enola.web.testlib.WebServerTestAbstract;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import org.junit.Test;

import java.io.IOException;
Expand All @@ -33,7 +35,8 @@ protected WebServer create(WebHandlers handlers) throws IOException {
}

@Test
public void testServer() throws IOException, InterruptedException {
@SuppressFBWarnings("USM_USELESS_SUBCLASS_METHOD")
public void testServer() throws IOException, InterruptedException { // skipcq: JAVA-W1016
super.testServer();
}
}