@Test public void testIsInstance() { checkIsInstance(true, Object.class, null); checkIsInstance(true, Object.class, "String"); checkIsInstance(true, String.class, "String"); checkIsInstance(false, Integer.class, "String"); checkIsInstance(false, int.class, null); checkIsInstancePrimitive(boolean.class, true); checkIsInstancePrimitive(char.class, 'a'); checkIsInstancePrimitive(byte.class, (byte) 1); checkIsInstancePrimitive(short.class, (short) 1); checkIsInstancePrimitive(int.class, 1); checkIsInstancePrimitive(long.class, 1L); checkIsInstancePrimitive(float.class, 1.0f); checkIsInstancePrimitive(double.class, 1.0); }
public static boolean isInstance(final Class type, final Object instance) { if (type.isPrimitive()) { if (instance == null) { return false; } if (type.equals(boolean.class)) { return instance instanceof Boolean; } else if (type.equals(char.class)) { return instance instanceof Character; } else if (type.equals(byte.class)) { return instance instanceof Byte; } else if (type.equals(short.class)) { return instance instanceof Short; } else if (type.equals(int.class)) { return instance instanceof Integer; } else if (type.equals(long.class)) { return instance instanceof Long; } else if (type.equals(float.class)) { return instance instanceof Float; } else if (type.equals(double.class)) { return instance instanceof Double; } else { throw new AssertionError("Invalid primitve type: " + type); } } return instance == null || type.isInstance(instance); }
Util { public static boolean isInstance(final Class type, final Object instance) { if (type.isPrimitive()) { if (instance == null) { return false; } if (type.equals(boolean.class)) { return instance instanceof Boolean; } else if (type.equals(char.class)) { return instance instanceof Character; } else if (type.equals(byte.class)) { return instance instanceof Byte; } else if (type.equals(short.class)) { return instance instanceof Short; } else if (type.equals(int.class)) { return instance instanceof Integer; } else if (type.equals(long.class)) { return instance instanceof Long; } else if (type.equals(float.class)) { return instance instanceof Float; } else if (type.equals(double.class)) { return instance instanceof Double; } else { throw new AssertionError("Invalid primitve type: " + type); } } return instance == null || type.isInstance(instance); } }
Util { public static boolean isInstance(final Class type, final Object instance) { if (type.isPrimitive()) { if (instance == null) { return false; } if (type.equals(boolean.class)) { return instance instanceof Boolean; } else if (type.equals(char.class)) { return instance instanceof Character; } else if (type.equals(byte.class)) { return instance instanceof Byte; } else if (type.equals(short.class)) { return instance instanceof Short; } else if (type.equals(int.class)) { return instance instanceof Integer; } else if (type.equals(long.class)) { return instance instanceof Long; } else if (type.equals(float.class)) { return instance instanceof Float; } else if (type.equals(double.class)) { return instance instanceof Double; } else { throw new AssertionError("Invalid primitve type: " + type); } } return instance == null || type.isInstance(instance); } private  Util(); }
Util { public static boolean isInstance(final Class type, final Object instance) { if (type.isPrimitive()) { if (instance == null) { return false; } if (type.equals(boolean.class)) { return instance instanceof Boolean; } else if (type.equals(char.class)) { return instance instanceof Character; } else if (type.equals(byte.class)) { return instance instanceof Byte; } else if (type.equals(short.class)) { return instance instanceof Short; } else if (type.equals(int.class)) { return instance instanceof Integer; } else if (type.equals(long.class)) { return instance instanceof Long; } else if (type.equals(float.class)) { return instance instanceof Float; } else if (type.equals(double.class)) { return instance instanceof Double; } else { throw new AssertionError("Invalid primitve type: " + type); } } return instance == null || type.isInstance(instance); } private  Util(); static boolean isInstance(final Class type, final Object instance); static void addProperty(final Hashtable env, String property); static Method findSetter(final Class<?> testClazz, final Field field, final Object propertyValue); static Method getMostSpecificMethod(final Method method1, final Method method2); }
Util { public static boolean isInstance(final Class type, final Object instance) { if (type.isPrimitive()) { if (instance == null) { return false; } if (type.equals(boolean.class)) { return instance instanceof Boolean; } else if (type.equals(char.class)) { return instance instanceof Character; } else if (type.equals(byte.class)) { return instance instanceof Byte; } else if (type.equals(short.class)) { return instance instanceof Short; } else if (type.equals(int.class)) { return instance instanceof Integer; } else if (type.equals(long.class)) { return instance instanceof Long; } else if (type.equals(float.class)) { return instance instanceof Float; } else if (type.equals(double.class)) { return instance instanceof Double; } else { throw new AssertionError("Invalid primitve type: " + type); } } return instance == null || type.isInstance(instance); } private  Util(); static boolean isInstance(final Class type, final Object instance); static void addProperty(final Hashtable env, String property); static Method findSetter(final Class<?> testClazz, final Field field, final Object propertyValue); static Method getMostSpecificMethod(final Method method1, final Method method2);  }