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
ConstructorsModifierConstructorDescriptionprivateDo not allow instantiation of this class. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAssociates the given property to the given primitive.private static booleanisValidKey(Object primitive) Returnstrueif the given type is a valid key.static ObjectReturns the property of the given primitive type, ornullif none.
-
Field Details
-
SENTINEL_VALUES
The map where to store specific instances. Keys are instances of the primitive wrappers considered as nil. Values are theNilReasonwhy 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 anIntegerinstance having the value 0. We don't want to consider every 0 integer value as nil, but only the specificIntegerinstance 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 anIdentityHashMapand aWeakHashMap. For now we do not use weak references. This means that if a user creates a customNilReasonby a call toNilReason.valueOf(String), and if he uses that nil reason for a primitive type, then that customNilReasoninstance 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
Returnstrueif the given type is a valid key. ThisPrimitiveTypePropertiesclass is a workaround to be used only for final classes on which we have no control. Non-final classes shall implementNilObjectinstead. -
associate
Associates the given property to the given primitive. Theprimitiveargument shall be a specific instance created by thenewkeyword, not a shared instance linkBoolean.FALSEor the values returned byInteger.valueOf(int). -
property
Returns the property of the given primitive type, ornullif none.
-