/** * Get the ClassDescriptors for the all subclasses of a class * @param cld the parent ClassDescriptor * @return the ClassDescriptors of all descedents */ public Set<ClassDescriptor> getAllSubs(ClassDescriptor cld) { Set<ClassDescriptor> returnSubs = new TreeSet<ClassDescriptor>(); Set<ClassDescriptor> directSubs = getDirectSubs(cld); returnSubs.addAll(directSubs); for (ClassDescriptor sub : directSubs) { returnSubs.addAll(getAllSubs(sub)); } return returnSubs; }
/** * Get the ClassDescriptors for the all subclasses of a class * @param cld the parent ClassDescriptor * @return the ClassDescriptors of all descedents */ public Set<ClassDescriptor> getAllSubs(ClassDescriptor cld) { Set<ClassDescriptor> returnSubs = new TreeSet<ClassDescriptor>(); Set<ClassDescriptor> directSubs = getDirectSubs(cld); returnSubs.addAll(directSubs); for (ClassDescriptor sub : directSubs) { returnSubs.addAll(getAllSubs(sub)); } return returnSubs; }
List<ClassDescriptor> clds = new ArrayList<ClassDescriptor>(model.getAllSubs(cld)); clds.add(cld); for (ClassDescriptor nextCld : clds) {
private void countAndStore(ObjectStore os, Model model, ClassDescriptor cld) throws ObjectStoreException { if (!classCountsMap.containsKey(cld.getName())) { int classCount = countClass(os, cld.getType()); LOG.info("Adding class count: " + cld.getUnqualifiedName() + " = " + classCount); classCountsMap.put(cld.getName(), new Integer(classCount)); // if this class is empty all subclasses MUST be empty as well if (classCount == 0) { for (ClassDescriptor subCld : model.getAllSubs(cld)) { if (!classCountsMap.containsKey(subCld.getName())) { classCountsMap.put(subCld.getName(), new Integer(classCount)); } } } } }
List<ClassDescriptor> clds = new ArrayList<ClassDescriptor>(model.getAllSubs(cld)); clds.add(cld); for (ClassDescriptor nextCld : clds) {
private Map<String, InterMineBag> filterBagsByType(Map<String, InterMineBag> bags, String type, boolean onlyCurrent, boolean includeSupers) { Set<String> acceptableTypes = new HashSet<String>(); acceptableTypes.add(type); ClassDescriptor bagTypeCld = model.getClassDescriptorByName(type); if (bagTypeCld == null) { throw new NullPointerException("Could not find ClassDescriptor for name " + type); } for (ClassDescriptor cld : model.getAllSubs(bagTypeCld)) { acceptableTypes.add(cld.getUnqualifiedName()); } if (includeSupers) { for (ClassDescriptor cld : bagTypeCld.getAllSuperDescriptors()) { acceptableTypes.add(cld.getUnqualifiedName()); } } Map<String, InterMineBag> bagsOfType = new HashMap<String, InterMineBag>(); for (Map.Entry<String, InterMineBag> entry : bags.entrySet()) { InterMineBag bag = entry.getValue(); if (acceptableTypes.contains(bag.getType())) { if ((onlyCurrent && bag.isCurrent()) || !onlyCurrent) { bagsOfType.put(entry.getKey(), bag); } } } return bagsOfType; }
private void countAndStore(ObjectStore os, Model model, ClassDescriptor cld) throws ObjectStoreException { if (!classCountsMap.containsKey(cld.getName())) { int classCount = countClass(os, cld.getType()); LOG.info("Adding class count: " + cld.getUnqualifiedName() + " = " + classCount); classCountsMap.put(cld.getName(), new Integer(classCount)); // if this class is empty all subclasses MUST be empty as well if (classCount == 0) { for (ClassDescriptor subCld : model.getAllSubs(cld)) { if (!classCountsMap.containsKey(subCld.getName())) { classCountsMap.put(subCld.getName(), new Integer(classCount)); } } } } }
private Map<String, InterMineBag> filterBagsByType(Map<String, InterMineBag> bags, String type, boolean onlyCurrent, boolean includeSupers) { Set<String> acceptableTypes = new HashSet<String>(); acceptableTypes.add(type); ClassDescriptor bagTypeCld = model.getClassDescriptorByName(type); if (bagTypeCld == null) { throw new NullPointerException("Could not find ClassDescriptor for name " + type); } for (ClassDescriptor cld : model.getAllSubs(bagTypeCld)) { acceptableTypes.add(cld.getUnqualifiedName()); } if (includeSupers) { for (ClassDescriptor cld : bagTypeCld.getAllSuperDescriptors()) { acceptableTypes.add(cld.getUnqualifiedName()); } } Map<String, InterMineBag> bagsOfType = new HashMap<String, InterMineBag>(); for (Map.Entry<String, InterMineBag> entry : bags.entrySet()) { InterMineBag bag = entry.getValue(); if (acceptableTypes.contains(bag.getType())) { if ((onlyCurrent && bag.isCurrent()) || !onlyCurrent) { bagsOfType.put(entry.getKey(), bag); } } } return bagsOfType; }
tracks.add(makeFeatureTrack(fcd, null)); for (ClassDescriptor cd: m.getAllSubs(fcd)) { tracks.add(makeFeatureTrack(cd, null));
private void processAdditionalConverters(Attributes attrs) { String fullyQualifiedName = attrs.getValue("class-name"); String constraintPath = attrs.getValue("constraint-path"); String targetType = attrs.getValue("target-type"); String title = attrs.getValue("title"); String urlField = attrs.getValue("urlField"); ClassDescriptor typeCld = model.getClassDescriptorByName(targetType); if (typeCld == null) { LOG.warn("Invalid target type for additional converter: " + targetType); return; } try { new Path(model, constraintPath); } catch (PathException e) { LOG.warn("Can't add converter to bag-queries.xml, constraint-path '" + constraintPath + "' isn't in " + model.getName() + " model."); return; } Set<String> clds = new HashSet<String>(); clds.add(typeCld.getName()); for (ClassDescriptor cld : model.getAllSubs(typeCld)) { clds.add(cld.getName()); } AdditionalConverter additionalConverter = new AdditionalConverter(constraintPath, targetType, fullyQualifiedName, title, urlField); for (String nextCld : clds) { Util.addToSetMap(additionalConverters, TypeUtil.unqualifiedName(nextCld), additionalConverter); } }
private void processAdditionalConverters(Attributes attrs) { String fullyQualifiedName = attrs.getValue("class-name"); String constraintPath = attrs.getValue("constraint-path"); String targetType = attrs.getValue("target-type"); String title = attrs.getValue("title"); String urlField = attrs.getValue("urlField"); ClassDescriptor typeCld = model.getClassDescriptorByName(targetType); if (typeCld == null) { LOG.warn("Invalid target type for additional converter: " + targetType); return; } try { new Path(model, constraintPath); } catch (PathException e) { LOG.warn("Can't add converter to bag-queries.xml, constraint-path '" + constraintPath + "' isn't in " + model.getName() + " model."); return; } Set<String> clds = new HashSet<String>(); clds.add(typeCld.getName()); for (ClassDescriptor cld : model.getAllSubs(typeCld)) { clds.add(cld.getName()); } AdditionalConverter additionalConverter = new AdditionalConverter(constraintPath, targetType, fullyQualifiedName, title, urlField); for (String nextCld : clds) { Util.addToSetMap(additionalConverters, TypeUtil.unqualifiedName(nextCld), additionalConverter); } }
tracks.add(makeFeatureTrack(fcd, null)); for (ClassDescriptor cd: m.getAllSubs(fcd)) { tracks.add(makeFeatureTrack(cd, null));
if (fld != null) { ClassKeyHelper.addKey(theseKeys, clsName, fld); for (ClassDescriptor subCld : model.getAllSubs(cld)) { ClassKeyHelper.addKey(theseKeys, subCld.getUnqualifiedName(), fld);
if (fld != null) { ClassKeyHelper.addKey(theseKeys, clsName, fld); for (ClassDescriptor subCld : model.getAllSubs(cld)) { ClassKeyHelper.addKey(theseKeys, subCld.getUnqualifiedName(), fld);
for (ClassDescriptor nextCld : os.getModel().getAllSubs(cld)) { clsNames.add(TypeUtil.unqualifiedName(nextCld.getName()));
for (ClassDescriptor nextCld : os.getModel().getAllSubs(cld)) { clsNames.add(TypeUtil.unqualifiedName(nextCld.getName()));
public void testGetAllSubs() throws Exception { Model model = Model.getInstanceByName("basicmodel"); Set<ClassDescriptor> hasAddressCds = model.getClassDescriptorsForClass(org.intermine.model.basicmodel.Thing.class); assertEquals(1, hasAddressCds.size()); ClassDescriptor addressCld = (ClassDescriptor) hasAddressCds.iterator().next(); if (addressCld.getName() == "org.intermine.model.InterMineObject") { // we want org.intermine.model.basicmodel.HasAddress addressCld = (ClassDescriptor) hasAddressCds.iterator().next(); } Set<ClassDescriptor> resultCds = model.getAllSubs(addressCld); Set<String> expectedCdNames = new HashSet<String>(); expectedCdNames.add("org.intermine.model.basicmodel.Employable"); expectedCdNames.add("org.intermine.model.basicmodel.Address"); expectedCdNames.add("org.intermine.model.basicmodel.Employee"); expectedCdNames.add("org.intermine.model.basicmodel.Manager"); expectedCdNames.add("org.intermine.model.basicmodel.Department"); expectedCdNames.add("org.intermine.model.basicmodel.Contractor"); Set<String> resultCdNames = new HashSet<String>(); for (ClassDescriptor cld : resultCds) { resultCdNames.add(cld.getName()); } assertEquals(expectedCdNames, resultCdNames); }
clds.addAll(cld.getModel().getAllSubs(cld)); for (ClassDescriptor nextCld : clds) { ClassDescriptor tableMaster = schema.getTableMaster(nextCld);
clds.addAll(cld.getModel().getAllSubs(cld)); for (ClassDescriptor nextCld : clds) { ClassDescriptor tableMaster = schema.getTableMaster(nextCld);