Skip to content

Commit 7d95562

Browse files
docs: add JavaDocs for remaining product-related classes
1 parent 81c5519 commit 7d95562

3 files changed

Lines changed: 143 additions & 6 deletions

File tree

src/main/java/de/hub/mse/variantsync/boosting/product/Product.java

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
import java.util.Objects;
1919
import java.util.stream.Collectors;
2020

21+
/**
22+
* Represents a product with features and an abstract syntax tree (AST).
23+
*
24+
* This class defines a product with a set of features and a product
25+
* AST.
26+
* It also stores the AST nodes of the main tree that correspond to the AST
27+
* nodes of the product AST.
28+
*/
2129
public class Product implements Serializable {
2230
private final EccoSet<Feature> features;
2331
private final String name;
@@ -27,6 +35,14 @@ public class Product implements Serializable {
2735
// product AST
2836
private EccoSet<ASTNode> astNodesMainTree;
2937

38+
/**
39+
* Constructs a new Product object with the given parameters.
40+
*
41+
* @param name the name of the product
42+
* @param astNodesMainTree the main tree of AST nodes for the product
43+
* @param productAST the abstract syntax tree for the product
44+
* @param features the set of features associated with the product
45+
*/
3046
public Product(final String name, final EccoSet<ASTNode> astNodesMainTree, final AbstractAST productAST,
3147
final EccoSet<Feature> features) {
3248
this.name = name;
@@ -35,52 +51,92 @@ public Product(final String name, final EccoSet<ASTNode> astNodesMainTree, final
3551
this.features = features;
3652
}
3753

54+
/**
55+
* Creates a new Product object by copying the contents of another Product
56+
* object.
57+
*
58+
* @param other The Product object to copy from
59+
* @throws UnsupportedOperationException if the productAST type is not JavaAST
60+
* or LineAST
61+
*/
3862
public Product(final Product other) {
63+
// Copy the name from the other Product object
3964
this.name = other.name;
65+
66+
// Create a new set of ASTNodes to copy from the other Product object
4067
final EccoSet<ASTNode> nodesToCopy = new EccoSet<>(other.astNodesMainTree);
4168
nodesToCopy.addAll(other.productAST.getAstNodes());
4269
nodesToCopy.add(other.productAST.getRoot());
70+
71+
// Create a mapping of original ASTNodes to copied ASTNodes
4372
final Map<ASTNode, ASTNode> originalToCopyMap = copyAstNodes(nodesToCopy);
4473

74+
// Copy the ASTNodes from the other Product object and update the main tree
4575
final EccoSet<ASTNode> astNodes = new EccoSet<>(
4676
other.astNodesMainTree
4777
.stream()
4878
.map(originalToCopyMap::get)
4979
.collect(Collectors.toCollection(EccoSet::new)));
5080
this.astNodesMainTree = new EccoSet<>(astNodes);
5181

82+
// Copy the ASTNodes from the other Product object and update the tree
5283
final EccoSet<ASTNode> treeNodes = new EccoSet<>(
5384
other.productAST.getAstNodes()
5485
.stream()
5586
.map(originalToCopyMap::get)
5687
.collect(Collectors.toCollection(EccoSet::new)));
88+
89+
// Create a new productAST object based on the type of the other Product
90+
// object's productAST
5791
if (other.productAST instanceof JavaAST) {
5892
final JavaAST ast = (JavaAST) other.productAST;
5993
this.productAST = new JavaAST(originalToCopyMap.get(ast.getRoot()), treeNodes);
6094
} else if (other.productAST instanceof LineAST) {
6195
final LineAST ast = (LineAST) other.productAST;
6296
this.productAST = new LineAST(originalToCopyMap.get(ast.getRoot()), treeNodes);
6397
} else {
64-
throw new UnsupportedOperationException();
98+
throw new UnsupportedOperationException("Unsupported productAST type");
6599
}
100+
101+
// Copy the features from the other Product object
66102
this.features = new EccoSet<>(other.getFeatures());
67103
}
68104

105+
/**
106+
* Clears the product Abstract Syntax Tree (AST) by setting it to null.
107+
*/
69108
public void forgetAST() {
70109
this.productAST = null;
71110
}
72111

112+
/**
113+
* Retrieves the set of features associated with the product.
114+
*
115+
* @return The set of features associated with the product.
116+
*/
73117
public EccoSet<Feature> getFeatures() {
74118
return features;
75119
}
76120

121+
/**
122+
* Returns the set of AST nodes in the main tree.
123+
*
124+
* @return EccoSet<ASTNode> - a set of AST nodes in the main tree
125+
*/
77126
public EccoSet<ASTNode> getAstNodesMainTree() {
78127
return astNodesMainTree;
79128
}
80129

81-
// returns the mapping of the node at given position in the product or (if it
82-
// was already merged into the main tree) the mapping of the corresponding node
83-
// in the main tree
130+
/**
131+
* Returns the mapping of the node at the given position in the product AST or,
132+
* if it has already been merged into the main tree, the mapping of the
133+
* corresponding
134+
* node in the main tree.
135+
*
136+
* @param position The position of the node to find the mapping for
137+
* @return The mapping of the node at the given position, or null if no node is
138+
* found
139+
*/
84140
public Formula getMappingFromPosition(final Position position) {
85141
// look for the right node in the product AST's nodes
86142
for (final ASTNode oldNode : productAST.getAstNodes()) {
@@ -97,12 +153,24 @@ public Formula getMappingFromPosition(final Position position) {
97153
return null;
98154
}
99155

156+
/**
157+
* Returns the name of the object.
158+
*
159+
* @return the name of the object as a String
160+
*/
100161
public String getName() {
101162
return name;
102163
}
103164

104-
// returns the node at given position in the product or (if it was already
105-
// merged into the main tree) the corresponding node in the main tree
165+
/**
166+
* Returns the ASTNode at the given position in the product AST or, if it has
167+
* already been merged into the main tree,
168+
* returns the corresponding node in the main tree.
169+
*
170+
* @param position The position to search for in the product AST.
171+
* @return The ASTNode at the given position in the product AST, or the
172+
* corresponding node in the main tree if merged.
173+
*/
106174
public ASTNode getNodeFromPosition(final Position position) {
107175
// look for the right node in the product AST's nodes
108176
for (final ASTNode oldNode : productAST.getAstNodes()) {
@@ -119,10 +187,20 @@ public ASTNode getNodeFromPosition(final Position position) {
119187
return null;
120188
}
121189

190+
/**
191+
* Returns the Abstract Syntax Tree (AST) representing the product.
192+
*
193+
* @return the AST representing the product
194+
*/
122195
public AbstractAST getProductAst() {
123196
return productAST;
124197
}
125198

199+
/**
200+
* Sets the AST nodes for the main tree.
201+
*
202+
* @param astNodesMainTree the AST nodes for the main tree
203+
*/
126204
public void setAstNodesMainTree(final EccoSet<ASTNode> astNodesMainTree) {
127205
this.astNodesMainTree = astNodesMainTree;
128206
}

src/main/java/de/hub/mse/variantsync/boosting/product/ProductLoader.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,32 @@
88
import java.util.concurrent.Executors;
99
import java.util.concurrent.Future;
1010

11+
/**
12+
* A class that implements an Iterator for loading products using multiple
13+
* threads.
14+
*
15+
* This class takes a list of ProductLoadTask objects and a number of threads to
16+
* use for loading the products.
17+
* It then creates a thread pool with the specified number of threads and
18+
* submits tasks to load products.
19+
*
20+
* @param loadTasks a list of ProductLoadTask objects representing the tasks to
21+
* load products
22+
* @param nThreads the number of threads to use for loading products
23+
*/
1124
public class ProductLoader implements Iterator<Product> {
1225
private final List<ProductLoadTask> remainingTasks;
1326
private final List<Future<ProductLoadTask.LoadResult>> futures;
1427
private final ExecutorService threadPool;
1528

29+
/**
30+
* Constructs a ProductLoader with the specified list of load tasks and number
31+
* of threads.
32+
*
33+
* @param loadTasks a list of ProductLoadTask objects representing the tasks to
34+
* load products
35+
* @param nThreads the number of threads to use for loading products
36+
*/
1637
public ProductLoader(final List<ProductLoadTask> loadTasks, final int nThreads) {
1738
this.remainingTasks = new LinkedList<>(loadTasks);
1839
this.threadPool = Executors.newFixedThreadPool(nThreads);
@@ -24,11 +45,22 @@ public ProductLoader(final List<ProductLoadTask> loadTasks, final int nThreads)
2445
}
2546
}
2647

48+
/**
49+
* Checks if there are more products to load.
50+
*
51+
* @return true if there are more products to load, false otherwise
52+
*/
2753
@Override
2854
public boolean hasNext() {
2955
return !futures.isEmpty();
3056
}
3157

58+
/**
59+
* Loads the next product using a thread from the thread pool.
60+
*
61+
* @return the next product to load
62+
* @throws RuntimeException if an error occurs while loading the product
63+
*/
3264
@Override
3365
public Product next() {
3466
if (!this.remainingTasks.isEmpty()) {

src/main/java/de/hub/mse/variantsync/boosting/product/ProductPassport.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,52 @@
22

33
import java.nio.file.Path;
44

5+
/**
6+
* Represents a product passport, containing information about the product name,
7+
* sources root, and configuration path.
8+
*/
59
public class ProductPassport {
610
private final String name;
711
private final Path sourcesRoot;
812
private final Path configuration;
913

14+
/**
15+
* Constructs a new ProductPassport with the given name, sources root, and
16+
* configuration path.
17+
*
18+
* @param name the name of the product
19+
* @param sourcesRoot the root path for the product sources
20+
* @param configuration the path to the product configuration
21+
*/
1022
public ProductPassport(final String name, final Path sourcesRoot, final Path configuration) {
1123
this.name = name;
1224
this.sourcesRoot = sourcesRoot;
1325
this.configuration = configuration;
1426
}
1527

28+
/**
29+
* Returns the root path for the product sources.
30+
*
31+
* @return the root path for the product sources
32+
*/
1633
public Path getSourcesRoot() {
1734
return sourcesRoot;
1835
}
1936

37+
/**
38+
* Returns the path to the product configuration.
39+
*
40+
* @return the path to the product configuration
41+
*/
2042
public Path getConfiguration() {
2143
return configuration;
2244
}
2345

46+
/**
47+
* Returns the name of the product.
48+
*
49+
* @return the name of the product
50+
*/
2451
public String getName() {
2552
return name;
2653
}

0 commit comments

Comments
 (0)