jdk/src/share/classes/com/sun/jmx/mbeanserver/Util.java
changeset 900 55c9c5a88bde
parent 834 dc74d4ddc28e
child 1004 5ba8217eb504
equal deleted inserted replaced
899:40d3416d937a 900:55c9c5a88bde
    24  */
    24  */
    25 
    25 
    26 package com.sun.jmx.mbeanserver;
    26 package com.sun.jmx.mbeanserver;
    27 
    27 
    28 import java.util.ArrayList;
    28 import java.util.ArrayList;
       
    29 import java.util.Arrays;
    29 import java.util.Collection;
    30 import java.util.Collection;
    30 import java.util.Collections;
    31 import java.util.Collections;
    31 import java.util.Comparator;
    32 import java.util.Comparator;
    32 import java.util.HashMap;
    33 import java.util.HashMap;
    33 import java.util.HashSet;
    34 import java.util.HashSet;
   111      */
   112      */
   112     @SuppressWarnings("unchecked")
   113     @SuppressWarnings("unchecked")
   113     public static <T> T cast(Object x) {
   114     public static <T> T cast(Object x) {
   114         return (T) x;
   115         return (T) x;
   115     }
   116     }
       
   117 
       
   118     /**
       
   119      * Computes a descriptor hashcode from its names and values.
       
   120      * @param names  the sorted array of descriptor names.
       
   121      * @param values the array of descriptor values.
       
   122      * @return a hash code value, as described in {@link #hashCode(Descriptor)}
       
   123      */
       
   124     public static int hashCode(String[] names, Object[] values) {
       
   125         int hash = 0;
       
   126         for (int i = 0; i < names.length; i++) {
       
   127             Object v = values[i];
       
   128             int h;
       
   129             if (v == null) {
       
   130                 h = 0;
       
   131             } else if (v instanceof Object[]) {
       
   132                 h = Arrays.deepHashCode((Object[]) v);
       
   133             } else if (v.getClass().isArray()) {
       
   134                 h = Arrays.deepHashCode(new Object[]{v}) - 31;
       
   135             // hashcode of a list containing just v is
       
   136             // v.hashCode() + 31, see List.hashCode()
       
   137             } else {
       
   138                 h = v.hashCode();
       
   139             }
       
   140             hash += names[i].toLowerCase().hashCode() ^ h;
       
   141         }
       
   142         return hash;
       
   143     }
       
   144 
   116 }
   145 }