/** * Return the Class for the array of Class objects. * * @param classes the classes and interfaces to extend/implement * @return the Class * @throws IllegalArgumentException is there is more than one Class, or if the fields are not * compatible. */ public static Class<? extends FastPathObject> composeClass(Class<?>... classes) { return composeClass(new HashSet<Class<?>>(Arrays.asList(classes))); }
/** * Return the Class for the array of Class objects. * * @param classes the classes and interfaces to extend/implement * @return the Class * @throws IllegalArgumentException is there is more than one Class, or if the fields are not * compatible. */ public static Class<? extends FastPathObject> composeClass(Class<?>... classes) { return composeClass(new HashSet<Class<?>>(Arrays.asList(classes))); }
/** * Return the Class for the array of Class objects. This method returns a Class which is * descriptive of the component classes, but not necessarily valid for instantiating. * This means that passing a single interface into this method will return the interface rather * than a class composed from it. * * @param classes the classes and interfaces to extend/implement * @return the Class * @throws IllegalArgumentException if there is more than one Class, or if the fields are not * compatible. */ @SuppressWarnings("unchecked") public static Class<? extends FastPathObject> composeDescriptiveClass(Class<?>... classes) { if (classes.length == 1) { if (!FastPathObject.class.isAssignableFrom(classes[0])) { throw new ClassCastException("Expected a FastPathObject class"); } return (Class<? extends FastPathObject>) classes[0]; } return composeClass(new HashSet<Class<?>>(Arrays.asList(classes))); }
/** * Return the Class for the array of Class objects. This method returns a Class which is * descriptive of the component classes, but not necessarily valid for instantiating. * This means that passing a single interface into this method will return the interface rather * than a class composed from it. * * @param classes the classes and interfaces to extend/implement * @return the Class * @throws IllegalArgumentException if there is more than one Class, or if the fields are not * compatible. */ @SuppressWarnings("unchecked") public static Class<? extends FastPathObject> composeDescriptiveClass(Class<?>... classes) { if (classes.length == 1) { if (!FastPathObject.class.isAssignableFrom(classes[0])) { throw new ClassCastException("Expected a FastPathObject class"); } return (Class<? extends FastPathObject>) classes[0]; } return composeClass(new HashSet<Class<?>>(Arrays.asList(classes))); }
/** * Constructs a QueryClass representing the specified set of classes and ObjectStoreBag. * * @param types the Set of classes * @param osb the ObjectStoreBag */ public QueryClassBag(Set<Class<?>> types, ObjectStoreBag osb) { Class<?> clazz; if (types.size() == 1) { clazz = types.iterator().next(); } else { clazz = DynamicUtil.composeClass(types); } if (!InterMineObject.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("Cannot create a QueryClassBag with a class that" + " is not a subclass of InterMineObject: " + Util.getFriendlyName( clazz)); } @SuppressWarnings("unchecked") Class<? extends InterMineObject> thisType = (Class) clazz; this.type = thisType; this.osb = osb; this.ids = null; this.bag = null; }
/** * Constructs a QueryClass representing the specified set of classes and ObjectStoreBag. * * @param types the Set of classes * @param osb the ObjectStoreBag */ public QueryClassBag(Set<Class<?>> types, ObjectStoreBag osb) { Class<?> clazz; if (types.size() == 1) { clazz = types.iterator().next(); } else { clazz = DynamicUtil.composeClass(types); } if (!InterMineObject.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("Cannot create a QueryClassBag with a class that" + " is not a subclass of InterMineObject: " + Util.getFriendlyName( clazz)); } @SuppressWarnings("unchecked") Class<? extends InterMineObject> thisType = (Class) clazz; this.type = thisType; this.osb = osb; this.ids = null; this.bag = null; }
/** * Constructs a QueryClass representing the specified set of classes and bag of objects. * * @param types the Set of classes * @param bag the Collection of objects */ public QueryClassBag(Set<Class<?>> types, Collection<?> bag) { Class<?> clazz; if (types.size() == 1) { clazz = types.iterator().next(); } else { clazz = DynamicUtil.composeClass(types); } if (!InterMineObject.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("Cannot create a QueryClassBag with a class that" + " is not a subclass of InterMineObject: " + Util.getFriendlyName( clazz)); } @SuppressWarnings("unchecked") Class<? extends InterMineObject> thisType = (Class) clazz; this.type = thisType; this.bag = bag; ids = convertToIds(bag, this.type); this.osb = null; }
/** * Constructs a QueryClass representing the specified set of classes and bag of objects. * * @param types the Set of classes * @param bag the Collection of objects */ public QueryClassBag(Set<Class<?>> types, Collection<?> bag) { Class<?> clazz; if (types.size() == 1) { clazz = types.iterator().next(); } else { clazz = DynamicUtil.composeClass(types); } if (!InterMineObject.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("Cannot create a QueryClassBag with a class that" + " is not a subclass of InterMineObject: " + Util.getFriendlyName( clazz)); } @SuppressWarnings("unchecked") Class<? extends InterMineObject> thisType = (Class) clazz; this.type = thisType; this.bag = bag; ids = convertToIds(bag, this.type); this.osb = null; }
public void testClassHeirarchyBrokeCEOIsCEO() throws Exception { Class brokeCEO = DynamicUtil.composeClass(new HashSet(Arrays.asList(new Class[] {Broke.class, CEO.class}))); assertTrue(CEO.class.isAssignableFrom(brokeCEO)); }
public void testClassHeirarchyBrokeCEOIsBroke() throws Exception { Class brokeCEO = DynamicUtil.composeClass(new HashSet(Arrays.asList(new Class[] {Broke.class, CEO.class}))); assertTrue(Broke.class.isAssignableFrom(brokeCEO)); }
public void testFindCommonSuperclasses() throws Exception { Set<Class<?>> input = new HashSet<Class<?>>(); input.add(Employee.class); input.add(Contractor.class); input.add(Manager.class); assertEquals(Collections.singleton(Employable.class), CollectionUtil.findCommonSuperclasses(input)); input.clear(); input.add(DynamicUtil.composeClass(Company.class, Broke.class)); input.add(DynamicUtil.composeClass(Company.class)); assertEquals(Collections.singleton(Company.class), CollectionUtil.findCommonSuperclasses(input)); input.clear(); input.add(DynamicUtil.composeClass(Company.class)); input.add(Types.class); assertEquals(Collections.singleton(InterMineObject.class), CollectionUtil.findCommonSuperclasses(input)); input.clear(); input.add(DynamicUtil.composeClass(Contractor.class, Broke.class)); input.add(DynamicUtil.composeClass(Employee.class, Broke.class)); assertEquals(new HashSet(Arrays.asList(Employable.class, Broke.class)), CollectionUtil.findCommonSuperclasses(input)); } }
currentColumn = classes.iterator().next(); } else { currentColumn = DynamicUtil.composeClass(classes);
currentColumn = classes.iterator().next(); } else { currentColumn = DynamicUtil.composeClass(classes);
public void testConstructors() throws Exception { Class c = DynamicUtil.composeClass(Company.class, Broke.class); Company obj = (Company) c.newInstance(); ((net.sf.cglib.proxy.Factory) obj).setCallback(0, new DynamicBean()); obj.setName("Fred"); assertEquals("Fred", obj.getName()); }
results.put("SelectFunctionNoGroup", ObjectStoreTestUtils.toList(r)); r = new Object[][]{{Address.class, new Long(8)}, {DynamicUtil.composeClass(Broke.class, CEO.class), new Long(1)}, {DynamicUtil.composeClass(Broke.class, Company.class), new Long(1)}, {DynamicUtil.composeClass(Broke.class, Contractor.class), new Long(1)}, {Company.class, new Long(1)}, {Contractor.class, new Long(1)}, {Types.class, new Long(1)}}; results.put("SelectClassFromInterMineObject", ObjectStoreTestUtils.toList(r)); r = new Object[][]{{DynamicUtil.composeClass(Broke.class, CEO.class), new Long(1)}, {Employee.class, new Long(3)}, {Manager.class, new Long(2)}}; results.put("SelectClassFromEmployee", ObjectStoreTestUtils.toList(r)); r = new Object[][]{{DynamicUtil.composeClass(Broke.class, CEO.class), new Long(1)}, {DynamicUtil.composeClass(Broke.class, Contractor.class), new Long(1)}}; results.put("SelectClassFromBrokeEmployable", ObjectStoreTestUtils.toList(r)); r = new Object[][]{{data.get("DepartmentA1"), Arrays.asList(data.get("EmployeeA1"))},