Author: desruisseaux
Date: Fri Mar 29 10:19:28 2013
New Revision: 1462435

URL: http://svn.apache.org/r1462435
Log:
More compact storage of boolean values in metadata objects.

Added:
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/internal/
    
sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/internal/metadata/
    
sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/internal/metadata/MetadataUtilitiesTest.java
   (with props)
Modified:
    
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java
    
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultFeatureCatalogueDescription.java
    
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java
    
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/AbstractGeographicExtent.java
    
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultConformanceResult.java
    
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectified.java
    
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeoreferenceable.java
    
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGridSpatialRepresentation.java
    
sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java

Modified: 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java?rev=1462435&r1=1462434&r2=1462435&view=diff
==============================================================================
--- 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java
 [UTF-8] (original)
+++ 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataUtilities.java
 [UTF-8] Fri Mar 29 10:19:28 2013
@@ -21,6 +21,9 @@ import org.apache.sis.util.Static;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.metadata.InvalidMetadataException;
 
+// Related to JDK7
+import java.util.Objects;
+
 
 /**
  * Miscellaneous utility methods for metadata.
@@ -60,6 +63,48 @@ public final class MetadataUtilities ext
     }
 
     /**
+     * Sets the bit under the given mask for the given boolean value.
+     * This method uses two bits as below:
+     *
+     * <ul>
+     *   <li>{@code 00} - {@code null}</li>
+     *   <li>{@code 10} - {@code Boolean.FALSE}</li>
+     *   <li>{@code 11} - {@code Boolean.TRUE}</li>
+     * </ul>
+     *
+     * @param  flags The set of bits to modify for the given boolean value.
+     * @param  mask  The bit mask, which much have exactly two consecutive 
bits set.
+     * @param  value The boolean value to store in the {@code flags}, or 
{@code null}.
+     * @return The updated {@code flags}.
+     */
+    public static int setBoolean(int flags, final int mask, final Boolean 
value) {
+        assert 3 << Integer.numberOfTrailingZeros(mask) == mask : mask;
+        if (value == null) {
+            flags &= ~mask;
+        } else {
+            flags |= mask;
+            if (!value) {
+                flags &= ~(mask & (mask >>> 1));
+            }
+        }
+        assert Objects.equals(getBoolean(flags, mask), value) : value;
+        return flags;
+    }
+
+    /**
+     * Returns the boolean value for the bits under the given mask.
+     * This method is the reverse of {@link #setBoolean(int, int, Boolean)}.
+     *
+     * @param  flags The set of bits from which to read the boolean value 
under the given mask.
+     * @param  mask  The bit mask, which much have exactly two consecutive 
bits set.
+     * @return The boolean value under the given mask (may be {@code null}).
+     */
+    public static Boolean getBoolean(int flags, final int mask) {
+        flags &= mask;
+        return (flags == 0) ? null : Boolean.valueOf(flags == mask);
+    }
+
+    /**
      * Makes sure that the given inclusion is non-null, then returns its value.
      *
      * @param  value The {@link 
org.opengis.metadata.extent.GeographicBoundingBox#getInclusion()} value.

Modified: 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultFeatureCatalogueDescription.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultFeatureCatalogueDescription.java?rev=1462435&r1=1462434&r2=1462435&view=diff
==============================================================================
--- 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultFeatureCatalogueDescription.java
 [UTF-8] (original)
+++ 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultFeatureCatalogueDescription.java
 [UTF-8] Fri Mar 29 10:19:28 2013
@@ -25,6 +25,9 @@ import org.opengis.util.GenericName;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.content.FeatureCatalogueDescription;
 
+import static org.apache.sis.internal.metadata.MetadataUtilities.getBoolean;
+import static org.apache.sis.internal.metadata.MetadataUtilities.setBoolean;
+
 
 /**
  * Information identifying the feature catalogue.
@@ -53,19 +56,25 @@ public class DefaultFeatureCatalogueDesc
     private static final long serialVersionUID = 1984922846251567908L;
 
     /**
-     * Indication of whether or not the cited feature catalogue complies with 
ISO 19110.
+     * Mask for the {@code compliant} {@link Boolean} value.
+     * Needs 2 bits since the values can be {@code true}, {@code false} or 
{@code null}.
+     *
+     * @see #booleans
      */
-    private Boolean compliant;
+    private static final byte COMPLIANT_MASK = 0b011;
 
     /**
-     * Language(s) used within the catalogue
+     * Mask for the {@code includedWithDataset} {@code boolean} value.
+     * Needs only 1 bit because the value can not be {@code null}.
+     *
+     * @see #booleans
      */
-    private Collection<Locale> languages;
+    private static final byte INCLUDED_MASK = 0b100;
 
     /**
-     * Indication of whether or not the feature catalogue is included with the 
dataset.
+     * Language(s) used within the catalogue
      */
-    private boolean includedWithDataset;
+    private Collection<Locale> languages;
 
     /**
      * Subset of feature types from cited feature catalogue occurring in 
dataset.
@@ -78,6 +87,15 @@ public class DefaultFeatureCatalogueDesc
     private Collection<Citation> featureCatalogueCitations;
 
     /**
+     * The set of {@code boolean} and {@link Boolean} values.
+     * Bits are read and written using the {@code *_MASK} constants.
+     *
+     * @see #COMPLIANT_MASK
+     * @see #INCLUDED_MASK
+     */
+    private byte booleans;
+
+    /**
      * Constructs an initially empty feature catalogue description.
      */
     public DefaultFeatureCatalogueDescription() {
@@ -94,9 +112,9 @@ public class DefaultFeatureCatalogueDesc
      */
     public DefaultFeatureCatalogueDescription(final 
FeatureCatalogueDescription object) {
         super(object);
-        compliant                 = object.isCompliant();
+        booleans                  = object.isIncludedWithDataset() ? 
INCLUDED_MASK : 0;
+        booleans                  = (byte) setBoolean(booleans, 
COMPLIANT_MASK, object.isCompliant());
         languages                 = copyCollection(object.getLanguages(), 
Locale.class);
-        includedWithDataset       = object.isIncludedWithDataset();
         featureTypes              = copyCollection(object.getFeatureTypes(), 
GenericName.class);
         featureCatalogueCitations = 
copyCollection(object.getFeatureCatalogueCitations(), Citation.class);
     }
@@ -132,7 +150,7 @@ public class DefaultFeatureCatalogueDesc
     @Override
     @XmlElement(name = "complianceCode")
     public synchronized Boolean isCompliant() {
-        return compliant;
+        return getBoolean(booleans, COMPLIANT_MASK);
     }
 
     /**
@@ -142,7 +160,7 @@ public class DefaultFeatureCatalogueDesc
      */
     public synchronized void setCompliant(final Boolean newValue) {
         checkWritePermission();
-        compliant = newValue;
+        booleans = (byte) setBoolean(booleans, COMPLIANT_MASK, newValue);
     }
 
     /**
@@ -169,7 +187,7 @@ public class DefaultFeatureCatalogueDesc
     @Override
     @XmlElement(name = "includedWithDataset", required = true)
     public synchronized boolean isIncludedWithDataset() {
-        return includedWithDataset;
+        return (booleans & INCLUDED_MASK) != 0;
     }
 
     /**
@@ -179,7 +197,11 @@ public class DefaultFeatureCatalogueDesc
      */
     public synchronized void setIncludedWithDataset(final boolean newValue) {
         checkWritePermission();
-        includedWithDataset = newValue;
+        if (newValue) {
+            booleans |= INCLUDED_MASK;
+        } else {
+            booleans &= ~INCLUDED_MASK;
+        }
     }
 
     /**

Modified: 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java?rev=1462435&r1=1462434&r2=1462435&view=diff
==============================================================================
--- 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java
 [UTF-8] (original)
+++ 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultImageDescription.java
 [UTF-8] Fri Mar 29 10:19:28 2013
@@ -25,6 +25,9 @@ import org.opengis.metadata.content.Imag
 import org.opengis.metadata.content.ImagingCondition;
 import org.apache.sis.measure.ValueRange;
 
+import static org.apache.sis.internal.metadata.MetadataUtilities.getBoolean;
+import static org.apache.sis.internal.metadata.MetadataUtilities.setBoolean;
+
 
 /**
  * Information about an image's suitability for use.
@@ -59,6 +62,46 @@ public class DefaultImageDescription ext
     private static final long serialVersionUID = -6168624828802439062L;
 
     /**
+     * Mask for the {@code triangulationIndicator} {@link Boolean} value.
+     * Needs 2 bits since the values can be {@code true}, {@code false} or 
{@code null}.
+     *
+     * @see #booleans
+     */
+    private static final short TRIANGULATION_MASK = 3;
+
+    /**
+     * Mask for the {@code radiometricCalibrationDataAvailable} {@link 
Boolean} value.
+     * Needs 2 bits since the values can be {@code true}, {@code false} or 
{@code null}.
+     *
+     * @see #booleans
+     */
+    private static final short RADIOMETRIC_MASK = TRIANGULATION_MASK << 2;
+
+    /**
+     * Mask for the {@code cameraCalibrationInformationAvailable} {@link 
Boolean} value.
+     * Needs 2 bits since the values can be {@code true}, {@code false} or 
{@code null}.
+     *
+     * @see #booleans
+     */
+    private static final short CAMERA_MASK = RADIOMETRIC_MASK << 2;
+
+    /**
+     * Mask for the {@code filmDistortionInformationAvailable} {@link Boolean} 
value.
+     * Needs 2 bits since the values can be {@code true}, {@code false} or 
{@code null}.
+     *
+     * @see #booleans
+     */
+    private static final short FILM_MASK = CAMERA_MASK << 2;
+
+    /**
+     * Mask for the {@code lensDistortionInformationAvailable} {@link Boolean} 
value.
+     * Needs 2 bits since the values can be {@code true}, {@code false} or 
{@code null}.
+     *
+     * @see #booleans
+     */
+    private static final short LENS_MASK = FILM_MASK << 2;
+
+    /**
      * Illumination elevation measured in degrees clockwise from the target 
plane
      * at intersection of the optical line of sight with the EarthÂ’s surface.
      * For images from a scanning device, refer to the centre pixel of the 
image.
@@ -93,36 +136,20 @@ public class DefaultImageDescription ext
     private Identifier processingLevelCode;
 
     /**
-     * Count of the number the number of lossy compression cycles performed on 
the image.
+     * Count of the number of lossy compression cycles performed on the image.
      */
     private Integer compressionGenerationQuantity;
 
     /**
-     * Indication of whether or not triangulation has been performed upon the 
image.
-     */
-    private Boolean triangulationIndicator;
-
-    /**
-     * Indication of whether or not the radiometric calibration information 
for generating the
-     * radiometrically calibrated standard data product is available.
-     */
-    private Boolean radiometricCalibrationDataAvailable;
-
-    /**
-     * Indication of whether or not constants are available which allow for 
camera calibration
-     * corrections.
-     */
-    private Boolean cameraCalibrationInformationAvailable;
-
-    /**
-     * Indication of whether or not Calibration Reseau information is 
available.
-     */
-    private Boolean filmDistortionInformationAvailable;
-
-    /**
-     * Indication of whether or not lens aberration correction information is 
available.
+     * The set of {@link Boolean} values. Bits are read and written using the 
{@code *_MASK} constants.
+     *
+     * @see #TRIANGULATION_MASK
+     * @see #RADIOMETRIC_MASK
+     * @see #CAMERA_MASK
+     * @see #FILM_MASK
+     * @see #LENS_MASK
      */
-    private Boolean lensDistortionInformationAvailable;
+    private short booleans;
 
     /**
      * Constructs an initially empty image description.
@@ -148,11 +175,14 @@ public class DefaultImageDescription ext
         cloudCoverPercentage                  = 
object.getCloudCoverPercentage();
         processingLevelCode                   = 
object.getProcessingLevelCode();
         compressionGenerationQuantity         = 
object.getCompressionGenerationQuantity();
-        triangulationIndicator                = 
object.getTriangulationIndicator();
-        radiometricCalibrationDataAvailable   = 
object.isRadiometricCalibrationDataAvailable();
-        cameraCalibrationInformationAvailable = 
object.isCameraCalibrationInformationAvailable();
-        filmDistortionInformationAvailable    = 
object.isFilmDistortionInformationAvailable();
-        lensDistortionInformationAvailable    = 
object.isLensDistortionInformationAvailable();
+
+        int flags;
+        flags = setBoolean(0,     TRIANGULATION_MASK, 
object.getTriangulationIndicator());
+        flags = setBoolean(flags, RADIOMETRIC_MASK,   
object.isRadiometricCalibrationDataAvailable());
+        flags = setBoolean(flags, CAMERA_MASK,        
object.isCameraCalibrationInformationAvailable());
+        flags = setBoolean(flags, FILM_MASK,          
object.isFilmDistortionInformationAvailable());
+        flags = setBoolean(flags, LENS_MASK,          
object.isLensDistortionInformationAvailable());
+        booleans = (short) flags;
     }
 
     /**
@@ -334,7 +364,7 @@ public class DefaultImageDescription ext
     @Override
     @XmlElement(name = "triangulationIndicator")
     public synchronized Boolean getTriangulationIndicator() {
-        return triangulationIndicator;
+        return getBoolean(booleans, TRIANGULATION_MASK);
     }
 
     /**
@@ -344,7 +374,7 @@ public class DefaultImageDescription ext
      */
     public synchronized void setTriangulationIndicator(final Boolean newValue) 
{
         checkWritePermission();
-        triangulationIndicator = newValue;
+        booleans = (short) setBoolean(booleans, TRIANGULATION_MASK, newValue);
     }
 
     /**
@@ -354,7 +384,7 @@ public class DefaultImageDescription ext
     @Override
     @XmlElement(name = "radiometricCalibrationDataAvailability")
     public synchronized Boolean isRadiometricCalibrationDataAvailable() {
-        return radiometricCalibrationDataAvailable;
+        return getBoolean(booleans, RADIOMETRIC_MASK);
     }
 
     /**
@@ -365,7 +395,7 @@ public class DefaultImageDescription ext
      */
     public synchronized void setRadiometricCalibrationDataAvailable(final 
Boolean newValue) {
         checkWritePermission();
-        radiometricCalibrationDataAvailable = newValue;
+        booleans = (short) setBoolean(booleans, RADIOMETRIC_MASK, newValue);
     }
 
     /**
@@ -375,7 +405,7 @@ public class DefaultImageDescription ext
     @Override
     @XmlElement(name = "cameraCalibrationInformationAvailability")
     public synchronized Boolean isCameraCalibrationInformationAvailable() {
-        return cameraCalibrationInformationAvailable;
+        return getBoolean(booleans, CAMERA_MASK);
     }
 
     /**
@@ -386,7 +416,7 @@ public class DefaultImageDescription ext
      */
     public synchronized void setCameraCalibrationInformationAvailable(final 
Boolean newValue) {
         checkWritePermission();
-        cameraCalibrationInformationAvailable = newValue;
+        booleans = (short) setBoolean(booleans, CAMERA_MASK, newValue);
     }
 
     /**
@@ -395,7 +425,7 @@ public class DefaultImageDescription ext
     @Override
     @XmlElement(name = "filmDistortionInformationAvailability")
     public synchronized Boolean isFilmDistortionInformationAvailable() {
-        return filmDistortionInformationAvailable;
+        return getBoolean(booleans, FILM_MASK);
     }
 
     /**
@@ -405,7 +435,7 @@ public class DefaultImageDescription ext
      */
     public synchronized void setFilmDistortionInformationAvailable(final 
Boolean newValue) {
         checkWritePermission();
-        filmDistortionInformationAvailable = newValue;
+        booleans = (short) setBoolean(booleans, FILM_MASK, newValue);
     }
 
     /**
@@ -414,7 +444,7 @@ public class DefaultImageDescription ext
     @Override
     @XmlElement(name = "lensDistortionInformationAvailability")
     public synchronized Boolean isLensDistortionInformationAvailable() {
-        return lensDistortionInformationAvailable;
+        return getBoolean(booleans, LENS_MASK);
     }
 
     /**
@@ -424,6 +454,6 @@ public class DefaultImageDescription ext
      */
     public synchronized void setLensDistortionInformationAvailable(final 
Boolean newValue) {
         checkWritePermission();
-        lensDistortionInformationAvailable = newValue;
+        booleans = (short) setBoolean(booleans, LENS_MASK, newValue);
     }
 }

Modified: 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/AbstractGeographicExtent.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/AbstractGeographicExtent.java?rev=1462435&r1=1462434&r2=1462435&view=diff
==============================================================================
--- 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/AbstractGeographicExtent.java
 [UTF-8] (original)
+++ 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/AbstractGeographicExtent.java
 [UTF-8] Fri Mar 29 10:19:28 2013
@@ -26,6 +26,9 @@ import org.opengis.metadata.extent.Geogr
 import org.opengis.metadata.extent.BoundingPolygon;
 import org.apache.sis.metadata.iso.ISOMetadata;
 
+import static org.apache.sis.internal.metadata.MetadataUtilities.getBoolean;
+import static org.apache.sis.internal.metadata.MetadataUtilities.setBoolean;
+
 
 /**
  * Base class for geographic area of the dataset.
@@ -51,10 +54,19 @@ public class AbstractGeographicExtent ex
     private static final long serialVersionUID = -8844015895495563161L;
 
     /**
-     * Indication of whether the bounding polygon encompasses an area covered 
by the data
-     * (<cite>inclusion</cite>) or an area where data is not present 
(<cite>exclusion</cite>).
+     * Mask for the {@code inclusion} {@link Boolean} value.
+     * Needs 2 bits since the values can be {@code true}, {@code false} or 
{@code null}.
+     *
+     * @see #booleans
+     */
+    private static final byte INCLUSION_MASK = 3;
+
+    /**
+     * The set of {@link Boolean} values. Bits are read and written using the 
{@code *_MASK} constants.
+     *
+     * @see #INCLUSION_MASK
      */
-    private Boolean inclusion;
+    private byte booleans;
 
     /**
      * Constructs an initially empty geographic extent.
@@ -68,7 +80,7 @@ public class AbstractGeographicExtent ex
      * @param inclusion Whether the bounding polygon encompasses an area 
covered by the data.
      */
     public AbstractGeographicExtent(final boolean inclusion) {
-        this.inclusion = Boolean.valueOf(inclusion);
+        booleans = inclusion ? INCLUSION_MASK : 0;
     }
 
     /**
@@ -82,7 +94,7 @@ public class AbstractGeographicExtent ex
      */
     public AbstractGeographicExtent(final GeographicExtent object) {
         super(object);
-        inclusion = object.getInclusion();
+        booleans = (byte) setBoolean(0, INCLUSION_MASK, object.getInclusion());
     }
 
     /**
@@ -134,7 +146,7 @@ public class AbstractGeographicExtent ex
     @Override
     @XmlElement(name = "extentTypeCode")
     public synchronized Boolean getInclusion() {
-        return inclusion;
+        return getBoolean(booleans, INCLUSION_MASK);
     }
 
     /**
@@ -145,6 +157,6 @@ public class AbstractGeographicExtent ex
      */
     public synchronized void setInclusion(final Boolean newValue) {
         checkWritePermission();
-        inclusion = newValue;
+        booleans = (byte) setBoolean(booleans, INCLUSION_MASK, newValue);
     }
 }

Modified: 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultConformanceResult.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultConformanceResult.java?rev=1462435&r1=1462434&r2=1462435&view=diff
==============================================================================
--- 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultConformanceResult.java
 [UTF-8] (original)
+++ 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultConformanceResult.java
 [UTF-8] Fri Mar 29 10:19:28 2013
@@ -60,9 +60,9 @@ public class DefaultConformanceResult ex
 
     /**
      * Indication of the conformance result.
-     * <p>
-     * The field is directly annotated here, because the getter method is 
called {@link #pass()},
-     * and JAXB does not recognize it. The method should have been called 
getPass() or isPass().
+     *
+     * <p>The field is directly annotated here, because the getter method is 
called {@link #pass()},
+     * and JAXB does not recognize it. The method should have been called 
getPass() or isPass().</p>
      */
     @XmlElement(name = "pass", required = true)
     private Boolean pass;

Modified: 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectified.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectified.java?rev=1462435&r1=1462434&r2=1462435&view=diff
==============================================================================
--- 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectified.java
 [UTF-8] (original)
+++ 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeorectified.java
 [UTF-8] Fri Mar 29 10:19:28 2013
@@ -62,10 +62,11 @@ public class DefaultGeorectified extends
     private static final long serialVersionUID = -4467097498958444505L;
 
     /**
-     * Indication of whether or not geographic position points are available 
to test the
-     * accuracy of the georeferenced grid data.
+     * Mask for the {@code checkPointAvailable} boolean value.
+     *
+     * @see #booleans
      */
-    private boolean checkPointAvailable;
+    private static final byte CHECK_POINT_MASK = TRANSFORMATION_MASK << 1;
 
     /**
      * Description of geographic position points used to test the accuracy of 
the
@@ -125,7 +126,9 @@ public class DefaultGeorectified extends
      */
     public DefaultGeorectified(final Georectified object) {
         super(object);
-        checkPointAvailable                = object.isCheckPointAvailable();
+        if (object.isCheckPointAvailable()) {
+            booleans |= CHECK_POINT_MASK;
+        }
         checkPointDescription              = object.getCheckPointDescription();
         cornerPoints                       = 
copyList(object.getCornerPoints(), Point.class);
         centerPoint                        = object.getCenterPoint();
@@ -167,7 +170,7 @@ public class DefaultGeorectified extends
     @Override
     @XmlElement(name = "checkPointAvailability", required = true)
     public synchronized boolean isCheckPointAvailable() {
-        return checkPointAvailable;
+        return (booleans & CHECK_POINT_MASK) != 0;
     }
 
     /**
@@ -178,7 +181,11 @@ public class DefaultGeorectified extends
      */
     public synchronized void setCheckPointAvailable(final boolean newValue) {
         checkWritePermission();
-        checkPointAvailable = newValue;
+        if (newValue) {
+            booleans |= CHECK_POINT_MASK;
+        } else {
+            booleans &= ~CHECK_POINT_MASK;
+        }
     }
 
     /**

Modified: 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeoreferenceable.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeoreferenceable.java?rev=1462435&r1=1462434&r2=1462435&view=diff
==============================================================================
--- 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeoreferenceable.java
 [UTF-8] (original)
+++ 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGeoreferenceable.java
 [UTF-8] Fri Mar 29 10:19:28 2013
@@ -57,14 +57,18 @@ public class DefaultGeoreferenceable ext
     private static final long serialVersionUID = 7369639367164358759L;
 
     /**
-     * Indication of whether or not control point(s) exists.
+     * Mask for the {@code controlPointAvailable} boolean value.
+     *
+     * @see #booleans
      */
-    private boolean controlPointAvailable;
+    private static final byte CONTROL_POINT_MASK = TRANSFORMATION_MASK << 1;
 
     /**
-     * Indication of whether or not orientation parameters are available.
+     * Mask for the {@code orientationParameterAvailable} boolean value.
+     *
+     * @see #booleans
      */
-    private boolean orientationParameterAvailable;
+    private static final byte OPERATION_MASK = CONTROL_POINT_MASK << 1;
 
     /**
      * Description of parameters used to describe sensor orientation.
@@ -103,8 +107,12 @@ public class DefaultGeoreferenceable ext
      */
     public DefaultGeoreferenceable(final Georeferenceable object) {
         super(object);
-        controlPointAvailable           = object.isControlPointAvailable();
-        orientationParameterAvailable   = 
object.isOrientationParameterAvailable();
+        if (object.isControlPointAvailable()) {
+            booleans |= CONTROL_POINT_MASK;
+        }
+        if (object.isOrientationParameterAvailable()) {
+            booleans |= OPERATION_MASK;
+        }
         orientationParameterDescription = 
object.getOrientationParameterDescription();
         parameterCitations              = 
copyCollection(object.getParameterCitations(), Citation.class);
         geolocationInformation          = 
copyCollection(object.getGeolocationInformation(), 
GeolocationInformation.class);
@@ -142,7 +150,7 @@ public class DefaultGeoreferenceable ext
     @Override
     @XmlElement(name = "controlPointAvailability", required = true)
     public synchronized boolean isControlPointAvailable() {
-        return controlPointAvailable;
+        return (booleans & CONTROL_POINT_MASK) != 0;
     }
 
     /**
@@ -152,7 +160,11 @@ public class DefaultGeoreferenceable ext
      */
     public synchronized void setControlPointAvailable(final boolean newValue) {
        checkWritePermission();
-       controlPointAvailable = newValue;
+        if (newValue) {
+            booleans |= CONTROL_POINT_MASK;
+        } else {
+            booleans &= ~CONTROL_POINT_MASK;
+        }
     }
 
     /**
@@ -161,7 +173,7 @@ public class DefaultGeoreferenceable ext
     @Override
     @XmlElement(name = "orientationParameterAvailability", required = true)
     public synchronized boolean isOrientationParameterAvailable() {
-        return orientationParameterAvailable;
+        return (booleans & OPERATION_MASK) != 0;
     }
 
     /**
@@ -171,7 +183,11 @@ public class DefaultGeoreferenceable ext
      */
     public synchronized void setOrientationParameterAvailable(final boolean 
newValue) {
         checkWritePermission();
-        orientationParameterAvailable = newValue;
+        if (newValue) {
+            booleans |= OPERATION_MASK;
+        } else {
+            booleans &= ~OPERATION_MASK;
+        }
     }
 
     /**

Modified: 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGridSpatialRepresentation.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGridSpatialRepresentation.java?rev=1462435&r1=1462434&r2=1462435&view=diff
==============================================================================
--- 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGridSpatialRepresentation.java
 [UTF-8] (original)
+++ 
sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/spatial/DefaultGridSpatialRepresentation.java
 [UTF-8] Fri Mar 29 10:19:28 2013
@@ -59,6 +59,16 @@ public class DefaultGridSpatialRepresent
     private static final long serialVersionUID = -8400572307442433979L;
 
     /**
+     * Mask for the {@code transformationParameterAvailable} boolean value.
+     *
+     * @see #booleans
+     */
+    static final byte TRANSFORMATION_MASK = 1;
+
+    // If more masks are added in a future version, then
+    // all of them should be private except the last one.
+
+    /**
      * Number of independent spatial-temporal axes.
      */
     private Integer numberOfDimensions;
@@ -74,9 +84,14 @@ public class DefaultGridSpatialRepresent
     private CellGeometry cellGeometry;
 
     /**
-     * Indication of whether or not parameters for transformation exists.
+     * The set of booleans values. Bits are read and written using the {@code 
*_MASK} constants.
+     *
+     * @see #TRANSFORMATION_MASK
+     * @see DefaultGeorectified#CHECK_POINT_MASK
+     * @see DefaultGeoreferenceable#CONTROL_POINT_MASK
+     * @see DefaultGeoreferenceable#OPERATION_MASK
      */
-    private boolean transformationParameterAvailable;
+    byte booleans;
 
     /**
      * Constructs an initially empty grid spatial representation.
@@ -95,10 +110,12 @@ public class DefaultGridSpatialRepresent
      */
     public DefaultGridSpatialRepresentation(final GridSpatialRepresentation 
object) {
         super(object);
-        numberOfDimensions               = object.getNumberOfDimensions();
-        axisDimensionProperties          = 
copyList(object.getAxisDimensionProperties(), Dimension.class);
-        cellGeometry                     = object.getCellGeometry();
-        transformationParameterAvailable = 
object.isTransformationParameterAvailable();
+        numberOfDimensions      = object.getNumberOfDimensions();
+        axisDimensionProperties = 
copyList(object.getAxisDimensionProperties(), Dimension.class);
+        cellGeometry            = object.getCellGeometry();
+        if (object.isTransformationParameterAvailable()) {
+            booleans = TRANSFORMATION_MASK;
+        }
     }
 
     /**
@@ -203,7 +220,7 @@ public class DefaultGridSpatialRepresent
     @Override
     @XmlElement(name = "transformationParameterAvailability", required = true)
     public synchronized boolean isTransformationParameterAvailable() {
-        return transformationParameterAvailable;
+        return (booleans & TRANSFORMATION_MASK) != 0;
     }
 
     /**
@@ -213,6 +230,10 @@ public class DefaultGridSpatialRepresent
      */
     public synchronized void setTransformationParameterAvailable(final boolean 
newValue) {
         checkWritePermission();
-        transformationParameterAvailable = newValue;
+        if (newValue) {
+            booleans |= TRANSFORMATION_MASK;
+        } else {
+            booleans &= ~TRANSFORMATION_MASK;
+        }
     }
 }

Added: 
sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/internal/metadata/MetadataUtilitiesTest.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/internal/metadata/MetadataUtilitiesTest.java?rev=1462435&view=auto
==============================================================================
--- 
sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/internal/metadata/MetadataUtilitiesTest.java
 (added)
+++ 
sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/internal/metadata/MetadataUtilitiesTest.java
 [UTF-8] Fri Mar 29 10:19:28 2013
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.metadata;
+
+import java.util.Date;
+import org.junit.Test;
+import org.apache.sis.test.TestCase;
+
+import static org.junit.Assert.*;
+import static java.lang.Boolean.TRUE;
+import static java.lang.Boolean.FALSE;
+
+
+/**
+ * Tests the {@link MetadataUtilities} class.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3
+ * @version 0.3
+ * @module
+ */
+public final strictfp class MetadataUtilitiesTest extends TestCase {
+    /**
+     * Tests {@link MetadataUtilities#toMilliseconds(Date)}.
+     */
+    @Test
+    public void testToMilliseconds() {
+        assertEquals(1000,           MetadataUtilities.toMilliseconds(new 
Date(1000)));
+        assertEquals(Long.MIN_VALUE, MetadataUtilities.toMilliseconds(null));
+    }
+
+    /**
+     * Tests {@link MetadataUtilities#toDate(long)}.
+     */
+    @Test
+    public void testToDate() {
+        assertEquals(new Date(1000), MetadataUtilities.toDate(1000));
+        assertNull(MetadataUtilities.toDate(Long.MIN_VALUE));
+    }
+
+    /**
+     * Tests {@link MetadataUtilities#setBoolean(int, byte, Boolean)}.
+     * This will indirectly test the getter method through Java assertion.
+     */
+    @Test
+    public void testSetBoolean() {
+        final int mask0 = 0b000011;
+        final int mask1 = 0b001100;
+        final int mask2 = 0b110000;
+        int flags = 0;
+        flags = MetadataUtilities.setBoolean(flags, mask1, null ); 
assertEquals(0b000000, flags);
+        flags = MetadataUtilities.setBoolean(flags, mask1, TRUE ); 
assertEquals(0b001100, flags);
+        flags = MetadataUtilities.setBoolean(flags, mask2, FALSE); 
assertEquals(0b101100, flags);
+        flags = MetadataUtilities.setBoolean(flags, mask1, null ); 
assertEquals(0b100000, flags);
+        flags = MetadataUtilities.setBoolean(flags, mask0, TRUE ); 
assertEquals(0b100011, flags);
+        flags = MetadataUtilities.setBoolean(flags, mask0, FALSE); 
assertEquals(0b100010, flags);
+    }
+}

Propchange: 
sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/internal/metadata/MetadataUtilitiesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/internal/metadata/MetadataUtilitiesTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: 
sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java?rev=1462435&r1=1462434&r2=1462435&view=diff
==============================================================================
--- 
sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
 [UTF-8] (original)
+++ 
sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
 [UTF-8] Fri Mar 29 10:19:28 2013
@@ -29,6 +29,7 @@ import org.junit.runners.Suite;
  * @module
  */
 @Suite.SuiteClasses({
+    org.apache.sis.internal.metadata.MetadataUtilitiesTest.class,
     org.apache.sis.metadata.PropertyDescriptorTest.class,
     org.apache.sis.metadata.PropertyAccessorTest.class
 })


Reply via email to