44
55import java .util .*;
66
7+ /**
8+ * Represents an association between modules and AST nodes.
9+ * An association consists of the following components:
10+ * - A set of AST nodes (astNodes) representing the code elements involved in
11+ * the association
12+ * - Three sets of modules (min, all, max) representing the minimum, all, and
13+ * maximum products in which the association appears
14+ * - A set of modules (not) representing the products in which the association
15+ * does not appear
16+ * - A boolean flag (isBasic) indicating whether the association appears in all
17+ * products
18+ * - A formula (mapping) representing the mapping between the modules and AST
19+ * nodes
20+ *
21+ * This class provides methods for accessing and modifying the components of the
22+ * association, such as:
23+ * - Getting and setting the AST nodes, modules, and mapping
24+ * - Removing specific AST nodes from the association
25+ * - Getting the smallest modules in the association based on their size
26+ * - Checking if the association is basic
27+ *
28+ * The equals and hashCode methods are overridden to ensure proper comparison of
29+ * association objects based on their components.
30+ */
731public class Association {
8- private EccoSet <EccoNode > astNodes ;
32+ private EccoSet <ASTNode > astNodes ;
933 private EccoSet <Module > min ;
1034 private EccoSet <Module > all ;
1135 private EccoSet <Module > max ;
@@ -14,8 +38,18 @@ public class Association {
1438 // isBasic tells whether the code of the association appears in all products
1539 private boolean isBasic ;
1640
41+ /**
42+ * Constructs a new Association with the specified sets of modules and AST
43+ * nodes.
44+ *
45+ * @param min the minimum set of modules
46+ * @param all the set of all modules
47+ * @param max the maximum set of modules
48+ * @param not the set of modules that are not in the association
49+ * @param astNodes the set of AST nodes associated with the modules
50+ */
1751 public Association (final EccoSet <Module > min , final EccoSet <Module > all , final EccoSet <Module > max ,
18- final EccoSet <Module > not , final EccoSet <EccoNode > astNodes ) {
52+ final EccoSet <Module > not , final EccoSet <ASTNode > astNodes ) {
1953 this .min = new EccoSet <>(min );
2054 this .all = new EccoSet <>(all );
2155 this .max = new EccoSet <>(max );
@@ -44,46 +78,110 @@ public int hashCode() {
4478 return Objects .hash (astNodes , min , all , max , not );
4579 }
4680
47- public EccoSet <EccoNode > getAstNodes () {
81+ /**
82+ * Returns the set of AST nodes contained in this EccoSet.
83+ *
84+ * @return EccoSet<EccoNode> - a set of EccoNode objects representing the AST
85+ * nodes
86+ */
87+ public EccoSet <ASTNode > getAstNodes () {
4888 return astNodes ;
4989 }
5090
51- public void removeNodes (final EccoSet <EccoNode > toRemove ) {
91+ /**
92+ * Removes the specified nodes from the current set of AST nodes.
93+ *
94+ * @param toRemove The set of nodes to be removed from the current set of AST
95+ * nodes.
96+ * @throws NullPointerException if the specified set of nodes to be removed is
97+ * null.
98+ */
99+ public void removeNodes (final EccoSet <ASTNode > toRemove ) {
100+ if (toRemove == null ) {
101+ throw new NullPointerException ("The specified set of nodes to be removed cannot be null." );
102+ }
103+
52104 astNodes = astNodes .without (toRemove );
53105 }
54106
107+ /**
108+ * Returns the feature mapping formula associated with this object.
109+ *
110+ * @return the mapping formula
111+ */
55112 public Formula getMapping () {
56113 return mapping ;
57114 }
58115
116+ /**
117+ * Sets the feature mapping for the association.
118+ *
119+ * @param mapping the formula to set as the mapping
120+ */
59121 public void setMapping (final Formula mapping ) {
60122 this .mapping = mapping ;
61123 }
62124
125+ /**
126+ * Returns the set of min modules.
127+ *
128+ * @return the min modules
129+ */
63130 public EccoSet <Module > getMin () {
64131 return min ;
65132 }
66133
134+ /**
135+ * Returns the set off all modules.
136+ *
137+ * @return the all modules
138+ */
67139 public EccoSet <Module > getAll () {
68140 return all ;
69141 }
70142
143+ /**
144+ * Returns the set of max module.
145+ *
146+ * @return the max modules
147+ */
71148 public EccoSet <Module > getMax () {
72149 return max ;
73150 }
74151
152+ /**
153+ * Returns the set of not modules.
154+ *
155+ * @return the not modules
156+ */
75157 public EccoSet <Module > getNot () {
76158 return not ;
77159 }
78160
161+ /**
162+ * Returns a list of the smallest min modules.
163+ *
164+ * @return List<Module> The list of smallest min modules
165+ */
79166 public List <Module > getSmallestMinModules () {
80167 return getSmallestModules (this .min );
81168 }
82169
170+ /**
171+ * Returns a list of the smallest max modules.
172+ *
173+ * @return List<Module> The list of smallest max modules
174+ */
83175 public List <Module > getSmallestMaxModules () {
84176 return getSmallestModules (this .max );
85177 }
86178
179+ /**
180+ * Returns a list of the smallest modules from the given EccoSet of modules.
181+ *
182+ * @param modules the EccoSet of modules to search for the smallest ones
183+ * @return a list of the smallest modules from the given EccoSet
184+ */
87185 private List <Module > getSmallestModules (final EccoSet <Module > modules ) {
88186 final List <Module > result = new LinkedList <>();
89187 int size = Integer .MAX_VALUE ;
@@ -101,27 +199,55 @@ private List<Module> getSmallestModules(final EccoSet<Module> modules) {
101199 return result ;
102200 }
103201
202+ /**
203+ * Sets the min modules.
204+ *
205+ * @param min a set of min modules
206+ */
104207 public void setMin (final EccoSet <Module > min ) {
105208 this .min = min ;
106209 }
107210
211+ /**
212+ * Sets the all modules.
213+ *
214+ * @param all a set of all modules
215+ */
108216 public void setAll (final EccoSet <Module > all ) {
109217 this .all = all ;
110218 }
111219
220+ /**
221+ * Sets the max modules.
222+ *
223+ * @param max a set of max modules
224+ */
112225 public void setMax (final EccoSet <Module > max ) {
113226 this .max = max ;
114227 }
115228
229+ /**
230+ * Sets the not modules.
231+ *
232+ * @param not a set of not modules
233+ */
116234 public void setNot (final EccoSet <Module > not ) {
117235 this .not = not ;
118236 }
119237
238+ /**
239+ * Define this association as tracking base code.
240+ */
120241 public void setBasic (final Boolean basicCode ) {
121242 this .isBasic = basicCode ;
122243 }
123244
245+ /**
246+ * Returns whether the association tracks base code.
247+ *
248+ */
124249 public boolean isBasic () {
125250 return isBasic ;
126251 }
252+
127253}
0 commit comments