incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r1171344 - /sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
Date Fri, 16 Sep 2011 00:42:59 GMT
Author: justin
Date: Fri Sep 16 00:42:59 2011
New Revision: 1171344

URL: http://svn.apache.org/viewvc?rev=1171344&view=rev
Log:
SLING-2221 - making Java 5 compatible (boo hiss)

Modified:
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java?rev=1171344&r1=1171343&r2=1171344&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
(original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
Fri Sep 16 00:42:59 2011
@@ -22,7 +22,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.Serializable;
 import java.lang.reflect.Array;
-import java.util.AbstractMap;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collection;
@@ -210,7 +209,7 @@ public class JcrPropertyMap
             Set<Map.Entry<String, Object>> result = new LinkedHashSet<Map.Entry<String,
Object>>(cache.size());
             for (Map.Entry<String, JcrPropertyMapCacheEntry> entry : cache.entrySet())
{
                 try {
-                    Map.Entry<String, Object> newEntry = new AbstractMap.SimpleEntry<String,
Object>(entry.getKey(), entry.getValue().getDefaultValue());
+                    Map.Entry<String, Object> newEntry = new SimpleImmutableEntry<String,
Object>(entry.getKey(), entry.getValue().getDefaultValue());
                     result.add(newEntry);
                 } catch (RepositoryException e) {
                     
@@ -516,4 +515,85 @@ public class JcrPropertyMap
             return super.resolveClass(classDesc);
         }
     }
+    
+    /**
+     * Adapted from edu.emory.mathcs.backport.java.util.AbstractMap.SimpleImmutableEntry
+     * which is public domain
+     */
+    private static class SimpleImmutableEntry<K,V> implements Entry<K, V> {
+        private final K key;
+        private final V value;
+
+        /**
+         * Creates an entry representing a mapping from the specified
+         * key to the specified value.
+         *
+         * @param key the key represented by this entry
+         * @param value the value represented by this entry
+         */
+        public SimpleImmutableEntry(K key, V value) {
+            this.key   = key;
+            this.value = value;
+        }
+
+        /**
+         * Returns the key corresponding to this entry.
+         *
+         * @return the key corresponding to this entry
+         */
+        public K getKey() {
+            return key;
+        }
+
+        /**
+         * Returns the value corresponding to this entry.
+         *
+         * @return the value corresponding to this entry
+         */
+        public V getValue() {
+            return value;
+        }
+
+        /**
+         * Replaces the value corresponding to this entry with the specified
+         * value (optional operation).  This implementation simply throws
+         * <tt>UnsupportedOperationException</tt>, as this class implements
+         * an <i>immutable</i> map entry.
+         *
+         * @param value new value to be stored in this entry
+         * @return (Does not return)
+         * @throws UnsupportedOperationException always
+         */
+        public V setValue(V value) {
+            throw new UnsupportedOperationException();
+        }
+
+        public boolean equals(Object o) {
+            if (!(o instanceof Map.Entry))
+                return false;
+            Map.Entry<?,?> e = (Map.Entry<?,?>)o;
+            return eq(key, e.getKey()) && eq(value, e.getValue());
+        }
+
+        public int hashCode() {
+            return ((key   == null) ? 0 :   key.hashCode()) ^
+                   ((value == null) ? 0 : value.hashCode());
+        }
+
+        /**
+         * Returns a String representation of this map entry.  This
+         * implementation returns the string representation of this
+         * entry's key followed by the equals character ("<tt>=</tt>")
+         * followed by the string representation of this entry's value.
+         *
+         * @return a String representation of this map entry
+         */
+        public String toString() {
+            return key + "=" + value;
+        }
+
+        private static boolean eq(Object o1, Object o2) {
+            return (o1 == null ? o2 == null : o1.equals(o2));
+        }
+    }
 }



Mime
View raw message