jdk/src/java.management/share/classes/sun/management/LazyCompositeData.java
changeset 33260 af1ca24593aa
parent 30355 e37c7eba132f
--- a/jdk/src/java.management/share/classes/sun/management/LazyCompositeData.java	Tue Oct 20 10:33:41 2015 -0700
+++ b/jdk/src/java.management/share/classes/sun/management/LazyCompositeData.java	Tue Oct 20 20:53:13 2015 +0200
@@ -27,6 +27,7 @@
 
 import java.io.Serializable;
 import java.util.*;
+import javax.management.openmbean.ArrayType;
 import javax.management.openmbean.CompositeData;
 import javax.management.openmbean.CompositeType;
 import javax.management.openmbean.OpenType;
@@ -48,39 +49,48 @@
     private CompositeData compositeData;
 
     // Implementation of the CompositeData interface
+    @Override
     public boolean containsKey(String key) {
         return compositeData().containsKey(key);
     }
 
+    @Override
     public boolean containsValue(Object value) {
         return compositeData().containsValue(value);
     }
 
+    @Override
     public boolean equals(Object obj) {
         return compositeData().equals(obj);
     }
 
+    @Override
     public Object get(String key) {
         return compositeData().get(key);
     }
 
+    @Override
     public Object[] getAll(String[] keys) {
         return compositeData().getAll(keys);
     }
 
+    @Override
     public CompositeType getCompositeType() {
         return compositeData().getCompositeType();
     }
 
+    @Override
     public int hashCode() {
         return compositeData().hashCode();
     }
 
+    @Override
     public String toString() {
         /** FIXME: What should this be?? */
         return compositeData().toString();
     }
 
+    @Override
     public Collection<?> values() {
         return compositeData().values();
     }
@@ -126,27 +136,31 @@
         if (cd == null)
             throw new IllegalArgumentException("Null CompositeData");
 
-        return ((Boolean) cd.get(itemName)).booleanValue();
+        return ((Boolean) cd.get(itemName));
     }
 
     public static long getLong(CompositeData cd, String itemName) {
         if (cd == null)
             throw new IllegalArgumentException("Null CompositeData");
 
-        return ((Long) cd.get(itemName)).longValue();
+        return ((Long) cd.get(itemName));
     }
 
     public static int getInt(CompositeData cd, String itemName) {
         if (cd == null)
             throw new IllegalArgumentException("Null CompositeData");
 
-        return ((Integer) cd.get(itemName)).intValue();
+        return ((Integer) cd.get(itemName));
     }
 
     /**
      * Compares two CompositeTypes and returns true if
      * all items in type1 exist in type2 and their item types
      * are the same.
+     * @param type1 the base composite type
+     * @param type2 the checked composite type
+     * @return {@code true} if all items in type1 exist in type2 and their item
+     *         types are the same.
      */
     protected static boolean isTypeMatched(CompositeType type1, CompositeType type2) {
         if (type1 == type2) return true;
@@ -159,24 +173,9 @@
         if (!type2.keySet().containsAll(allItems))
             return false;
 
-        for (String item: allItems) {
-            OpenType<?> ot1 = type1.getType(item);
-            OpenType<?> ot2 = type2.getType(item);
-            if (ot1 instanceof CompositeType) {
-                if (! (ot2 instanceof CompositeType))
-                    return false;
-                if (!isTypeMatched((CompositeType) ot1, (CompositeType) ot2))
-                    return false;
-            } else if (ot1 instanceof TabularType) {
-                if (! (ot2 instanceof TabularType))
-                    return false;
-                if (!isTypeMatched((TabularType) ot1, (TabularType) ot2))
-                    return false;
-            } else if (!ot1.equals(ot2)) {
-                return false;
-            }
-        }
-        return true;
+        return allItems.stream().allMatch(
+            item -> isTypeMatched(type1.getType(item), type2.getType(item))
+        );
     }
 
     protected static boolean isTypeMatched(TabularType type1, TabularType type2) {
@@ -192,5 +191,41 @@
         return isTypeMatched(type1.getRowType(), type2.getRowType());
     }
 
+    protected static boolean isTypeMatched(ArrayType<?> type1, ArrayType<?> type2) {
+        if (type1 == type2) return true;
+
+        int dim1 = type1.getDimension();
+        int dim2 = type2.getDimension();
+
+        // check if the array dimensions are the same
+        if (dim1 != dim2)
+            return false;
+
+        return isTypeMatched(type1.getElementOpenType(), type2.getElementOpenType());
+    }
+
+    private static boolean isTypeMatched(OpenType<?> ot1, OpenType<?> ot2) {
+        if (ot1 instanceof CompositeType) {
+            if (! (ot2 instanceof CompositeType))
+                return false;
+            if (!isTypeMatched((CompositeType) ot1, (CompositeType) ot2))
+                return false;
+        } else if (ot1 instanceof TabularType) {
+            if (! (ot2 instanceof TabularType))
+                return false;
+            if (!isTypeMatched((TabularType) ot1, (TabularType) ot2))
+                return false;
+        } else if (ot1 instanceof ArrayType) {
+            if (! (ot2 instanceof ArrayType))
+                return false;
+            if (!isTypeMatched((ArrayType<?>) ot1, (ArrayType<?>) ot2)) {
+                return false;
+            }
+        } else if (!ot1.equals(ot2)) {
+            return false;
+        }
+        return true;
+    }
+
     private static final long serialVersionUID = -2190411934472666714L;
 }