Class PrimitiveUtils.PathCounter

  • Enclosing class:
    PrimitiveUtils

    public static final class PrimitiveUtils.PathCounter
    extends java.lang.Object
    The PathCounter class helps count the number of possible paths from a source (parent) primitive to a target (child) primitive. It memorizes all previous results to avoid redundant tree traversals. N.B. The class can be used only for OP primitives. Other primitive kinds are not supported (there is no need for such a facility).
    • Constructor Summary

      Constructors 
      Constructor Description
      PathCounter()
      Constructs a path counter object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getPathCount​(Primitive source, java.lang.String target)
      Counts the number of possible paths from the source (parent) primitive to the target (child) primitive.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PathCounter

        public PathCounter()
        Constructs a path counter object.
    • Method Detail

      • getPathCount

        public int getPathCount​(Primitive source,
                                java.lang.String target)
        Counts the number of possible paths from the source (parent) primitive to the target (child) primitive. The method recursively traverses all AND- and OR- rules starting from the source primitive searching for child primitives which name equals the target name. Important points: (1) If the source is not an OP primitive (operation) 0 is returned. (2) If there are several references from a parent to a child they are considered as a single path. To avoid redundant traversals and calculations, the method memorizes all previous results. This information is used when it is requested again. This is important as the method works recursively. That is information on paths from a parent is calculated as a sum of the result of its childs. In this case, there is no need to traverse all the hierarchy again if information on child primitives has already been calculated.
        Parameters:
        source - Source (parent) primitive.
        target - Target (child) primitive name.
        Returns:
        The number of possible paths from the source to the target.
        Throws:
        java.lang.NullPointerException - if any of the parameters equals null.