Class EfficientTreeImpl

  • All Implemented Interfaces:
    java.lang.Cloneable, EfficientTree

    public class EfficientTreeImpl
    extends java.lang.Object
    implements EfficientTree
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int childrenFactor  
    • Constructor Summary

      Constructors 
      Constructor Description
      EfficientTreeImpl​(int[] tree, gnu.trove.map.TObjectIntMap<java.lang.String> activity2int, java.lang.String[] int2activity)
      Construct a new efficient tree using the given inputs.
    • Constructor Detail

      • EfficientTreeImpl

        public EfficientTreeImpl​(int[] tree,
                                 gnu.trove.map.TObjectIntMap<java.lang.String> activity2int,
                                 java.lang.String[] int2activity)
        Construct a new efficient tree using the given inputs. These inputs will not be copied and should not be altered outside the EfficientTree context after creating the tree.
        Parameters:
        tree -
        activity2int - The mapping from activities (strings) to integers. The map should be created such that the emptiness value is not 0 (as that is a valid activity). Preferably, use getEmptyActivity2int() to obtain such a map.
        int2activity - The mapping from integers to the activities (strings). Should be consistent with activity2int.
    • Method Detail

      • getTree

        public int[] getTree()
        Specified by:
        getTree in interface EfficientTree
        Returns:
        the internal representation of the process tree. Do not edit the returned object.
      • getActivity2int

        public gnu.trove.map.TObjectIntMap<java.lang.String> getActivity2int()
        Specified by:
        getActivity2int in interface EfficientTree
        Returns:
        A map from activity to index
      • getInt2activity

        public java.lang.String[] getInt2activity()
        Specified by:
        getInt2activity in interface EfficientTree
        Returns:
        A map from index (not node!) to activity.
      • addChild

        public void addChild​(int parent,
                             int asChildNr,
                             int operatorOrActivity)
        Add a child to the tree, as a child of parent, at the given position. The caller has to ensure there's enough space in the array of the tree.
        Parameters:
        parent -
        asChildNr -
      • traverse

        public int traverse​(int node)
        Specified by:
        traverse in interface EfficientTree
        Returns:
        the first node after node i.
      • getActivity

        public int getActivity​(int node)
        Specified by:
        getActivity in interface EfficientTree
        Returns:
        the activity number denoted at position node. Only call if the node is an activity.
      • getActivityName

        public java.lang.String getActivityName​(int node)
        Specified by:
        getActivityName in interface EfficientTree
        Returns:
        the activity name denoted at position node. Only call if the node is an activity.
      • isOperator

        public boolean isOperator​(int node)
        Specified by:
        isOperator in interface EfficientTree
        Returns:
        whether the node at position i is an operator
      • getNumberOfChildren

        public int getNumberOfChildren​(int node)
        Specified by:
        getNumberOfChildren in interface EfficientTree
        Returns:
        the number of children of the current node. Only call when the node is an operator.
      • getChild

        public int getChild​(int parent,
                            int numberOfChild)
        Specified by:
        getChild in interface EfficientTree
        numberOfChild - (the first child has number 0)
        Returns:
        the position of the #nrOfChild child of parent.
      • isTau

        public boolean isTau​(int node)
        Specified by:
        isTau in interface EfficientTree
        Returns:
        whether the given node is a tau
      • isActivity

        public boolean isActivity​(int node)
        Specified by:
        isActivity in interface EfficientTree
        Returns:
        whether the given node is an activity
      • isSequence

        public boolean isSequence​(int node)
        Specified by:
        isSequence in interface EfficientTree
        Returns:
        whether the given node is a sequence
      • isXor

        public boolean isXor​(int node)
        Specified by:
        isXor in interface EfficientTree
        Returns:
        whether the given node is a xor
      • isConcurrent

        public boolean isConcurrent​(int node)
        Specified by:
        isConcurrent in interface EfficientTree
        Returns:
        whether the given node is an and
      • isInterleaved

        public boolean isInterleaved​(int node)
        Specified by:
        isInterleaved in interface EfficientTree
        Returns:
        whether the given node is an interleaved node
      • isLoop

        public boolean isLoop​(int node)
        Specified by:
        isLoop in interface EfficientTree
        Returns:
        whether the given node is a loop
      • isOr

        public boolean isOr​(int node)
        Specified by:
        isOr in interface EfficientTree
        Returns:
        whether the given node is an or
      • getRoot

        public int getRoot()
        Specified by:
        getRoot in interface EfficientTree
        Returns:
        The index of the root of the tree.
      • getChildren

        public java.lang.Iterable<java.lang.Integer> getChildren​(int node)
        Specified by:
        getChildren in interface EfficientTree
        Returns:
        an iterable over all children of the given node.
      • shortenTree

        public EfficientTreeImpl shortenTree()
        Copy the tree into a tight array
      • isSkip

        public boolean isSkip​(int node)
        Specified by:
        isSkip in interface EfficientTree
        Returns:
        whether the given node is not a semantic node (doesn't exist)
      • getChildTree

        @Deprecated
        public int[] getChildTree​(int node)
        Deprecated.
      • getEmptyActivity2int

        public static gnu.trove.map.TObjectIntMap<java.lang.String> getEmptyActivity2int()
      • replaceTree

        public void replaceTree​(int[] tree)
        Replace the tree structure.
        Parameters:
        tree -
      • toString

        public java.lang.String toString()
        Return a string representation of this tree. This string representation is not unique for equivalent trees, e.g. the trees xor(a, b) and xor(b, a) are equivalent, but do not have the same string representation.
        Overrides:
        toString in class java.lang.Object
      • hashCode

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

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • getMaxNumberOfNodes

        public int getMaxNumberOfNodes()
        Specified by:
        getMaxNumberOfNodes in interface EfficientTree
        Returns:
        a number that is larger or equal to the number of nodes in the tree.
      • copy

        public void copy​(int srcPos,
                         int destPos,
                         int length)
        Description copied from interface: EfficientTree
        Please refer to EfficientTreeUtils for higher-level editing functions. The usage of this method is not encouraged. Copies nodes in the tree, overwriting the nodes at the destination. It is the responsibility of the caller to ensure there is enough space in the tree, and to ensure the tree remains consistent.
        Specified by:
        copy in interface EfficientTree
        Parameters:
        srcPos - start of the block - source
        destPos - start of the block - destination
        length - number of nodes to be moved
      • setNodeType

        public void setNodeType​(int node,
                                EfficientTree.NodeType operator)
        Description copied from interface: EfficientTree
        Please refer to EfficientTreeUtils for higher-level editing functions. The usage of this method is not encouraged. Sets the type of a node. It is the responsibility of the caller to ensure that no non-operator is changed into/from an operator, as this might have unexpected consequences.
        Specified by:
        setNodeType in interface EfficientTree
      • setNodeActivity

        public void setNodeActivity​(int node,
                                    int activity)
        Description copied from interface: EfficientTree
        Please refer to EfficientTreeUtils for higher-level editing functions. The usage of this method is not encouraged.
        Specified by:
        setNodeActivity in interface EfficientTree
      • setNumberOfChildren

        public void setNumberOfChildren​(int node,
                                        int numberOfChildren)
        Description copied from interface: EfficientTree
        Please refer to EfficientTreeUtils for higher-level editing functions. The usage of this method is not encouraged. Sets the number of children of a node. It is the responsibility of the caller to ensure the tree remains consistent.
        Specified by:
        setNumberOfChildren in interface EfficientTree
      • setSize

        public void setSize​(int size)
        Description copied from interface: EfficientTree
        Please refer to EfficientTreeUtils for higher-level editing functions. The usage of this method is not encouraged. Set the size as given. Adds skip nodes if necessary.
        Specified by:
        setSize in interface EfficientTree
      • swap

        public void swap​(int startA,
                         int startB,
                         int lengthB)
        Description copied from interface: EfficientTree
        Please refer to EfficientTreeUtils for higher-level editing functions. The usage of this method is not encouraged. Swap two consecutive children in a tree.
        Specified by:
        swap in interface EfficientTree
      • reorderNodes

        public void reorderNodes​(java.lang.Integer[] nodes,
                                 int end)
        Description copied from interface: EfficientTree
        Please refer to EfficientTreeUtils for higher-level editing functions. The usage of this method is not encouraged. Reorders nodes
        Specified by:
        reorderNodes in interface EfficientTree
        Parameters:
        nodes - A consecutive but possibly shuffled list of indices, in which to reorder nodes.
        end - The index after the end of the last node.