Class Path


  • public class Path
    extends java.lang.Object
    Object to represent a path through an InterMine model. Construction from a String validates against model.
    Author:
    Richard Smith
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static org.apache.log4j.Logger LOG  
    • Constructor Summary

      Constructors 
      Constructor Description
      Path​(Model model, java.lang.String path)
      Create a new Path object.
      Path​(Model model, java.lang.String stringPath, java.util.Map<java.lang.String,​java.lang.String> constraintMap)
      Create a Path object using class constraints from a Map.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Path append​(java.lang.String fieldName)
      Return new Path that has this Path as its prefix and has fieldName as the last element.
      boolean containsCollections()
      Return true if and only if any part of the path is a collection.
      boolean containsReferences()
      Return true if and only if any part of the path is a reference.
      java.util.List<Path> decomposePath()
      Returns a list of paths, each corresponding to one step further along the path.
      boolean endIsAttribute()
      Return true if and only if the end of the path is an attribute.
      boolean endIsCollection()
      Return true if and only if the end of the path is a collection.
      boolean endIsReference()
      Return true if and only if the end of the path is a reference .
      boolean equals​(java.lang.Object o)
      java.util.List<ClassDescriptor> getElementClassDescriptors()
      Return a List of the ClassDescriptor objects for each element of the path.
      java.util.List<java.lang.String> getElements()
      Return a list of field names, one per path element (except for the first, which is a class).
      java.util.List<java.lang.Integer> getElementsContainingField​(java.lang.String cls, java.lang.String field)
      Return the indexes of elements containing the field given in input
      ClassDescriptor getEndClassDescriptor()
      If the last element in the path is a reference or collection return the ClassDescriptor that the reference or collection references.
      FieldDescriptor getEndFieldDescriptor()
      Return the FieldDescriptor of the last element in the path or null if the path has just one element.
      java.lang.Class<?> getEndType()
      Return the type of the last element in the path, regardless of whether it is an attribute or a class.
      ClassDescriptor getLastClassDescriptor()
      Returns the last ClassDescriptor in the path.
      java.lang.String getLastElement()
      Return the last string element of this path, throw an exception of there is only one element, i.e.
      Model getModel()
      Return the model that this path is created for.
      java.lang.String getNoConstraintsString()
      Required for jsp
      Path getPrefix()
      Return a Path object that represents the prefix of this path, ie this Path without the last element.
      ClassDescriptor getSecondLastClassDescriptor()
      Returns the second to last ClassDescriptor in the path.
      ClassDescriptor getStartClassDescriptor()
      Return the ClassDescriptor of the first element in the path.
      java.util.Map<java.lang.String,​java.lang.String> getSubClassConstraintPaths()
      Returns a Map from simplified path string (with dots instead of colons, and no constraints) to constraint class name.
      int hashCode()
      boolean isOnlyAttribute()
      Return true if the Path does not contain references or collections
      boolean isRootPath()
      Return true if this path represents just the starting class, e.g.
      boolean startContainsClass​(java.lang.String cls)
      Return true if the first element in the path has the class given in input as type
      java.lang.String toString()
      Returns a representation of the Path as a String, with class constraint markers.
      java.lang.String toStringNoConstraints()
      Returns a representation of the Path as a String, with no class constraint markers.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • LOG

        protected static final org.apache.log4j.Logger LOG
    • Constructor Detail

      • Path

        public Path​(Model model,
                    java.lang.String path)
             throws PathException
        Create a new Path object. The Path must start with a class name.
        Parameters:
        model - the Model used to check ClassDescriptors and FieldDescriptors
        path - a String of the form "Department.manager.name" or "Department.employees[Manager].seniority"
        Throws:
        PathException - thrown if there is a problem resolving the path eg. a reference doesn't exist in the model
      • Path

        public Path​(Model model,
                    java.lang.String stringPath,
                    java.util.Map<java.lang.String,​java.lang.String> constraintMap)
             throws PathException
        Create a Path object using class constraints from a Map. Unlike the other constructor, the stringPath cannot contain class constraint annotation. Either call the other constructor like this: new Path(model, "Department.employees[Manager].seniority") or call this constructor like this: new Path(model, "Department.employees.seniority", map) where the map contains: key "Department.employees" -> value: "Manager"
        Parameters:
        model - the Model used to check ClassDescriptors and FieldDescriptors
        stringPath - a String of the form "Department.manager.name"
        constraintMap - a Map from paths as string to class names - use when parts of the path are constrained to be sub-classes
        Throws:
        PathException - thrown if there is a problem resolving the path eg. a reference doesn't exist in the model
    • Method Detail

      • decomposePath

        public java.util.List<Path> decomposePath()
        Returns a list of paths, each corresponding to one step further along the path. Starts with the root path, and ends in the current path, ie: Company.departments.manager.name decomposes to: Company, Company.departments, Company.departments.manager, Company.departments.manager.name
        Returns:
        the list of composing paths.
      • containsCollections

        public boolean containsCollections()
        Return true if and only if any part of the path is a collection.
        Returns:
        the collections flag
      • containsReferences

        public boolean containsReferences()
        Return true if and only if any part of the path is a reference.
        Returns:
        the references flag
      • isOnlyAttribute

        public boolean isOnlyAttribute()
        Return true if the Path does not contain references or collections
        Returns:
        a boolean
      • endIsAttribute

        public boolean endIsAttribute()
        Return true if and only if the end of the path is an attribute.
        Returns:
        the end-is-attribute flag
      • endIsCollection

        public boolean endIsCollection()
        Return true if and only if the end of the path is a collection.
        Returns:
        the end-is-collection flag
      • endIsReference

        public boolean endIsReference()
        Return true if and only if the end of the path is a reference .
        Returns:
        the end-is-reference flag
      • getStartClassDescriptor

        public ClassDescriptor getStartClassDescriptor()
        Return the ClassDescriptor of the first element in the path. eg. for Department.name, return the Department descriptor.
        Returns:
        the starting ClassDescriptor
      • getEndFieldDescriptor

        public FieldDescriptor getEndFieldDescriptor()
        Return the FieldDescriptor of the last element in the path or null if the path has just one element. eg. for "Employee.department.name", return the Department.name descriptor but for "Employee" return null.
        Returns:
        the end FieldDescriptor
      • getEndClassDescriptor

        public ClassDescriptor getEndClassDescriptor()
        If the last element in the path is a reference or collection return the ClassDescriptor that the reference or collection references. If the path has one element (eg. "Employee"), return its ClassDescriptor. If the last element in the path is an attribute, return null.
        Returns:
        the ClassDescriptor
      • getPrefix

        public Path getPrefix()
        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.
        Returns:
        the prefix Path
      • append

        public Path append​(java.lang.String fieldName)
                    throws PathException
        Return new Path that has this Path as its prefix and has fieldName as the last element.
        Parameters:
        fieldName - the field name
        Returns:
        the new Path
        Throws:
        PathException - if the resulting Path is not valid
      • getEndType

        public java.lang.Class<?> getEndType()
        Return the type of the last element in the path, regardless of whether it is an attribute or a class.
        Returns:
        the Class of the last element
      • getLastClassDescriptor

        public ClassDescriptor getLastClassDescriptor()
        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.
        Returns:
        the ClassDescriptor
      • getSecondLastClassDescriptor

        public ClassDescriptor getSecondLastClassDescriptor()
        Returns the second to last ClassDescriptor in the path. That is, the one before the one returned by getLastClassDescriptor.
        Returns:
        the ClassDescriptor
      • getLastElement

        public java.lang.String getLastElement()
        Return the last string element of this path, throw an exception of there is only one element, i.e. for 'Company.departments.manager' return 'manager'.
        Returns:
        the last string element of the path
      • isRootPath

        public boolean isRootPath()
        Return true if this path represents just the starting class, e.g. 'Department'. Returns false of there are further elements, e.g. 'Department.manager'
        Returns:
        true if this is a root path
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Returns a representation of the Path as a String, with class constraint markers. eg. "Department.employees[Manager].seniority"
        Overrides:
        toString in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • getElements

        public java.util.List<java.lang.String> getElements()
        Return a list of field names, one per path element (except for the first, which is a class). To clarify, this does not include the root class of the path.
        Returns:
        a list of field names
      • getElementClassDescriptors

        public java.util.List<ClassDescriptor> getElementClassDescriptors()
        Return a List of the ClassDescriptor objects for each element of the path.
        Returns:
        the ClassDescriptors
      • toStringNoConstraints

        public java.lang.String toStringNoConstraints()
        Returns a representation of the Path as a String, with no class constraint markers. eg. "Department.employees.seniority"
        Returns:
        a String version of the Path
      • getNoConstraintsString

        public java.lang.String getNoConstraintsString()
        Required for jsp
        Returns:
        a String version of the Path
      • getSubClassConstraintPaths

        public java.util.Map<java.lang.String,​java.lang.String> getSubClassConstraintPaths()
        Returns a Map from simplified path string (with dots instead of colons, and no constraints) to constraint class name.
        Returns:
        subClassConstraintPaths
      • getModel

        public Model getModel()
        Return the model that this path is created for.
        Returns:
        the model
      • startContainsClass

        public boolean startContainsClass​(java.lang.String cls)
        Return true if the first element in the path has the class given in input as type
        Parameters:
        cls - the class
        Returns:
        true if the first element contains the class
      • getElementsContainingField

        public java.util.List<java.lang.Integer> getElementsContainingField​(java.lang.String cls,
                                                                            java.lang.String field)
        Return the indexes of elements containing the field given in input
        Parameters:
        cls - the class containing the field
        field - the field
        Returns:
        list of indexes