Hello all
This is a minor note mostly for information purpose. In my attempt to
fix some known shortcomings that we had with metadata, I was trying
today to enforce some ISO 19115 conditions. The standard often defines
two properties, said A and B, with a constraint of the kind "Only one of
A or B can be set". When A and B are not collection, this is
straightforward: if A is non-null, then B must be null, and conversely.
However this become more tricky with collections. We are encouraged by
numerous books (e.g. "Effective Java") to prefer empty collections over
null collections. This work well in 90% of cases. But it is a bit
problematic with conditional properties in metadata objects. This is
because properties of type Collection in org.apache.sis.metadata are by
design modifiable. This allow us to write:
dataQuality.getReports().add(myReport);
instead of the slightly more tedious:
dataQuality.setReports(Collections.singleton(myReport));
It also allows users to add information instead than replacing it.
However DataQuality [1] have another property, "lineage", and ISO 19115
said that those two properties are mutually exclusive. If the "lineage"
property is set, what should getReports() returns? If it returns an
empty collection, then the user may have the false feeling that he can
add elements to it since this is the pattern in most of the SIS metadata
API. Returning 'null' make clears that this property can not be used,
unless the user clears the lineage property. However users who rely on
the "always prefer empty collections over null" recommendation could get
a NullPointerException.
However I didn't found simple alternative yet (we could create yet
another custom collection implementation, but we may not need such
complication), so I'm tempted to go with null collections in this
particular kind of situations, with clear javadoc...
Martin
[1]
http://www.geoapi.org/snapshot/javadoc/org/opengis/metadata/quality/DataQuality.html