/** * Return new Path that has this Path as its prefix and has fieldName as the last element. * * @param fieldName the field name * @return the new Path * @throws PathException if the resulting Path is not valid */ public Path append(String fieldName) throws PathException { return new Path(model, toString() + "." + fieldName); }
/** * Constructor that takes a Path object. The human readable name for getName() will be * generated from the path. * * @param path a Path object * @param index the number of the column * @param type the type of the column (ClassDescriptor or Class) */ public Column(Path path, int index, Class type) { this.path = path; this.name = path.toStringNoConstraints().replaceAll("[:.](?!\\s)", " > "); this.index = index; this.type = type; setColumnId(path.toString().substring(0, path.toString().lastIndexOf(".")) + "_" + TypeUtil.unqualifiedName(type.getName())); }
/** * Return new Path that has this Path as its prefix and has fieldName as the last element. * * @param fieldName the field name * @return the new Path * @throws PathException if the resulting Path is not valid */ public Path append(String fieldName) throws PathException { return new Path(model, toString() + "." + fieldName); }
/** * Constructor that takes a Path object. The human readable name for getName() will be * generated from the path. * * @param path a Path object * @param index the number of the column * @param type the type of the column (ClassDescriptor or Class) */ public Column(Path path, int index, Class type) { this.path = path; this.name = path.toStringNoConstraints().replaceAll("[:.](?!\\s)", " > "); this.index = index; this.type = type; setColumnId(path.toString().substring(0, path.toString().lastIndexOf(".")) + "_" + TypeUtil.unqualifiedName(type.getName())); }
/** * Constructor that takes a Path object. * * @param path a Path object * @param name an optional, more human readable description of the Column that will be * returned by getName() - can be null in which case the column name (given by * path.toStringNoConstraints()) will be used * @param index the number of the column * @param type the type of the column (ClassDescriptor or Class) */ public Column(Path path, String name, int index, Class type) { this.path = path; this.name = name; this.index = index; this.type = type; setColumnId(path.toString().substring(0, path.toString().lastIndexOf(".")) + "_" + TypeUtil.unqualifiedName(type.getName())); }
/** * Constructor that takes a Path object. * * @param path a Path object * @param name an optional, more human readable description of the Column that will be * returned by getName() - can be null in which case the column name (given by * path.toStringNoConstraints()) will be used * @param index the number of the column * @param type the type of the column (ClassDescriptor or Class) */ public Column(Path path, String name, int index, Class type) { this.path = path; this.name = name; this.index = index; this.type = type; setColumnId(path.toString().substring(0, path.toString().lastIndexOf(".")) + "_" + TypeUtil.unqualifiedName(type.getName())); }
/** * Return a Path object that represents the prefix of this path, ie this Path without the * last element. If the Path contains only the root class, an exception is thrown. * * @return the prefix Path */ public Path getPrefix() { if (isRootPath()) { throw new RuntimeException("path (" + this + ") has only one element"); } String pathString = toString(); int lastDotIndex = pathString.lastIndexOf('.'); int lastIndex = pathString.lastIndexOf(':'); if (lastDotIndex > lastIndex) { lastIndex = lastDotIndex; } try { return new Path(model, pathString.substring(0, lastIndex)); } catch (PathException e) { // Should not happen throw new Error("There must be a bug", e); } }
/** * Return a Path object that represents the prefix of this path, ie this Path without the * last element. If the Path contains only the root class, an exception is thrown. * * @return the prefix Path */ public Path getPrefix() { if (isRootPath()) { throw new RuntimeException("path (" + this + ") has only one element"); } String pathString = toString(); int lastDotIndex = pathString.lastIndexOf('.'); int lastIndex = pathString.lastIndexOf(':'); if (lastDotIndex > lastIndex) { lastIndex = lastDotIndex; } try { return new Path(model, pathString.substring(0, lastIndex)); } catch (PathException e) { // Should not happen throw new Error("There must be a bug", e); } }
public void testToString() throws Exception { Map<String, String> constraintMap = new HashMap<String, String>(); constraintMap.put("Department.manager", "CEO"); constraintMap.put("Department.manager.company.departments.employees", "Manager"); String stringPath = "Department.manager.company.departments.employees.age"; Path path = new Path(model, stringPath, constraintMap); assertEquals("Department.manager[CEO].company.departments.employees[Manager].age", path.toString()); }
public void testAppend2() throws Exception { Path expDeptPath = new Path(model, "Department.manager[CEO].company.departments"); Path expEmpPath = new Path(model, "Department.manager[CEO].company.departments.employees"); String testPathStr = "Department.manager[CEO].company"; Path path = new Path(model, testPathStr); Path depPath = path.append("departments"); assertEquals(expDeptPath.toString(), depPath.toString()); Path empPath = depPath.append("employees"); assertEquals(expEmpPath.toString(), empPath.toString()); }
+ " is not a superclass of the class: " + Util.getFriendlyName(o.getClass()) + " while resolving object: " + o, path.toString());
+ " is not a superclass of the class: " + Util.getFriendlyName(o.getClass()) + " while resolving object: " + o, path.toString());
public void testDecomposePath() throws Exception { String shortPathString = "Company"; Path shortPath = new Path(model, shortPathString); List<Path> decomposedPaths = shortPath.decomposePath(); assertTrue(decomposedPaths != null); assertTrue(decomposedPaths.size() == 1); assertTrue("Company".equals(decomposedPaths.get(0).toString())); String longPathString = "Company.departments.manager.name"; Path longPath = new Path(model, longPathString); decomposedPaths = longPath.decomposePath(); assertTrue(decomposedPaths != null); assertTrue(decomposedPaths.size() == 4); assertTrue("Company".equals(decomposedPaths.get(0).toString())); assertTrue("Company.departments".equals(decomposedPaths.get(1).toString())); assertTrue("Company.departments.manager".equals(decomposedPaths.get(2).toString())); assertTrue("Company.departments.manager.name".equals(decomposedPaths.get(3).toString())); }
+ " is not a superclass of the class: " + Util.getFriendlyName(o.getClass()) + " while resolving object: " + o, path.toString());
+ " is not a superclass of the class: " + Util.getFriendlyName(o.getClass()) + " while resolving object: " + o, path.toString());
public void testGetPrefix() throws Exception { Map<String, String> constraintMap = new HashMap<String, String>(); constraintMap.put("Department.manager", "CEO"); constraintMap.put("Department.manager.company.departments.employees", "Manager"); String stringPath = "Department.manager.company.departments.employees.age"; Path path = new Path(model, stringPath, constraintMap); Path prefix = path.getPrefix(); assertEquals("Department.manager[CEO].company.departments.employees[Manager]", prefix.toString()); prefix = prefix.getPrefix(); assertEquals("Department.manager[CEO].company.departments", prefix.toString()); prefix = prefix.getPrefix(); assertEquals("Department.manager[CEO].company", prefix.toString()); prefix = prefix.getPrefix(); assertEquals("Department.manager[CEO]", prefix.toString()); prefix = prefix.getPrefix(); assertEquals("Department", prefix.toString()); try { prefix = prefix.getPrefix(); fail("expected RuntimeException"); } catch (RuntimeException e) { // expected } }
public void testGetPrefixOuterJoin() throws Exception { Map<String, String> constraintMap = new HashMap<String, String>(); constraintMap.put("Department.manager", "CEO"); constraintMap.put("Department.manager.company.departments.employees", "Manager"); String stringPath = "Department:manager.company:departments.employees.age"; Path path = new Path(model, stringPath, constraintMap); Path prefix = path.getPrefix(); assertEquals("Department:manager[CEO].company:departments.employees[Manager]", prefix.toString()); prefix = prefix.getPrefix(); assertEquals("Department:manager[CEO].company:departments", prefix.toString()); prefix = prefix.getPrefix(); assertEquals("Department:manager[CEO].company", prefix.toString()); prefix = prefix.getPrefix(); assertEquals("Department:manager[CEO]", prefix.toString()); prefix = prefix.getPrefix(); assertEquals("Department", prefix.toString()); try { prefix = prefix.getPrefix(); fail("expected RuntimeException"); } catch (RuntimeException e) { // expected } }
public void testValid() throws Exception { String stringPath = "Department.company"; Path path = new Path(model, stringPath); ClassDescriptor cld = model.getClassDescriptorByName("org.intermine.pathquery.model.testmodel.Department"); assertEquals(cld, path.getStartClassDescriptor()); FieldDescriptor fld = cld.getFieldDescriptorByName("company"); assertEquals(fld, path.getEndFieldDescriptor()); ClassDescriptor compDesc = model.getClassDescriptorByName("org.intermine.pathquery.model.testmodel.Company"); assertEquals(compDesc, path.getEndClassDescriptor()); assertFalse(path.containsCollections()); assertEquals(stringPath, path.toString()); }