gchq / MagmaCore

Magma Core is a collection of Java Classes and utilities to enable HQDM objects and patterns to be created and consumed as RDF Linked Data.
Apache License 2.0
26 stars 4 forks source link

Update Top.java to reduce code clutter #189

Closed twalmsley closed 8 months ago

twalmsley commented 9 months ago

It is very common to need a single value from a possible Set of values obtained using this method in Top.java:

Set<Object> value(Object predicateId);

So the client code ends up with code similar to this in many places, which looks ugly and is hard to read:

String s = (String) entity.value(HQDM.ENTITY_NAME).iterator().next();

I suggest replacing it with two methods like this:

<T> T oneValue(IRI predicate) {...}
<T> Set<T> values(IRI predicate) {...}

Using method names different from value will force clients to choose the correct new method and clear up the code clutter.