/** * Asserts that all entries in the list are either instances or subclasses of at least one of the specified classes. * * @param l The list to check. * @param c The valid classes. */ public static void assertTypes(List<Object> l, Class<?>...c) { for (Object o : l) { boolean matches = false; if (o.getClass() == Class.class) { Class<?> o2 = (Class<?>)o; for (int i = 0; i < c.length && ! matches; i++) matches = c[i].isAssignableFrom(o2); } else { for (int i = 0; i < c.length && ! matches; i++) matches = c[i].isInstance(o); } if (! matches) throw new FormattedRuntimeException("Invalid list entry ''{0}'' ({1}). Not one of the following types: {2}", string(o), className(o), c); } }
/** * Asserts that all entries in the list are either instances or subclasses of at least one of the specified classes. * * @param l The list to check. * @param c The valid classes. */ public static void assertTypes(List<Object> l, Class<?>...c) { for (Object o : l) { boolean matches = false; if (o.getClass() == Class.class) { Class<?> o2 = (Class<?>)o; for (int i = 0; i < c.length && ! matches; i++) matches = c[i].isAssignableFrom(o2); } else { for (int i = 0; i < c.length && ! matches; i++) matches = c[i].isInstance(o); } if (! matches) throw new FormattedRuntimeException("Invalid list entry ''{0}'' ({1}). Not one of the following types: {2}", string(o), className(o), c); } }
/** * Asserts that all entries in the list are either instances or subclasses of at least one of the specified classes. * * @param l The list to check. * @param c The valid classes. */ public static void assertTypes(List<Object> l, Class<?>...c) { for (Object o : l) { boolean matches = false; if (o.getClass() == Class.class) { Class<?> o2 = (Class<?>)o; for (int i = 0; i < c.length && ! matches; i++) matches = c[i].isAssignableFrom(o2); } else { for (int i = 0; i < c.length && ! matches; i++) matches = c[i].isInstance(o); } if (! matches) throw new FormattedRuntimeException("Invalid list entry ''{0}'' ({1}). Not one of the following types: {2}", string(o), className(o), c); } }