/** * Returns the second to last ClassDescriptor in the path. That is, the one before the one * returned by getLastClassDescriptor. * * @return the ClassDescriptor */ public ClassDescriptor getSecondLastClassDescriptor() { List<ClassDescriptor> l = getElementClassDescriptors(); if (l.size() > 1) { return l.get(l.size() - 2); } return null; }
/** * Returns the last ClassDescriptor in the path. If the last element is an attribute, then the * class before it in the path is returned. Otherwise, class of the last element is returned. * The class of an element is the referenced type of the FieldDescriptor (modified by the class * constraint), or simply the class if it is the first element in the path. For example, if the * path is "Department.manager.name" then this method will return Manager. If the path is * "Department.manager[CEO].name" then this method will return CEO. * * @return the ClassDescriptor */ public ClassDescriptor getLastClassDescriptor() { List<ClassDescriptor> l = getElementClassDescriptors(); return l.get(l.size() - 1); }
/** * Returns the last ClassDescriptor in the path. If the last element is an attribute, then the * class before it in the path is returned. Otherwise, class of the last element is returned. * The class of an element is the referenced type of the FieldDescriptor (modified by the class * constraint), or simply the class if it is the first element in the path. For example, if the * path is "Department.manager.name" then this method will return Manager. If the path is * "Department.manager[CEO].name" then this method will return CEO. * * @return the ClassDescriptor */ public ClassDescriptor getLastClassDescriptor() { List<ClassDescriptor> l = getElementClassDescriptors(); return l.get(l.size() - 1); }
/** * Returns the second to last ClassDescriptor in the path. That is, the one before the one * returned by getLastClassDescriptor. * * @return the ClassDescriptor */ public ClassDescriptor getSecondLastClassDescriptor() { List<ClassDescriptor> l = getElementClassDescriptors(); if (l.size() > 1) { return l.get(l.size() - 2); } return null; }
/** * Return the indexes of elements containing the field given in input * @param cls the class containing the field * @param field the field * @return list of indexes */ public List<Integer> getElementsContainingField(String cls, String field) { List<Integer> indexElementsContainingField = new ArrayList<Integer>(); ClassDescriptor cd; for (int index = 0; index < elements.size(); index++) { if (elements.get(index).equals(field)) { cd = getElementClassDescriptors().get(index); if (cd.getSimpleName().equals(cls)) { indexElementsContainingField.add(index); } else { for (String superClass : cd.getAllSuperclassNames()) { if (superClass.equals(cls)) { indexElementsContainingField.add(index); break; } } } } } return indexElementsContainingField; } }
/** * Return the indexes of elements containing the field given in input * @param cls the class containing the field * @param field the field * @return list of indexes */ public List<Integer> getElementsContainingField(String cls, String field) { List<Integer> indexElementsContainingField = new ArrayList<Integer>(); ClassDescriptor cd; for (int index = 0; index < elements.size(); index++) { if (elements.get(index).equals(field)) { cd = getElementClassDescriptors().get(index); if (cd.getSimpleName().equals(cls)) { indexElementsContainingField.add(index); } else { for (String superClass : cd.getAllSuperclassNames()) { if (superClass.equals(cls)) { indexElementsContainingField.add(index); break; } } } } } return indexElementsContainingField; } }
for (String viewPath : viewPaths) { Path path = templateQuery.makePath(viewPath); if (path.getElementClassDescriptors().size() == 1 && path.getLastClassDescriptor().getUnqualifiedName().equals(rootClass)) { if (templateQuery.getEditableConstraints(viewPath).isEmpty()) {
for (String viewPath : viewPaths) { Path path = templateQuery.makePath(viewPath); if (path.getElementClassDescriptors().size() == 1 && path.getLastClassDescriptor().getUnqualifiedName().equals(rootClass)) { if (templateQuery.getEditableConstraints(viewPath).isEmpty()) {
private void checkConstrainedPath(Path path) { assertEquals(model.getClassDescriptorByName("org.intermine.pathquery.model.testmodel.Department"), path.getStartClassDescriptor()); assertEquals(model.getClassDescriptorByName("org.intermine.pathquery.model.testmodel.Department"), path.getElementClassDescriptors().get(0)); assertEquals("manager", path.getElements().get(0)); assertEquals(model.getClassDescriptorByName("org.intermine.pathquery.model.testmodel.CEO"), path.getElementClassDescriptors().get(1)); assertEquals("company", path.getElements().get(1)); assertEquals(model.getClassDescriptorByName("org.intermine.pathquery.model.testmodel.Company"), path.getElementClassDescriptors().get(2)); assertEquals("departments", path.getElements().get(2)); assertEquals(model.getClassDescriptorByName("org.intermine.pathquery.model.testmodel.Department"), path.getElementClassDescriptors().get(3)); assertEquals("employees", path.getElements().get(3)); assertEquals(model.getClassDescriptorByName("org.intermine.pathquery.model.testmodel.Manager"), path.getElementClassDescriptors().get(4)); assertEquals("age", path.getElements().get(4)); assertEquals(Integer.class, path.getEndType()); }
List<ClassDescriptor> classDescriptors = path.getElementClassDescriptors(); List<String> fields = path.getElements();
List<ClassDescriptor> classDescriptors = path.getElementClassDescriptors(); List<String> fields = path.getElements();