@Test @SuppressWarnings("unchecked") public void testSameInterfaces() { assertTrue (Classes.sameInterfaces(StringBuilder.class, String.class, CharSequence.class)); assertTrue (Classes.sameInterfaces(StringBuilder.class, String.class, Serializable.class)); assertFalse(Classes.sameInterfaces((Class) File.class, String.class, CharSequence.class)); assertTrue (Classes.sameInterfaces( File.class, String.class, Serializable.class)); }
public static <T> boolean sameInterfaces(final Class<? extends T> object1, final Class<? extends T> object2, final Class<T> base) { if (object1 == object2) { return true; } if (object1==null || object2==null) { return false; } final Class<?>[] c1 = object1.getInterfaces(); final Class<?>[] c2 = object2.getInterfaces(); int n = 0; for (int i=0; i<c2.length; i++) { final Class<?> c = c2[i]; if (base.isAssignableFrom(c)) { c2[n++] = c; } } compare:for (int i=0; i<c1.length; i++) { final Class<?> c = c1[i]; if (base.isAssignableFrom(c)) { for (int j=0; j<n; j++) { if (c.equals(c2[j])) { System.arraycopy(c2, j+1, c2, j, --n-j); continue compare; } } return false; } } return n == 0; }
Classes { public static <T> boolean sameInterfaces(final Class<? extends T> object1, final Class<? extends T> object2, final Class<T> base) { if (object1 == object2) { return true; } if (object1==null || object2==null) { return false; } final Class<?>[] c1 = object1.getInterfaces(); final Class<?>[] c2 = object2.getInterfaces(); int n = 0; for (int i=0; i<c2.length; i++) { final Class<?> c = c2[i]; if (base.isAssignableFrom(c)) { c2[n++] = c; } } compare:for (int i=0; i<c1.length; i++) { final Class<?> c = c1[i]; if (base.isAssignableFrom(c)) { for (int j=0; j<n; j++) { if (c.equals(c2[j])) { System.arraycopy(c2, j+1, c2, j, --n-j); continue compare; } } return false; } } return n == 0; } }
Classes { public static <T> boolean sameInterfaces(final Class<? extends T> object1, final Class<? extends T> object2, final Class<T> base) { if (object1 == object2) { return true; } if (object1==null || object2==null) { return false; } final Class<?>[] c1 = object1.getInterfaces(); final Class<?>[] c2 = object2.getInterfaces(); int n = 0; for (int i=0; i<c2.length; i++) { final Class<?> c = c2[i]; if (base.isAssignableFrom(c)) { c2[n++] = c; } } compare:for (int i=0; i<c1.length; i++) { final Class<?> c = c1[i]; if (base.isAssignableFrom(c)) { for (int j=0; j<n; j++) { if (c.equals(c2[j])) { System.arraycopy(c2, j+1, c2, j, --n-j); continue compare; } } return false; } } return n == 0; } private  Classes(final Class<?> primitive, final Class<?> wrapper,
                    final boolean  isFloat,   final boolean  isInteger,
                    final byte     size,      final byte     ordinal); }
Classes { public static <T> boolean sameInterfaces(final Class<? extends T> object1, final Class<? extends T> object2, final Class<T> base) { if (object1 == object2) { return true; } if (object1==null || object2==null) { return false; } final Class<?>[] c1 = object1.getInterfaces(); final Class<?>[] c2 = object2.getInterfaces(); int n = 0; for (int i=0; i<c2.length; i++) { final Class<?> c = c2[i]; if (base.isAssignableFrom(c)) { c2[n++] = c; } } compare:for (int i=0; i<c1.length; i++) { final Class<?> c = c1[i]; if (base.isAssignableFrom(c)) { for (int j=0; j<n; j++) { if (c.equals(c2[j])) { System.arraycopy(c2, j+1, c2, j, --n-j); continue compare; } } return false; } } return n == 0; } private  Classes(final Class<?> primitive, final Class<?> wrapper,
                    final boolean  isFloat,   final boolean  isInteger,
                    final byte     size,      final byte     ordinal); static Class<?> boundOfParameterizedAttribute(final Field field); static Class<?> boundOfParameterizedAttribute(final Method method); @SuppressWarnings("unchecked") static Class<? extends T> getClass(final T object); static Class<?> specializedClass(final Collection<?> objects); static Class<?> commonClass(final Collection<?> objects); static boolean sameInterfaces(final Class<? extends T> object1,
                                             final Class<? extends T> object2,
                                             final Class<T> base); static boolean isFloat(final Class<?> type); static boolean isInteger(final Class<?> type); static int getBitCount(final Class<?> type); static Class<?> primitiveToWrapper(final Class<?> type); static Class<?> wrapperToPrimitive(final Class<?> type); static byte getEnumConstant(final Class<?> type); @SuppressWarnings("unchecked") static T valueOf(final Class<T> type, final String value); static String getShortName(Class<?> classe); static String getShortClassName(final Object object); }
Classes { public static <T> boolean sameInterfaces(final Class<? extends T> object1, final Class<? extends T> object2, final Class<T> base) { if (object1 == object2) { return true; } if (object1==null || object2==null) { return false; } final Class<?>[] c1 = object1.getInterfaces(); final Class<?>[] c2 = object2.getInterfaces(); int n = 0; for (int i=0; i<c2.length; i++) { final Class<?> c = c2[i]; if (base.isAssignableFrom(c)) { c2[n++] = c; } } compare:for (int i=0; i<c1.length; i++) { final Class<?> c = c1[i]; if (base.isAssignableFrom(c)) { for (int j=0; j<n; j++) { if (c.equals(c2[j])) { System.arraycopy(c2, j+1, c2, j, --n-j); continue compare; } } return false; } } return n == 0; } private  Classes(final Class<?> primitive, final Class<?> wrapper,
                    final boolean  isFloat,   final boolean  isInteger,
                    final byte     size,      final byte     ordinal); static Class<?> boundOfParameterizedAttribute(final Field field); static Class<?> boundOfParameterizedAttribute(final Method method); @SuppressWarnings("unchecked") static Class<? extends T> getClass(final T object); static Class<?> specializedClass(final Collection<?> objects); static Class<?> commonClass(final Collection<?> objects); static boolean sameInterfaces(final Class<? extends T> object1,
                                             final Class<? extends T> object2,
                                             final Class<T> base); static boolean isFloat(final Class<?> type); static boolean isInteger(final Class<?> type); static int getBitCount(final Class<?> type); static Class<?> primitiveToWrapper(final Class<?> type); static Class<?> wrapperToPrimitive(final Class<?> type); static byte getEnumConstant(final Class<?> type); @SuppressWarnings("unchecked") static T valueOf(final Class<T> type, final String value); static String getShortName(Class<?> classe); static String getShortClassName(final Object object); static final byte DOUBLE; }