Package org.apache.sis.internal.jaxb
Class PrimitiveTypeProperties
java.lang.Object
org.apache.sis.internal.jaxb.PrimitiveTypeProperties
A workaround for attaching properties (
nilreason
, href
, etc.) to primitive type wrappers.
The normal approach in SIS is to implement the NilObject
interface. However, we cannot
do so when the object is a final Java class like Boolean
, Integer
, Double
or String
.
This class provides a workaround using specific instances of those wrappers.- Since:
- 0.4
- Version:
- 0.4
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe map where to store specific instances. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Do not allow instantiation of this class. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Associates the given property to the given primitive.private static boolean
isValidKey
(Object primitive) Returnstrue
if the given type is a valid key.static Object
Returns the property of the given primitive type, ornull
if none.
-
Field Details
-
SENTINEL_VALUES
The map where to store specific instances. Keys are instances of the primitive wrappers considered as nil. Values are theNilReason
why the primitive is missing, or any other property we may want to attach.Identity comparisons
We really need an identity hash map; using theObject.equals(Object)
method is not allowed here. This is because "nil values" are real values. For example if the type isInteger
, then the nil value is anInteger
instance having the value 0. We don't want to consider every 0 integer value as nil, but only the specificInteger
instance used as sentinel value for nil.Weak references
We cannot use weak value references, because we don't want theNilReason
(the map value) to be lost while the sentinel value (the map key) is still in use. We could use weak references for the keys, but JDK 7 does not provides any map implementation which is both anIdentityHashMap
and aWeakHashMap
. For now we do not use weak references. This means that if a user creates a customNilReason
by a call toNilReason.valueOf(String)
, and if he uses that nil reason for a primitive type, then that customNilReason
instance and its sentinel values will never be garbage-collected. We presume that such cases will be rare enough for not being an issue in practice.Synchronization
All accesses to this map shall be synchronized on the map object.
-
-
Constructor Details
-
PrimitiveTypeProperties
private PrimitiveTypeProperties()Do not allow instantiation of this class.
-
-
Method Details
-
isValidKey
Returnstrue
if the given type is a valid key. ThisPrimitiveTypeProperties
class is a workaround to be used only for final classes on which we have no control. Non-final classes shall implementNilObject
instead. -
associate
Associates the given property to the given primitive. Theprimitive
argument shall be a specific instance created by thenew
keyword, not a shared instance linkBoolean.FALSE
or the values returned byInteger.valueOf(int)
. -
property
Returns the property of the given primitive type, ornull
if none.
-