sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1422232 - in /sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry: AbstractDirectPosition.java DirectPosition1D.java DirectPosition2D.java GeneralDirectPosition.java
Date Sat, 15 Dec 2012 12:32:48 GMT
Author: desruisseaux
Date: Sat Dec 15 12:32:47 2012
New Revision: 1422232

URL: http://svn.apache.org/viewvc?rev=1422232&view=rev
Log:
Documentation fixes and slight API simplification by removing the static toString(...) method.

Modified:
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition1D.java
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java?rev=1422232&r1=1422231&r2=1422232&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
Sat Dec 15 12:32:47 2012
@@ -153,45 +153,22 @@ public abstract class AbstractDirectPosi
      * are the {@linkplain #getOrdinate(int) ordinate} values at index 0, 1, 2, <i>etc.</i>:
      *
      * {@preformat wkt
-     *   POINT(x₀, x₁, x₂, …)
+     *   POINT(x₀ x₁ x₂ …)
      * }
      *
-     * The output of this method can be parsed by the by the {@link GeneralDirectPosition}
constructor.
+     * The string returned by this method can be parsed by the {@link GeneralDirectPosition}
constructor.
      *
      * @return This position as a {@code POINT} in <cite>Well Known Text</cite>
(WKT) format.
      */
     @Override
     public String toString() {
-        return toString(this);
-    }
-
-    /**
-     * Formats a {@code POINT} element from a given direct position.
-     * This method formats the given position in the <cite>Well Known Text</cite>
(WKT) format.
-     * The returned string is like below, where {@code x₀}, {@code x₁}, {@code
x₂}, <i>etc.</i>
-     * are the {@linkplain #getOrdinate(int) ordinate} values at index 0, 1, 2, <i>etc.</i>:
-     *
-     * {@preformat wkt
-     *   POINT(x₀, x₁, x₂, …)
-     * }
-     *
-     * The output of this method can be parsed by the by the {@link GeneralDirectPosition}
constructor.
-     *
-     * @param  position The position to format.
-     * @return The position as a {@code POINT} in <cite>Well Known Text</cite>
(WKT) format.
-     *
-     * @see GeneralDirectPosition#GeneralDirectPosition(String)
-     * @see org.apache.sis.measure.CoordinateFormat
-     * @see org.apache.sis.io.wkt
-     */
-    public static String toString(final DirectPosition position) {
         final StringBuilder buffer = new StringBuilder(32).append("POINT(");
-        final int dimension = position.getDimension();
+        final int dimension = getDimension();
         for (int i=0; i<dimension; i++) {
             if (i != 0) {
                 buffer.append(' ');
             }
-            trimFractionalPart(buffer.append(position.getOrdinate(i)));
+            trimFractionalPart(buffer.append(getOrdinate(i)));
         }
         return buffer.append(')').toString();
     }
@@ -289,7 +266,10 @@ parse:  while (i < length) {
     }
 
     /**
-     * Returns a hash value for this coordinate.
+     * Returns a hash value for this coordinate. This method returns a value compliant
+     * with the contract documented in the {@link DirectPosition#hashCode()} javadoc.
+     * Consequently, it should be possible to mix different {@code DirectPosition}
+     * implementations in the same hash map.
      *
      * @return A hash code value for this position.
      */
@@ -309,16 +289,23 @@ parse:  while (i < length) {
     }
 
     /**
-     * Returns {@code true} if the specified object is also a
-     * {@linkplain DirectPosition direct position} with equal
-     * {@linkplain #getCoordinate() coordinate} array and equal
+     * Returns {@code true} if the specified object is also a {@code DirectPosition}
+     * with equal {@linkplain #getCoordinate() coordinate} and equal
      * {@linkplain #getCoordinateReferenceSystem CRS}.
      *
+     * This method performs the comparison as documented in the {@link DirectPosition#equals(Object)}
+     * javadoc. In particular, the given object is not required to be of the same implementation
class.
+     * Consequently, it should be possible to mix different {@code DirectPosition} implementations
in
+     * the same hash map.
+     *
      * @param object The object to compare with this position.
      * @return {@code true} if the given object is equal to this position.
      */
     @Override
     public boolean equals(final Object object) {
+        if (object == this) {
+            return true;
+        }
         if (object instanceof DirectPosition) {
             final DirectPosition that = (DirectPosition) object;
             final int dimension = getDimension();

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition1D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition1D.java?rev=1422232&r1=1422231&r2=1422232&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition1D.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition1D.java
Sat Dec 15 12:32:47 2012
@@ -213,7 +213,7 @@ public class DirectPosition1D extends Ab
     }
 
     /**
-     * Returns a hash value for this coordinate.
+     * {@inheritDoc}
      */
     @Override
     public int hashCode() {

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java?rev=1422232&r1=1422231&r2=1422232&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java
Sat Dec 15 12:32:47 2012
@@ -23,7 +23,9 @@ import org.opengis.geometry.MismatchedDi
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.cs.AxisDirection;
 import org.apache.sis.util.resources.Errors;
+
 import static java.lang.Double.doubleToLongBits;
+import static org.apache.sis.util.StringBuilders.trimFractionalPart;
 
 
 /**
@@ -278,11 +280,14 @@ public class DirectPosition2D extends Po
      *   POINT(x y)
      * }
      *
-     * The output of this method can be parsed by the by the {@link GeneralDirectPosition}
constructor.
+     * The string returned by this method can be parsed by the {@link #DirectPosition2D(String)}
constructor.
      */
     @Override
     public String toString() {
-        return AbstractDirectPosition.toString(this);
+        final StringBuilder buffer = new StringBuilder(32);
+        trimFractionalPart(buffer.append("POINT(").append(x));
+        trimFractionalPart(buffer.append(' ').append(y));
+        return buffer.append(')').toString();
     }
 
     /**

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java?rev=1422232&r1=1422231&r2=1422232&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
Sat Dec 15 12:32:47 2012
@@ -267,7 +267,7 @@ public class GeneralDirectPosition exten
     }
 
     /**
-     * Returns a hash value for this coordinate.
+     * {@inheritDoc}
      */
     @Override
     public int hashCode() {



Mime
View raw message