cug.ptree
Class PTree

java.lang.Object
  |
  +--cug.ptree.PTree
Direct Known Subclasses:
RStones

public class PTree
extends java.lang.Object

Tree to store Person objects typical representation of organization (left to right this time): O.OU.OU.person etc. scenario: create tree, build structure, call get... root: parent == null; both leaves (all persons) and nodelist (all branches/groups) have members branch: leaves empty, no persons are added to branch group: nodelist empty, no brach or group is added to group add all persons to root, place persons in groups, structure groups in branches two or more references to each Person instance are kept: 1 in root and 1 in each group person belongs to


Field Summary
(package private)  PTreeAtts atts
          attributes for node
(package private) static Category cat
           
protected  java.lang.String code
          unique code for this PTree; concatenation of name and parent names (cf distinguished name)
(package private)  java.util.Map leaves
          Person instances belonging to this; only root PTree and groups have leaves
(package private)  java.lang.String name
          name
(package private)  java.util.Map nodelist
          branches and groups with parented by this
(package private)  PTree parent
          parent PTree
 
Constructor Summary
PTree(PTree p, java.lang.String name)
           
PTree(java.lang.String name, java.lang.String code)
          create PTree as root
 
Method Summary
 void addNode(PTree n)
          can only add node if leaves is empty (or this is root) after first call to addNode, this is a branch, and adding persons is no longer possible :error: cannot add node to group
 void addPerson(Person p)
          can only add person if nodelist is empty (or root) if this method is called 'this' becomes a group, and adding nodes is no longer possible person is added to 'this' and to root (if 'this' is not root) :error: cannot add person to branch
 void build()
          Deprecated.  
 void connectPersonsToGroupName()
          Deprecated. is really just foolish
 void connectPersonsToLevelName()
          Deprecated. is really just foolish
 void connectPersonsToNextLevelName()
          Deprecated. is really just foolish
 PTree createNode(java.lang.String s)
          create sub-node
 java.util.List getAllNodes()
           
 java.lang.String getAttribute(java.lang.String key)
          public interface to ptree-atts
 java.lang.String getAttribute(java.lang.String key, java.lang.String def)
          public interface to ptree-atts
protected  PTreeAtts getAttributes()
           
 java.lang.String getCode()
           
 java.util.List getGroupNodes()
           
 java.lang.String getName()
           
 PTree getNode(java.lang.String s)
           
 PTree getNodeBelow(java.lang.String s)
          lookup
 PTree getNodeByName(java.lang.String s)
          Deprecated.  
 java.util.Iterator getNodeIt()
           
 PTree getOrCreateNode(java.lang.String s)
          useful when tree is filled on the fly
 PTree getParent()
           
 java.lang.String getParentCode()
          extract parentcode from code string ( !
 java.util.List getParents()
          Deprecated.  
 Person getPerson(java.lang.String s)
          retrieve person by personID
 Person getPersonBelow(java.lang.String key)
          retrieve person by personID in this and all nodes below
 java.util.Iterator getPersonIt()
          order by personID
 java.util.List getPersonsBelow()
           
 java.util.Iterator getPersonsBelowIt()
          natural order
 java.util.Iterator getPersonSortIt()
          natural order of Person (names)
 java.util.Iterator getPersonSortIt(java.util.Comparator c)
           
(package private)  PTreeAtts getPTreeAtts()
           
 PTree getRoot()
           
 boolean isBranch()
          no leaves && parent <> null
 boolean isGroup()
          no sub nodes
 boolean isRoot()
          parent == null
 void removeAll()
          empty nodelist and leaves;
static void report(java.io.PrintWriter pw, PTree pt)
          diagnostic report print contents of PTree depth first to printwriter (simple text)
 void setAttribute(java.lang.String key, java.lang.String value)
          public interface to ptree-atts
protected  void setCode()
          write once set code based on name (no whitespace, uppercase) and parent-code called in setParent to reset code
 void setCode(java.lang.String c)
          write once; use to set code if parent is not yet known (asynchronous initialization) code is set again if parent is set
 void setParent(PTree pt)
          write once; resets code :warn: ptree is moved if code is changed after reset :error: parent already set'
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cat

static Category cat

parent

PTree parent
parent PTree


name

java.lang.String name
name


code

protected java.lang.String code
unique code for this PTree; concatenation of name and parent names (cf distinguished name)


nodelist

java.util.Map nodelist
branches and groups with parented by this


leaves

java.util.Map leaves
Person instances belonging to this; only root PTree and groups have leaves


atts

PTreeAtts atts
attributes for node

Constructor Detail

PTree

public PTree(java.lang.String name,
             java.lang.String code)
create PTree as root

See Also:
for asynchronous initialization, for code-constraints

PTree

public PTree(PTree p,
             java.lang.String name)
Method Detail

build

public void build()
           throws java.lang.Exception
Deprecated.  

java.lang.Exception

isRoot

public boolean isRoot()
parent == null


isBranch

public boolean isBranch()
no leaves && parent <> null


isGroup

public boolean isGroup()
no sub nodes


removeAll

public void removeAll()
empty nodelist and leaves;


getName

public java.lang.String getName()

getParent

public PTree getParent()

getCode

public java.lang.String getCode()

getRoot

public PTree getRoot()
Returns:
PTree parent of parent etc.; should never return null

getParents

public java.util.List getParents()
Deprecated.  

attempt to implement xpath-like axis

Returns:
all parents including root; (order from (larger) root to (smaller) group)

setParent

public void setParent(PTree pt)
write once; resets code

:warn: ptree is moved if code is changed after reset

:error: parent already set'


setCode

public void setCode(java.lang.String c)
write once; use to set code if parent is not yet known (asynchronous initialization) code is set again if parent is set

See Also:
setParent(cug.ptree.PTree)

setCode

protected void setCode()
write once set code based on name (no whitespace, uppercase) and parent-code called in setParent to reset code


getParentCode

public java.lang.String getParentCode()
extract parentcode from code string ( != getParent().getCode() ) use in asynchronous construction of PTree (code known, parent not known)

Returns:
String substring of code up to last '.'; null if no '.' (root)

getPTreeAtts

PTreeAtts getPTreeAtts()
Returns:
null if no attributes are set

getAttributes

protected PTreeAtts getAttributes()

setAttribute

public void setAttribute(java.lang.String key,
                         java.lang.String value)
public interface to ptree-atts


getAttribute

public java.lang.String getAttribute(java.lang.String key,
                                     java.lang.String def)
public interface to ptree-atts


getAttribute

public java.lang.String getAttribute(java.lang.String key)
public interface to ptree-atts


createNode

public PTree createNode(java.lang.String s)
create sub-node


addNode

public void addNode(PTree n)
can only add node if leaves is empty (or this is root) after first call to addNode, this is a branch, and adding persons is no longer possible

:error: cannot add node to group


getNode

public PTree getNode(java.lang.String s)
Returns:
PTree pt; node with this as parent and param name

getOrCreateNode

public PTree getOrCreateNode(java.lang.String s)
useful when tree is filled on the fly

Returns:
PTree pt; node previously added or created based on name

getAllNodes

public java.util.List getAllNodes()
Returns:
List l, item-type PTree; this and all nodes below

getGroupNodes

public java.util.List getGroupNodes()
Returns:
List l, item-type PTree; all group-nodes below (leaves)

getNodeBelow

public PTree getNodeBelow(java.lang.String s)
lookup

Returns:
PTree pt; if node with code param is found below this; null if not found

getNodeByName

public PTree getNodeByName(java.lang.String s)
Deprecated.  

lookup

Returns:
PTree pt; first node with name param; null if not found

addPerson

public void addPerson(Person p)
can only add person if nodelist is empty (or root) if this method is called 'this' becomes a group, and adding nodes is no longer possible person is added to 'this' and to root (if 'this' is not root)

:error: cannot add person to branch


getPerson

public Person getPerson(java.lang.String s)
retrieve person by personID


getPersonBelow

public Person getPersonBelow(java.lang.String key)
retrieve person by personID in this and all nodes below

Returns:
Person p; first match found; null if none of the persons below match

getNodeIt

public java.util.Iterator getNodeIt()
Returns:
Iterator (PTree) over all sub-nodes

getPersonIt

public java.util.Iterator getPersonIt()
order by personID

Returns:
Iterator (Person) over all persons belonging to this

getPersonSortIt

public java.util.Iterator getPersonSortIt()
natural order of Person (names)

Returns:
Iterator (Person) over all persons belonging to this

getPersonSortIt

public java.util.Iterator getPersonSortIt(java.util.Comparator c)
Returns:
Iterator (Person) over all persons belonging to this

getPersonsBelow

public java.util.List getPersonsBelow()
Returns:
List of Person; all persons in groups below 'this' in tree

getPersonsBelowIt

public java.util.Iterator getPersonsBelowIt()
natural order

Returns:
Iterator over all persons belonging to group-nodes below

connectPersonsToLevelName

public void connectPersonsToLevelName()
Deprecated. is really just foolish

make name of ptree available to person

See Also:
Person.setConnectedObject(java.lang.Object)

connectPersonsToNextLevelName

public void connectPersonsToNextLevelName()
Deprecated. is really just foolish

make name of ptree of next level (parent is 'this') available to person

See Also:
Person.setConnectedObject(java.lang.Object)

connectPersonsToGroupName

public void connectPersonsToGroupName()
Deprecated. is really just foolish

make name of group person belongs to his connected object available to person ; name of last group found is used

See Also:
Person.setConnectedObject(java.lang.Object)

report

public static void report(java.io.PrintWriter pw,
                          PTree pt)
diagnostic report print contents of PTree depth first to printwriter (simple text)