sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1639257 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/metadata/ sis-utility/src/main/java/org/apache/sis/internal/util/ sis-utility/src/main/java/org/apache/sis/util/iso/
Date Thu, 13 Nov 2014 07:12:16 GMT
Author: desruisseaux
Date: Thu Nov 13 07:12:15 2014
New Revision: 1639257

URL: http://svn.apache.org/r1639257
Log:
Factor out default implementation of 'equals', 'hashCode' and 'toString' for Map.Entry.
This change fixes a hole in DefaultRecord.

Added:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/AbstractMapEntry.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/ValueMap.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecord.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/ValueMap.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/ValueMap.java?rev=1639257&r1=1639256&r2=1639257&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/ValueMap.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/ValueMap.java
[UTF-8] Thu Nov 13 07:12:15 2014
@@ -20,15 +20,11 @@ import java.util.Map;
 import java.util.Set;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
-import org.apache.sis.util.CharSequences;
-import org.apache.sis.util.Debug;
+import org.apache.sis.internal.util.AbstractMapEntry;
 
 import static org.apache.sis.metadata.PropertyAccessor.RETURN_NULL;
 import static org.apache.sis.metadata.PropertyAccessor.RETURN_PREVIOUS;
 
-// Branch-dependent imports
-import java.util.Objects;
-
 
 /**
  * A view of a metadata object as a map. Keys are property names and values
@@ -181,7 +177,7 @@ final class ValueMap extends PropertyMap
      * @version 0.3
      * @module
      */
-    final class Property implements Map.Entry<String,Object> {
+    final class Property extends AbstractMapEntry<String,Object> {
         /**
          * The property index.
          */
@@ -229,41 +225,6 @@ final class ValueMap extends PropertyMap
         public Object setValue(final Object value) {
             return accessor.set(index, metadata, value, RETURN_PREVIOUS);
         }
-
-        /**
-         * Compares the specified object with this entry for equality.
-         * Criterion are specified by the {@link Map.Entry} contract.
-         */
-        @Override
-        public boolean equals(final Object object) {
-            if (object instanceof Map.Entry<?,?>) {
-                final Map.Entry<?,?> entry = (Map.Entry<?,?>) object;
-                return Objects.equals(getKey(),   entry.getKey()) &&
-                       Objects.equals(getValue(), entry.getValue());
-            }
-            return false;
-        }
-
-        /**
-         * Returns the hash code value for this map entry. The
-         * formula is specified by the {@link Map.Entry} contract.
-         */
-        @Override
-        public int hashCode() {
-            return Objects.hashCode(getKey()) ^ Objects.hashCode(getValue());
-        }
-
-        /**
-         * Returns a string representation of this entry.
-         * This method is mostly for debugging purpose.
-         */
-        @Debug
-        @Override
-        public String toString() {
-            String value = String.valueOf(getValue());
-            value = value.substring(0, CharSequences.indexOfLineStart(value, 1, 0));
-            return getKey() + '=' + value;
-        }
     }
 
 

Added: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/AbstractMapEntry.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/AbstractMapEntry.java?rev=1639257&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/AbstractMapEntry.java
(added)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/AbstractMapEntry.java
[UTF-8] Thu Nov 13 07:12:15 2014
@@ -0,0 +1,83 @@
+/*
+ * 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.util;
+
+import java.util.Map;
+import org.apache.sis.util.CharSequences;
+import org.apache.sis.util.Debug;
+
+// Branch-dependent imports
+import java.util.Objects;
+
+
+/**
+ * Provides default implementations of {@link #equals(Object)}, {@link #hashCode()} and {@link
#toString()}
+ * for a map entry.
+ *
+ * @param <K> The type of keys maintained by the map.
+ * @param <V> The type of mapped values.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5
+ * @version 0.5
+ * @module
+ */
+public abstract class AbstractMapEntry<K,V> implements Map.Entry<K,V> {
+    /**
+     * For subclasses constructors.
+     */
+    protected AbstractMapEntry() {
+    }
+
+    /**
+     * Compares the specified object with this entry for equality.
+     * Criterion are specified by the {@link Map.Entry} contract.
+     *
+     * @param object The other object to compare with this entry.
+     */
+    @Override
+    public boolean equals(final Object object) {
+        if (object instanceof Map.Entry<?,?>) {
+            final Map.Entry<?,?> entry = (Map.Entry<?,?>) object;
+            return Objects.equals(getKey(),   entry.getKey()) &&
+                   Objects.equals(getValue(), entry.getValue());
+        }
+        return false;
+    }
+
+    /**
+     * Returns the hash code value for this map entry.
+     * The formula is specified by the {@link Map.Entry} contract.
+     */
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(getKey()) ^ Objects.hashCode(getValue());
+    }
+
+    /**
+     * Returns a string representation of this entry. If the string representation
+     * of the value uses more than one line, then only the first line is shown.
+     * This method is mostly for debugging purpose.
+     */
+    @Debug
+    @Override
+    public String toString() {
+        String value = String.valueOf(getValue());
+        value = value.substring(0, CharSequences.indexOfLineStart(value, 1, 0));
+        return String.valueOf(getKey()) + '=' + value;
+    }
+}

Propchange: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/AbstractMapEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/AbstractMapEntry.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecord.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecord.java?rev=1639257&r1=1639256&r2=1639257&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecord.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecord.java
[UTF-8] Thu Nov 13 07:12:15 2014
@@ -31,6 +31,7 @@ import org.apache.sis.util.Debug;
 import org.apache.sis.util.Utilities;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
+import org.apache.sis.internal.util.AbstractMapEntry;
 
 // Branch-dependent imports
 import java.util.Objects;
@@ -193,7 +194,7 @@ public class DefaultRecord implements Re
      * Operations on this entry delegate to {@link DefaultRecord#locate(MemberName)}
      * and {@link DefaultRecord#set(MemberName, Object)} methods.
      */
-    private final class Entry implements Map.Entry<MemberName,Object> {
+    private final class Entry extends AbstractMapEntry<MemberName,Object> {
         /** Index of the record member represented by this entry. */
         private final int index;
 



Mime
View raw message