sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mlebi...@apache.org
Subject svn commit: r1647263 - in /sis/branches/JDK8/storage/sis-shapefile/src: main/java/org/apache/sis/storage/shapefile/ test/java/org/apache/sis/storage/shapefile/
Date Mon, 22 Dec 2014 08:54:36 GMT
Author: mlebihan
Date: Mon Dec 22 08:54:35 2014
New Revision: 1647263

URL: http://svn.apache.org/r1647263
Log:
SIS-185 :
- ShapeFile public variable members reduced to private. Method getFeatureMap() added to allow
a test to continue working.
- FieldDescriptor public variable members reduced to private.
- Database methods : close, isClosed, loadRowIntoFeature and readNextRowAsObjects marked as
deprecated to warn programmers against using them.

Modified:
    sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/AbstractByteReader.java
    sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/Database.java
    sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/FieldDescriptor.java
    sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/MappedByteReader.java
    sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java
    sis/branches/JDK8/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java

Modified: sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/AbstractByteReader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/AbstractByteReader.java?rev=1647263&r1=1647262&r2=1647263&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/AbstractByteReader.java
(original)
+++ sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/AbstractByteReader.java
Mon Dec 22 08:54:35 2014
@@ -36,10 +36,10 @@ abstract class AbstractByteReader extend
     protected String dbfFile;
 
     /** Number of bytes in the header. */
-    protected short DbaseHeaderBytes;
+    protected short dbaseHeaderBytes;
 
     /** Number of bytes in the record. */
-    protected short DbaseRecordBytes;
+    protected short dbaseRecordBytes;
     
     /** Reserved (dBASE IV) Filled with 00h. */
     protected byte[] reservedFiller1 = new byte[2];
@@ -77,7 +77,7 @@ abstract class AbstractByteReader extend
     protected byte descriptorTerminator;
 
     /** Valid dBASE III PLUS table file (03h without a memo .DBT file; 83h with a memo).
*/
-    protected byte DbaseVersion;
+    protected byte dbaseVersion;
 
     /** Number of records in the table. */
     protected int recordCount;
@@ -86,7 +86,7 @@ abstract class AbstractByteReader extend
     protected Charset charset;
 
     /** Date of last update; in YYMMDD format. */
-    protected byte[] DbaseLastUpdate = new byte[3];
+    protected byte[] dbaseLastUpdate = new byte[3];
 
     /** Fields descriptor. */
     protected FieldsDescriptors fieldsDescriptors = new FieldsDescriptors();
@@ -115,7 +115,7 @@ abstract class AbstractByteReader extend
      * @return Date of the last update.
      */
     @Override public Date getDateOfLastUpdate() {
-        return toDate(DbaseLastUpdate);
+        return toDate(dbaseLastUpdate);
     }
 
     /**

Modified: sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/Database.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/Database.java?rev=1647263&r1=1647262&r2=1647263&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/Database.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/Database.java
[UTF-8] Mon Dec 22 08:54:35 2014
@@ -20,8 +20,8 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.nio.charset.Charset;
-import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Objects;
 
 import org.apache.sis.util.logging.AbstractAutoChecker;
@@ -64,8 +64,9 @@ public class Database extends AbstractAu
 
     /**
      * @see java.lang.AutoCloseable#close()
+     * @deprecated Will be removed in next API versions.
      */
-    @Override
+    @Override @Deprecated
     public void close() throws IOException {
         binaryReader.close();
         isClosed = true;
@@ -91,7 +92,7 @@ public class Database extends AbstractAu
      * Return the fields descriptor.
      * @return Field descriptor.
      */
-    public ArrayList<FieldDescriptor> getFieldsDescriptor() {
+    public List<FieldDescriptor> getFieldsDescriptor() {
         return binaryReader.getFieldsDescriptors();
     }
 
@@ -114,7 +115,9 @@ public class Database extends AbstractAu
     /**
      * Determines if the database is closed.
      * @return true if it is closed.
+     * @deprecated Will be removed in next API versions.
      */
+    @Deprecated
     public boolean isClosed() {
         return isClosed;
     }
@@ -122,14 +125,19 @@ public class Database extends AbstractAu
     /**
      * Load a row into a feature.
      * @param feature Feature to fill.
+     * @deprecated Will be removed in next API versions.
      */
+    @Deprecated 
     public void loadRowIntoFeature(Feature feature) {
         binaryReader.loadRowIntoFeature(feature);
     }
+    
     /**
      * Read the next row as a set of objects.
      * @return Map of field name / object value.
+     * @deprecated Will be removed in next API versions.
      */
+    @Deprecated 
     public HashMap<String, Object> readNextRowAsObjects() {
         return binaryReader.readNextRowAsObjects();
     }

Modified: sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/FieldDescriptor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/FieldDescriptor.java?rev=1647263&r1=1647262&r2=1647263&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/FieldDescriptor.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/FieldDescriptor.java
[UTF-8] Mon Dec 22 08:54:35 2014
@@ -16,6 +16,8 @@
  */
 package org.apache.sis.storage.shapefile;
 
+import java.nio.MappedByteBuffer;
+
 import org.apache.sis.util.logging.AbstractAutoChecker;
 
 
@@ -29,37 +31,37 @@ import org.apache.sis.util.logging.Abstr
  */
  public class FieldDescriptor extends AbstractAutoChecker {
     /** Field name. */
-    public byte[] FieldName = new byte[11];
+    private byte[] fieldName = new byte[11];
 
     /** Field type. */
-    public DataType FieldType;
+    private DataType fieldType;
 
     /** Field address (Field data address (address is set in memory; not useful on disk).
*/
-    public byte[] FieldAddress = new byte[4];
+    private byte[] fieldAddress = new byte[4];
 
     /** Field length. */
-    public byte FieldLength;
+    private byte fieldLength;
 
     /** Decimal count. */
-    public byte FieldDecimalCount;
+    private byte fieldDecimalCount;
 
     /** Reserved 2. */
-    public byte[] DbasePlusLanReserved2 = new byte[2];
+    private byte[] dbasePlusLanReserved2 = new byte[2];
 
     /** Work area id. */
-    public byte WorkAreaID;
+    private byte workAreaID;
 
     /** Reserved 3. */
-    public byte[] DbasePlusLanReserved3 = new byte[2];
+    private byte[] dbasePlusLanReserved3 = new byte[2];
 
-    public byte SetFields;
+    private byte SetFields;
     
     /**
      * Returns the decimal count of that field.
      * @return Decimal count.
      */
     public int getDecimalCount() {
-        return Byte.toUnsignedInt(this.FieldDecimalCount);
+        return Byte.toUnsignedInt(this.fieldDecimalCount);
     }
     
     /**
@@ -67,7 +69,7 @@ import org.apache.sis.util.logging.Abstr
      * @return field length.
      */
     public int getLength() {
-        return Byte.toUnsignedInt(this.FieldLength);
+        return Byte.toUnsignedInt(this.fieldLength);
     }
 
     /**
@@ -75,11 +77,11 @@ import org.apache.sis.util.logging.Abstr
      * @return Field name.
      */
     public String getName() {
-        int length = FieldName.length;
-        while (length != 0 && FieldName[length - 1] <= ' ') {
+        int length = fieldName.length;
+        while (length != 0 && fieldName[length - 1] <= ' ') {
             length--;
         }
-        return new String(this.FieldName, 0, length);
+        return new String(this.fieldName, 0, length);
     }
 
     /**
@@ -87,7 +89,47 @@ import org.apache.sis.util.logging.Abstr
      * @return Data type.
      */
     public DataType getType() {
-        return(FieldType);
+        return(fieldType);
+    }
+
+    /**
+     * Create a field descriptor from the current position of the binary stream.
+     * @param df ByteBuffer.
+     * @return FieldDescriptor or null if there is no more available.
+     */
+    static FieldDescriptor toFieldDescriptor(MappedByteBuffer df) {
+        FieldDescriptor fd = new FieldDescriptor();
+
+        // Field name.
+        df.get(fd.fieldName);
+
+        // Field type.
+        char dt = (char) df.get();
+        fd.fieldType = DataType.valueOfDataType(dt);
+
+        // Field address.
+        df.get(fd.fieldAddress);
+
+        // Length and scale.
+        fd.fieldLength = df.get();
+        fd.fieldDecimalCount = df.get();
+
+        df.getShort(); // reserved
+
+        df.get(fd.dbasePlusLanReserved2);
+
+        // Work area id.
+        fd.workAreaID = df.get();
+
+        df.get(fd.dbasePlusLanReserved3);
+
+        // Fields.
+        fd.SetFields = df.get();
+
+        byte[] data = new byte[6];
+        df.get(data); // reserved
+
+        return fd;
     }
     
     /**
@@ -95,7 +137,7 @@ import org.apache.sis.util.logging.Abstr
      */
     @Override
     public String toString() {
-        String text = format("toString", getName(), FieldType, FieldLength, FieldDecimalCount);
+        String text = format("toString", getName(), fieldType, fieldLength, fieldDecimalCount);
         return text;
     }
 }

Modified: sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/MappedByteReader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/MappedByteReader.java?rev=1647263&r1=1647262&r2=1647263&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/MappedByteReader.java
(original)
+++ sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/MappedByteReader.java
Mon Dec 22 08:54:35 2014
@@ -129,13 +129,13 @@ class MappedByteReader extends AbstractB
             int fsize = (int) fc.size();
             df = fc.map(FileChannel.MapMode.READ_ONLY, 0, fsize);
     
-            this.DbaseVersion = df.get();
-            df.get(this.DbaseLastUpdate);
+            this.dbaseVersion = df.get();
+            df.get(this.dbaseLastUpdate);
     
             df.order(ByteOrder.LITTLE_ENDIAN);
             this.recordCount = df.getInt();
-            this.DbaseHeaderBytes = df.getShort();
-            this.DbaseRecordBytes = df.getShort();
+            this.dbaseHeaderBytes = df.getShort();
+            this.dbaseRecordBytes = df.getShort();
             df.order(ByteOrder.BIG_ENDIAN);
             
             df.get(reservedFiller1);
@@ -151,8 +151,8 @@ class MappedByteReader extends AbstractB
             
             df.get(reservedFiller2); 
     
-            while(df.position() < this.DbaseHeaderBytes - 1) {
-                FieldDescriptor fd = toFieldDescriptor();
+            while(df.position() < this.dbaseHeaderBytes - 1) {
+                FieldDescriptor fd = FieldDescriptor.toFieldDescriptor(df);
                 this.fieldsDescriptors.add(fd);
                 // loop until you hit the 0Dh field terminator
             }
@@ -174,47 +174,4 @@ class MappedByteReader extends AbstractB
             throw new InvalidDbaseFileFormatException(message);
         }
     }
-
-    /**
-     * Create a field descriptor from the current position of the binary stream.
-     * @return FieldDescriptor or null if there is no more available.
-     */
-    private FieldDescriptor toFieldDescriptor() {
-        // If there is no more field description available, return null.
-        if (df.position() >= this.DbaseHeaderBytes - 1)
-            return null;
-
-        FieldDescriptor fd = new FieldDescriptor();
-
-        // Field name.
-        df.get(fd.FieldName);
-
-        // Field type.
-        char dt = (char) df.get();
-        fd.FieldType = DataType.valueOfDataType(dt);
-
-        // Field address.
-        df.get(fd.FieldAddress);
-
-        // Length and scale.
-        fd.FieldLength = df.get();
-        fd.FieldDecimalCount = df.get();
-
-        df.getShort(); // reserved
-
-        df.get(fd.DbasePlusLanReserved2);
-
-        // Work area id.
-        fd.WorkAreaID = df.get();
-
-        df.get(fd.DbasePlusLanReserved3);
-
-        // Fields.
-        fd.SetFields = df.get();
-
-        byte[] data = new byte[6];
-        df.get(data); // reserved
-
-        return fd;
-    }
 }

Modified: sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java?rev=1647263&r1=1647262&r2=1647263&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-shapefile/src/main/java/org/apache/sis/storage/shapefile/ShapeFile.java
[UTF-8] Mon Dec 22 08:54:35 2014
@@ -53,46 +53,46 @@ public class ShapeFile {
     private static final String GEOMETRY_NAME = "geometry";
 
     /** File code. */
-    public int FileCode; // big
+    private int fileCode; // big
 
     /** File length. */
-    public int FileLength; // big // The value for file length is the total length of the
file in 16-bit words
+    private int fileLength; // big // The value for file length is the total length of the
file in 16-bit words
 
     /** File version. */
-    public int Version; // little
+    private int version; // little
 
     /** Shapefile type. */
-    public ShapeTypeEnum ShapeType; // little
+    private ShapeTypeEnum shapeType; // little
 
     /** X Min. */
-    public double xmin; // little
+    private double xmin; // little
 
     /** Y Min. */
-    public double ymin; // little
+    private double ymin; // little
 
     /** X Max. */
-    public double xmax; // little
+    private double xmax; // little
 
     /** Y Max. */
-    public double ymax; // little
+    private double ymax; // little
 
     /** Z Min. */
-    public double zmin; // little
+    private double zmin; // little
 
     /** Z Max. */
-    public double zmax; // little
+    private double zmax; // little
 
     /** M Min. */
-    public double mmin; // little
+    private double mmin; // little
 
     /** M Max. */
-    public double mmax; // little
+    private double mmax; // little
 
     /** Underlying databasefile content. */
     private Database dbf;
 
     /** Features existing in the shapefile. */
-    public Map<Integer, Feature> FeatureMap = new HashMap<>();
+    private Map<Integer, Feature> featureMap = new HashMap<>();
 
     /**
      * Construct a Shapefile from a file.
@@ -114,17 +114,17 @@ public class ShapeFile {
                 int fsize = (int) fc.size();
                 MappedByteBuffer rf = fc.map(FileChannel.MapMode.READ_ONLY, 0, fsize);
     
-                this.FileCode = rf.getInt();
+                this.fileCode = rf.getInt();
                 rf.getInt();
                 rf.getInt();
                 rf.getInt();
                 rf.getInt();
                 rf.getInt();
-                this.FileLength = rf.getInt() * 2;
+                this.fileLength = rf.getInt() * 2;
     
                 rf.order(ByteOrder.LITTLE_ENDIAN);
-                this.Version = rf.getInt();
-                this.ShapeType = ShapeTypeEnum.get(rf.getInt());
+                this.version = rf.getInt();
+                this.shapeType = ShapeTypeEnum.get(rf.getInt());
                 this.xmin = rf.getDouble();
                 this.ymin = rf.getDouble();
                 this.xmax = rf.getDouble();
@@ -168,6 +168,14 @@ public class ShapeFile {
     }
 
     /**
+     * Returns the feature Map.
+     * @return Feature Map.
+     */
+    public Map<Integer, Feature> getFeatureMap() {
+        return this.featureMap;
+    }
+    
+    /**
      * Load the features of a shapefile.
      * @param featureType Features descriptor.
      * @param rf byte buffer mapper.
@@ -211,7 +219,7 @@ public class ShapeFile {
 
             dbf.loadRowIntoFeature(f);
 
-            this.FeatureMap.put(RecordNumber, f);
+            this.featureMap.put(RecordNumber, f);
         }
     }
 
@@ -340,10 +348,10 @@ public class ShapeFile {
         StringBuilder s = new StringBuilder();
         String lineSeparator = System.getProperty("line.separator", "\n");
 
-        s.append("FileCode: ").append(FileCode).append(lineSeparator);
-        s.append("FileLength: ").append(FileLength).append(lineSeparator);
-        s.append("Version: ").append(Version).append(lineSeparator);
-        s.append("ShapeType: ").append(ShapeType).append(lineSeparator);
+        s.append("FileCode: ").append(fileCode).append(lineSeparator);
+        s.append("FileLength: ").append(fileLength).append(lineSeparator);
+        s.append("Version: ").append(version).append(lineSeparator);
+        s.append("ShapeType: ").append(shapeType).append(lineSeparator);
         s.append("xmin: ").append(xmin).append(lineSeparator);
         s.append("ymin: ").append(ymin).append(lineSeparator);
         s.append("xmax: ").append(xmax).append(lineSeparator);

Modified: sis/branches/JDK8/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java?rev=1647263&r1=1647262&r2=1647263&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-shapefile/src/test/java/org/apache/sis/storage/shapefile/ShapeFileTest.java
[UTF-8] Mon Dec 22 08:54:35 2014
@@ -54,7 +54,7 @@ public final strictfp class ShapeFileTes
     @Test
     public void testPolyineCount() throws URISyntaxException, IOException, DataStoreException
{
         ShapeFile shp = new ShapeFile(path("SignedBikeRoute_4326_clipped.shp"));
-        assertEquals(shp.FeatureMap.size(), shp.getFeatureCount());
+        assertEquals(shp.getFeatureMap().size(), shp.getFeatureCount());
     }
 
     /**
@@ -66,7 +66,7 @@ public final strictfp class ShapeFileTes
      @Test
      public void testPolygonCount() throws URISyntaxException, IOException, DataStoreException
{
         ShapeFile shp = new ShapeFile(path("ANC90Ply_4326.shp"));
-        assertEquals(shp.FeatureMap.size(), shp.getFeatureCount());
+        assertEquals(shp.getFeatureMap().size(), shp.getFeatureCount());
     }
 
      /**
@@ -78,6 +78,6 @@ public final strictfp class ShapeFileTes
      @Test
      public void testPointCount() throws URISyntaxException, IOException, DataStoreException
{
         ShapeFile shp = new ShapeFile(path("ABRALicenseePt_4326_clipped.shp"));
-        assertEquals(shp.FeatureMap.size(), shp.getFeatureCount());
+        assertEquals(shp.getFeatureMap().size(), shp.getFeatureCount());
     }
 }



Mime
View raw message