Hey Martin,

-----Original Message-----
From: Martin Desruisseaux <[email protected]>
Organization: Geomatys
Reply-To: "[email protected]" <[email protected]>
Date: Friday, March 29, 2013 4:29 PM
To: Apache SIS <[email protected]>
Subject: On null collections

>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?

How about Collections.unmodifiable{List|Map|etc}?

>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...

Let me know what you think about the un-modifiable option. Thanks!

Cheers,
Chris

>
>     Martin
>
>[1] 
>http://www.geoapi.org/snapshot/javadoc/org/opengis/metadata/quality/DataQu
>ality.html
>

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Chris Mattmann, Ph.D.
Senior Computer Scientist
NASA Jet Propulsion Laboratory Pasadena, CA 91109 USA
Office: 171-266B, Mailstop: 171-246
Email: [email protected]
WWW:  http://sunset.usc.edu/~mattmann/
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adjunct Assistant Professor, Computer Science Department
University of Southern California, Los Angeles, CA 90089 USA
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++





Reply via email to