sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1476241 - in /sis/branches/JDK7/sis-metadata/src: main/java/org/apache/sis/metadata/PropertyAccessor.java test/java/org/apache/sis/metadata/PropertyAccessorTest.java
Date Fri, 26 Apr 2013 14:57:39 GMT
Author: desruisseaux
Date: Fri Apr 26 14:57:33 2013
New Revision: 1476241

URL: http://svn.apache.org/r1476241
Log:
Added 'toString()' implementation for debugging purpose.

Modified:
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
    sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java?rev=1476241&r1=1476240&r2=1476241&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyAccessor.java
[UTF-8] Fri Apr 26 14:57:33 2013
@@ -30,7 +30,9 @@ import net.jcip.annotations.ThreadSafe;
 import org.opengis.annotation.UML;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.ExtendedElementInformation;
+import org.apache.sis.internal.util.Citations;
 import org.apache.sis.measure.ValueRange;
+import org.apache.sis.util.Debug;
 import org.apache.sis.util.Classes;
 import org.apache.sis.util.Numbers;
 import org.apache.sis.util.ArraysExt;
@@ -1100,4 +1102,28 @@ final class PropertyAccessor {
         }
         return code;
     }
+
+    /**
+     * Returns a string representation of this accessor for debugging purpose.
+     * Output example:
+     *
+     * {@preformat text
+     *     PropertyAccessor[13 properties in DefaultCitation:Citation from “ISO 19115”]
+     * }
+     */
+    @Debug
+    @Override
+    public String toString() {
+        final StringBuilder buffer = new StringBuilder(60);
+        buffer.append("PropertyAccessor[").append(standardCount).append(" properties");
+        final int extra = allCount - standardCount;
+        if (extra != 0) {
+            buffer.append(" (+").append(extra).append(" ext.)");
+        }
+        buffer.append(" in ").append(Classes.getShortName(implementation));
+        if (type != implementation) {
+            buffer.append(':').append(Classes.getShortName(type));
+        }
+        return buffer.append(" from “").append(Citations.getIdentifier(standard)).append("”]").toString();
+    }
 }

Modified: sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java?rev=1476241&r1=1476240&r2=1476241&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyAccessorTest.java
[UTF-8] Fri Apr 26 14:57:33 2013
@@ -399,4 +399,14 @@ public final strictfp class PropertyAcce
         hashCode = accessor.hashCode(instance);
         assertEquals("Metadata with two values.", baseCode + title.hashCode() + Arrays.asList(alternateTitle).hashCode(),
hashCode);
     }
+
+    /**
+     * Tests {@link PropertyAccessor#toString()}. The {@code toString()}
+     * method is only for debugging purpose, but we test it anyway.
+     */
+    @Test
+    public void testToString() {
+        final PropertyAccessor accessor = createPropertyAccessor();
+        assertEquals("PropertyAccessor[13 properties in DefaultCitation:Citation from “ISO
19115”]", accessor.toString());
+    }
 }



Mime
View raw message