Class Partition

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class Partition
    extends Data
    This is an abstract container for a partition in the graph. This used for the generation of the partition element in the partition graph, and identifies the relations between the jobs in the partition if any.
    Version:
    $Revision$
    Author:
    Karan Vahi
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String mID
      The partition id of the partition.
      private int mIndex
      The index associated with the partition.
      private GraphNode mLastAddedNode
      A pointer to the last added node to the partition.
      private java.lang.String mName
      The name of the partition.
      private java.util.List mNodeList
      The list of GraphNode objects corresponding to the nodes making the partiition.
      private java.util.Set mNodeSet
      The set of node id's in the partition.
      private java.util.Map mParentsMap
      A map containing a node and it's parents ids in the partition.
    • Constructor Summary

      Constructors 
      Constructor Description
      Partition()
      The default constructor.
      Partition​(java.util.List nodeList, java.lang.String id)
      The overloaded constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addNode​(GraphNode node)
      Adds a node to the partition.
      void addParents​(java.lang.String node, java.util.List parents)
      Ends up assigning the parents to a particular node.
      java.lang.Object clone()
      Returns a copy of the object
      void constructPartition()
      It while looking at the node list constructs the relations between the jobs in the partition, that can be gotten through getRelationsInPartition().
      java.lang.String getID()
      It returns the unique id that is associated with the partition.
      int getIndex()
      It returns the index to number of the partition.
      java.lang.String getName()
      It returns the name of the partition.
      java.util.Set getNodeIDs()
      It returns the set of the job ids making up the partition.
      java.util.List<GraphNode> getNodes()
      Returns a list of nodes making up the partition.
      java.util.List<java.lang.String> getParents​(java.lang.String id)
      Returns a list of id's of parents for a node in the partition.
      java.util.Map getRelations()
      A function to return the child-parent relations for the jobs making up the partition.
      java.util.List getRootNodes()
      Returns the root nodes in the partition.
      GraphNode lastAddedNode()
      Returns the last added node to the partition.
      void setID​(java.lang.String id)
      It sets the id of the partition.
      void setIndex​(int index)
      It sets the index associated with this partition to the value passed.
      void setName​(java.lang.String name)
      It sets the partition name to the value passed.
      int size()
      Returns the number of nodes in the partition.
      java.lang.String toString()
      Returns a String version of the object.
      java.lang.String toXML()
      Returns the xml description of the object.
      void toXML​(java.io.Writer writer)
      Returns the xml description of the object.
      private void writeAttribute​(java.io.Writer writer, java.lang.String key, java.lang.String value)
      Writes an attribute to the stream.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • mNodeSet

        private java.util.Set mNodeSet
        The set of node id's in the partition.
      • mParentsMap

        private java.util.Map mParentsMap
        A map containing a node and it's parents ids in the partition. A node id's is the key and the corresponding value is the list of String id's of it's parents. The map only contain those nodes for which there is a parent.
      • mNodeList

        private java.util.List mNodeList
        The list of GraphNode objects corresponding to the nodes making the partiition.
      • mID

        private java.lang.String mID
        The partition id of the partition.
      • mIndex

        private int mIndex
        The index associated with the partition. In most cases the ID of the partition is constructed using this index.
      • mName

        private java.lang.String mName
        The name of the partition.
      • mLastAddedNode

        private GraphNode mLastAddedNode
        A pointer to the last added node to the partition.
    • Constructor Detail

      • Partition

        public Partition()
        The default constructor.
      • Partition

        public Partition​(java.util.List nodeList,
                         java.lang.String id)
        The overloaded constructor.
        Parameters:
        nodeList - list of GraphNode objects.
        id - the partition id of the partition.
    • Method Detail

      • addNode

        public void addNode​(GraphNode node)
        Adds a node to the partition. It ends up adding it to the underneath node list.
        Parameters:
        node - the GraphNode object corresponding to the job that is to be added.
      • lastAddedNode

        public GraphNode lastAddedNode()
        Returns the last added node to the partition.
        Returns:
        the last added node, or null in case partition is empty
      • getNodes

        public java.util.List<GraphNode> getNodes()
        Returns a list of nodes making up the partition.
        Returns:
        List of GraphNode objects.
      • getRootNodes

        public java.util.List getRootNodes()
        Returns the root nodes in the partition. They can only be determined, after the constructPartition() has been called.
        Returns:
        List of GraphNode objects that are the root.
      • constructPartition

        public void constructPartition()
        It while looking at the node list constructs the relations between the jobs in the partition, that can be gotten through getRelationsInPartition().
      • setName

        public void setName​(java.lang.String name)
        It sets the partition name to the value passed.
        Parameters:
        name - the name to which the partition name needs to be set to.
      • getName

        public java.lang.String getName()
        It returns the name of the partition.
      • setIndex

        public void setIndex​(int index)
        It sets the index associated with this partition to the value passed.
        Parameters:
        index - the index value.
      • getIndex

        public int getIndex()
        It returns the index to number of the partition.
      • getID

        public java.lang.String getID()
        It returns the unique id that is associated with the partition.
      • setID

        public void setID​(java.lang.String id)
        It sets the id of the partition.
        Parameters:
        id - the id of the partition.
      • size

        public int size()
        Returns the number of nodes in the partition.
        Returns:
        the number of nodes.
      • getParents

        public java.util.List<java.lang.String> getParents​(java.lang.String id)
        Returns a list of id's of parents for a node in the partition. It lists parents that in the partition itself
        Parameters:
        id - the node for which parents are required
        Returns:
        List of parents else empty list
      • toString

        public java.lang.String toString()
        Returns a String version of the object.
        Specified by:
        toString in class Data
      • toXML

        public void toXML​(java.io.Writer writer)
                   throws java.io.IOException
        Returns the xml description of the object. This is used for generating the partition graph. That is no longer done.
        Parameters:
        writer - is a Writer opened and ready for writing. This can also be a StringWriter for efficient output.
        Throws:
        java.io.IOException - if something fishy happens to the stream.
      • toXML

        public java.lang.String toXML()
                               throws java.io.IOException
        Returns the xml description of the object. This is used for generating the partition graph. That is no longer done.
        Returns:
        String containing the Partition object in XML.
        Throws:
        java.io.IOException - if something fishy happens to the stream.
      • writeAttribute

        private void writeAttribute​(java.io.Writer writer,
                                    java.lang.String key,
                                    java.lang.String value)
                             throws java.io.IOException
        Writes an attribute to the stream. Wraps the value in quotes as required by XML.
        Parameters:
        writer -
        key -
        value -
        Throws:
        java.io.IOException - if something fishy happens to the stream.
      • getNodeIDs

        public java.util.Set getNodeIDs()
        It returns the set of the job ids making up the partition.
      • addParents

        public void addParents​(java.lang.String node,
                               java.util.List parents)
        Ends up assigning the parents to a particular node. It does assign the parents to the node, if the node is in the partition. It however does not check if the parents are in the partition or not.
        Parameters:
        node - the id of the node for which you want to add the parents.
        parents - list of id's of the parents of the nodes.
      • getRelations

        public java.util.Map getRelations()
        A function to return the child-parent relations for the jobs making up the partition. The child parent relations are only returned for the jobs that have parents in the partition.
        Returns:
        Map containing the job id's as the keys and the values as the list of the parent id's in the partition.
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Returns a copy of the object
        Overrides:
        clone in class java.lang.Object
        Throws:
        java.lang.CloneNotSupportedException