1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.river.tool.classdepend;
19
20 import java.util.Collections;
21 import java.util.HashSet;
22 import java.util.Iterator;
23 import java.util.Set;
24
25
26
27
28
29
30 public class ClassDependencyRelationship {
31
32 private final Set dependants;
33 private final Set providers;
34 private final String fullyQualifiedClassName;
35 private final int hash;
36 private final boolean rootClass;
37
38 ClassDependencyRelationship (String fullyQualifiedClassName, boolean rootClass){
39 this.fullyQualifiedClassName = fullyQualifiedClassName;
40 hash = 59 * 7 + (this.fullyQualifiedClassName != null ? this.fullyQualifiedClassName.hashCode() : 0);
41 dependants = new HashSet();
42 providers = new HashSet();
43 this.rootClass = rootClass;
44 }
45
46 ClassDependencyRelationship (String fullyQualifiedClassName){
47 this(fullyQualifiedClassName, false);
48 }
49
50
51
52 private void addDependant(ClassDependencyRelationship dependant) {
53 synchronized (dependants) {
54 dependants.add(dependant);
55 }
56 }
57
58
59
60
61
62 public void addProvider(ClassDependencyRelationship provider) {
63 synchronized (providers){
64 providers.add(provider);
65 }
66 provider.addDependant(this);
67 }
68
69
70
71
72
73 public Set getDependants() {
74 Set deps = new HashSet();
75
76 synchronized (dependants){
77 deps.addAll(dependants);
78 }
79 return deps;
80 }
81
82
83
84
85
86 public Set getProviders() {
87 Set prov = new HashSet();
88
89 synchronized (providers){
90 prov.addAll(providers);
91 }
92 return prov;
93 }
94
95 public String toString(){
96 return fullyQualifiedClassName;
97 }
98
99 @Override
100 public int hashCode() {
101 return hash;
102 }
103
104 public boolean equals(Object o){
105 if ( o == null ) return false;
106 if (!(o instanceof ClassDependencyRelationship)) return false;
107 if (fullyQualifiedClassName.equals(
108 ((ClassDependencyRelationship)o).fullyQualifiedClassName))
109 return true;
110 return false;
111 }
112
113
114
115
116
117 public boolean isRootClass() {
118 return rootClass;
119 }
120 }