1 21 24 package org.lobobrowser.util; 25 26 29 public class Objects { 30 33 private Objects() { 34 } 35 36 public static boolean equals(Object obj1, Object obj2) { 37 return obj1 == null ? (obj2 == null) : (obj1.equals(obj2)); 38 } 39 40 public static boolean isBoxClass(Class clazz) { 41 return clazz == Integer .class || 42 clazz == Boolean .class || 43 clazz == Double .class || 44 clazz == Float .class || 45 clazz == Long .class || 46 clazz == Byte .class || 47 clazz == Short .class || 48 clazz == Character .class; 49 } 50 51 public static boolean areAssignableTo(Object [] objects, Class [] types) { 52 int length = objects.length; 53 if(length != types.length) { 54 return false; 55 } 56 for(int i = 0; i < length; i++) { 57 if(!isAssignableOrBox(objects[i], types[i])) { 58 return false; 59 } 60 } 61 return true; 62 } 63 64 public static boolean isAssignableOrBox(Object value, Class clazz) { 65 return clazz.isInstance(value) || 66 (clazz.isPrimitive() && ( 67 (clazz == double.class && value instanceof Double ) || 68 (clazz == int.class && value instanceof Integer ) || 69 (clazz == byte.class && value instanceof Byte ) || 70 (clazz == boolean.class && value instanceof Boolean ) || 71 (clazz == char.class && value instanceof Character ) || 72 (clazz == short.class && value instanceof Short ) || 73 (clazz == long.class && value instanceof Long ) || 74 (clazz == float.class && value instanceof Float ) 75 )) || 76 (isNumeric(clazz) && isNumeric(value)) 77 ; 78 } 79 80 private static boolean isNumeric(Class clazz) { 81 return Number .class.isAssignableFrom(clazz) || 82 (clazz.isPrimitive() && 83 (clazz == int.class || clazz == double.class || clazz == byte.class || clazz == short.class || clazz == float.class || clazz == long.class) 84 ); 85 } 86 87 private static boolean isNumeric(Object value) { 88 if(value == null) { 89 return false; 90 } 91 return isNumeric(value.getClass()); 92 } 93 } 94 | Popular Tags |