KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > JaWEParentMap


1 /* PEParentMap.java
2  *
3  * Authors:
4  * Stefanovic Nenad chupo@iis.ns.ac.yu
5  * Bojanic Sasa sasaboy@neobee.net
6  * Puskas Vladimir vpuskas@eunet.yu
7  * Pilipovic Goran zboniek@uns.ac.yu
8  *
9  */

10
11 package org.enhydra.jawe;
12
13 import org.enhydra.jawe.graph.*;
14
15 import org.jgraph.graph.*;
16
17 import java.util.*;
18 import javax.swing.tree.TreeNode JavaDoc;
19
20 /**
21 * Describes relations between childs and parents.
22 *
23 */

24 public class JaWEParentMap extends ParentMap {
25
26    /**
27    * Returns the list of parents that will be empty when
28    * this parent map is applied.
29    */

30    public ArrayList emptyParentList() {
31       ArrayList list = new ArrayList();
32       Iterator it = childCount.entrySet().iterator();
33       while (it.hasNext()) {
34          Map.Entry entry = (Map.Entry) it.next();
35          if (entry.getValue() instanceof Integer JavaDoc) {
36             if (((Integer JavaDoc) entry.getValue()).intValue()==0)
37                list.add(entry.getKey());
38          }
39       }
40       return list;
41    }
42
43    /**
44    * Returns true if Participant that is in changed nodes set has other Participants.
45    * NOTE: because this method is not used when Participants are added to each other,
46    * method doesn't check for added participants but only for removed.
47    */

48    public boolean hasAnyParticipant (Object JavaDoc p) {
49       if ((p==null) || !(p instanceof Participant)) {
50          return false;
51       }
52       // getting current state in model
53
Set childParticipants=new HashSet(((Participant)p).getChildParticipants());
54       // removing from it all changedNodes - this means (considering a NOTE)
55
// that these participants will be deleted after parent map is applied
56
childParticipants.removeAll(changedNodes);
57
58       return (childParticipants.size()>0);
59
60    }
61
62
63    /**
64    * Returns all children which will belong to given parent
65    * when this parent map is applied.
66    */

67    public ArrayList getNewChildren (Object JavaDoc parent) {
68       ArrayList list = new ArrayList();
69       if (parent!= null) {
70          Iterator it = entries.iterator();
71          while (it.hasNext()) {
72             Entry entry = (Entry)it.next();
73             Object JavaDoc parentFromEntry=entry.getParent();
74             if (parentFromEntry != null && parentFromEntry.equals(parent)) {
75                list.add(entry.getChild());
76             }
77          }
78       }
79       return list;
80    }
81
82    /**
83    * Returns parent of given child. The child will belong to returned
84    * parent when this parent map is applied.
85    */

86    public Object JavaDoc getNewParent (Object JavaDoc child) {
87       Object JavaDoc parent=null;
88       if (child !=null) {
89          Iterator it = entries.iterator();
90          while (it.hasNext()) {
91             Entry entry = (Entry)it.next();
92             Object JavaDoc childFromEntry=entry.getChild();
93             if (childFromEntry!=null && childFromEntry.equals(child)) {
94                parent=entry.getParent();
95                break;
96             }
97          }
98       }
99       return parent;
100    }
101
102    /**
103    * Returns nodes that will be removed after this map is applied (These
104    * are entries which parent part is null).
105    */

106    public ArrayList getRemovedNodes () {
107       ArrayList list = new ArrayList();
108       Iterator it = entries.iterator();
109       while (it.hasNext()) {
110          Entry entry = (Entry)it.next();
111          Object JavaDoc parentFromEntry=entry.getParent();
112          if (parentFromEntry == null) {
113             list.add(entry.getChild());
114          }
115       }
116       return list;
117    }
118
119    /**
120    * Returns the number of entries in parent map.
121    */

122    public int entryCount () {
123       return entries.size();
124    }
125
126 }
127
128 /* End of PEParentMap.java */
129
Popular Tags