Skip to content

Commit aa5cb14

Browse files
committed
refactorings and commenting
1 parent bf829a8 commit aa5cb14

9 files changed

Lines changed: 279 additions & 305 deletions

File tree

src/main/java/org/variantsync/boosting/TraceBoosting.java

Lines changed: 230 additions & 256 deletions
Large diffs are not rendered by default.

src/main/java/org/variantsync/boosting/datastructure/MainTree.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.variantsync.boosting.parsing.AbstractAST;
55
import org.variantsync.boosting.position.ProductPosition;
66
import org.variantsync.boosting.position.UnspecifiedPosition;
7-
import org.variantsync.boosting.product.Product;
7+
import org.variantsync.boosting.product.Variant;
88

99
import org.logicng.formulas.Formula;
1010

@@ -36,19 +36,19 @@ public MainTree(final AbstractAST tree) {
3636
* main AST (main tree) and returns the set of all nodes
3737
* in the resulting main tree corresponding to the nodes of this AST.
3838
*
39-
* @param product The product containing the main tree to merge this AST into.
39+
* @param variant The product containing the main tree to merge this AST into.
4040
* @return The set of all nodes in the resulting main tree corresponding to the
4141
* nodes of this AST.
4242
*/
43-
public CustomHashSet<ASTNode> unite(final Product product) {
43+
public CustomHashSet<ASTNode> unite(final Variant variant) {
4444
final CustomHashSet<ASTNode> result = new CustomHashSet<>();
45-
uniteChildren(result, product.getProductAst().getRoot(), tree.getRoot(), product);
45+
uniteChildren(result, variant.getProductAst().getRoot(), tree.getRoot(), variant);
4646
tree.getAstNodes().addAll(result);
4747
return result;
4848
}
4949

5050
private void uniteChildren(final CustomHashSet<ASTNode> result, final ASTNode productNode, final ASTNode nodeMainTree,
51-
final Product product) {
51+
final Variant variant) {
5252
for (final ASTNode productChild : productNode.getChildren()) {
5353
Set<ProductPosition> productPositions = new HashSet<>();
5454

@@ -68,7 +68,7 @@ private void uniteChildren(final CustomHashSet<ASTNode> result, final ASTNode pr
6868
mainTreeEquivalent.setMapping(productChild.getMapping());
6969
}
7070
}
71-
uniteChildren(result, productChild, mainTreeEquivalent, product);
71+
uniteChildren(result, productChild, mainTreeEquivalent, variant);
7272
} else {
7373
// add a copy of the product child node to the main tree
7474
final ASTNode childToAdd = new ASTNode(nodeMainTree, productChild.getCode(),
@@ -79,9 +79,9 @@ private void uniteChildren(final CustomHashSet<ASTNode> result, final ASTNode pr
7979
positionMap.put(childToAdd, productPositions);
8080
// add the new node and all its children to the result (since they become
8181
// corresponding nodes of the main tree)
82-
addAllSubNodes(result, childToAdd, productChild.getChildren(), product);
82+
addAllSubNodes(result, childToAdd, productChild.getChildren(), variant);
8383
}
84-
productPositions.add(new ProductPosition(product, productChild.getStartPosition()));
84+
productPositions.add(new ProductPosition(variant, productChild.getStartPosition()));
8585
}
8686
}
8787

@@ -102,19 +102,19 @@ private ASTNode findSimilarDescendant(final ASTNode productNode, final ASTNode n
102102
}
103103

104104
private void addAllSubNodes(final CustomHashSet<ASTNode> result, final ASTNode mainTreeParent,
105-
final CustomHashSet<ASTNode> productChildren, final Product product) {
105+
final CustomHashSet<ASTNode> productChildren, final Variant variant) {
106106
for (final ASTNode child : productChildren) {
107107
final ASTNode childCopy = new ASTNode(mainTreeParent, child.getCode(), UnspecifiedPosition.INSTANCE,
108108
child.getType(), child.getMapping());
109109
mainTreeParent.addChild(childCopy);
110110
childCopy.setParent(mainTreeParent);
111111
result.add(childCopy);
112112
final Set<ProductPosition> productPositions = new HashSet<>();
113-
productPositions.add(new ProductPosition(product, child.getStartPosition()));
113+
productPositions.add(new ProductPosition(variant, child.getStartPosition()));
114114
positionMap.put(childCopy, productPositions);
115115

116-
productPositions.add(new ProductPosition(product, child.getStartPosition()));
117-
addAllSubNodes(result, childCopy, child.getChildren(), product);
116+
productPositions.add(new ProductPosition(variant, child.getStartPosition()));
117+
addAllSubNodes(result, childCopy, child.getChildren(), variant);
118118
}
119119
}
120120

src/main/java/org/variantsync/boosting/position/ProductPosition.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.variantsync.boosting.position;
22

3-
import org.variantsync.boosting.product.Product;
3+
import org.variantsync.boosting.product.Variant;
44

55
import java.io.Serializable;
66
import java.nio.file.Path;
@@ -10,17 +10,17 @@
1010
* Represents a mapping between a Product and a Position.
1111
*/
1212
public class ProductPosition implements Serializable {
13-
public final Product product;
13+
public final Variant variant;
1414
public final Position position;
1515

1616
/**
1717
* Constructs a new ProductPosition object with the given Product and Position.
1818
*
19-
* @param product The Product object to associate with this ProductPosition.
19+
* @param variant The Product object to associate with this ProductPosition.
2020
* @param position The Position object to associate with this ProductPosition.
2121
*/
22-
public ProductPosition(final Product product, final Position position) {
23-
this.product = product;
22+
public ProductPosition(final Variant variant, final Position position) {
23+
this.variant = variant;
2424
this.position = position;
2525
}
2626

@@ -37,7 +37,7 @@ public boolean equals(final Object o) {
3737
if (!(o instanceof ProductPosition))
3838
return false;
3939
final ProductPosition that = (ProductPosition) o;
40-
return Objects.equals(product, that.product) && Objects.equals(position, that.position);
40+
return Objects.equals(variant, that.variant) && Objects.equals(position, that.position);
4141
}
4242

4343
/**
@@ -47,7 +47,7 @@ public boolean equals(final Object o) {
4747
*/
4848
@Override
4949
public int hashCode() {
50-
return Objects.hash(product, position);
50+
return Objects.hash(variant, position);
5151
}
5252

5353
/**

src/main/java/org/variantsync/boosting/product/ProductLoadTask.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public LoadResult call() throws Exception {
4545
Logger.info("#" + processedCount + ": Loading product " + id + " from " + productPath);
4646
processedCount++;
4747
}
48-
return new LoadResult(id, (Product) in.readObject());
48+
return new LoadResult(id, (Variant) in.readObject());
4949
} catch (final IOException e) {
5050
Logger.error("Was not able to read file: ", e);
5151
throw new UncheckedIOException(e);
@@ -68,12 +68,12 @@ public static void resetProcessedCount() {
6868
*/
6969
public static class LoadResult {
7070
public final int id;
71-
public final Product product;
71+
public final Variant variant;
7272

73-
public LoadResult(final int id, final Product product) {
73+
public LoadResult(final int id, final Variant variant) {
7474
Logger.info("#" + id + ": Finished loading.");
7575
this.id = id;
76-
this.product = product;
76+
this.variant = variant;
7777
}
7878
}
7979
}

src/main/java/org/variantsync/boosting/product/ProductLoader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* It then creates a thread pool with the specified number of threads and
1818
* submits tasks to load products.
1919
*/
20-
public class ProductLoader implements Iterator<Product> {
20+
public class ProductLoader implements Iterator<Variant> {
2121
private final List<ProductLoadTask> remainingTasks;
2222
private final List<Future<ProductLoadTask.LoadResult>> futures;
2323
private final ExecutorService threadPool;
@@ -58,14 +58,14 @@ public boolean hasNext() {
5858
* @throws RuntimeException if an error occurs while loading the product
5959
*/
6060
@Override
61-
public Product next() {
61+
public Variant next() {
6262
if (!this.remainingTasks.isEmpty()) {
6363
futures.add(threadPool.submit(remainingTasks.remove(0)));
6464
} else {
6565
this.threadPool.shutdown();
6666
}
6767
try {
68-
return futures.remove(0).get().product;
68+
return futures.remove(0).get().variant;
6969
} catch (final InterruptedException | ExecutionException e) {
7070
throw new RuntimeException(e);
7171
}

src/main/java/org/variantsync/boosting/product/ProductSaveTask.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
*/
1616
public class ProductSaveTask implements Runnable {
1717
private static int processedCount = 0;
18-
private final Product product;
18+
private final Variant variant;
1919
private final String folderName;
2020
private final int id;
2121

2222
/**
2323
* Constructor for ProductSaveTask.
2424
*
25-
* @param product The product to be saved.
25+
* @param variant The product to be saved.
2626
* @param folderName The name of the folder where the product will be saved.
2727
* @param id The unique identifier of the product.
2828
*/
29-
public ProductSaveTask(final Product product, final String folderName, final int id) {
30-
this.product = product;
29+
public ProductSaveTask(final Variant variant, final String folderName, final int id) {
30+
this.variant = variant;
3131
this.folderName = folderName;
3232
this.id = id;
3333
}
@@ -39,7 +39,7 @@ public ProductSaveTask(final Product product, final String folderName, final int
3939
*/
4040
@Override
4141
public void run() {
42-
final String filePath = folderName + "/" + product.getName().replaceAll("Variant", "product-") + ".product";
42+
final String filePath = folderName + "/" + variant.getName().replaceAll("Variant", "product-") + ".product";
4343
synchronized (ProductSaveTask.class) {
4444
Logger.info("#" + processedCount + ": Saving product " + id + " to " + filePath);
4545
processedCount++;
@@ -51,7 +51,7 @@ public void run() {
5151
throw new UncheckedIOException(e);
5252
}
5353
try (final ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filePath))) {
54-
out.writeObject(product);
54+
out.writeObject(variant);
5555
} catch (final IOException e) {
5656
Logger.error("Was not able to write products to " + filePath, e);
5757
throw new UncheckedIOException(e);

src/main/java/org/variantsync/boosting/product/Product.java renamed to src/main/java/org/variantsync/boosting/product/Variant.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* It also stores the AST nodes of the main tree that correspond to the AST
2727
* nodes of the product AST.
2828
*/
29-
public class Product implements Serializable {
29+
public class Variant implements Serializable {
3030
private final CustomHashSet<Feature> features;
3131
private final String name;
3232
// the original product AST
@@ -43,7 +43,7 @@ public class Product implements Serializable {
4343
* @param productAST the abstract syntax tree for the product
4444
* @param features the set of features associated with the product
4545
*/
46-
public Product(final String name, final CustomHashSet<ASTNode> astNodesMainTree, final AbstractAST productAST,
46+
public Variant(final String name, final CustomHashSet<ASTNode> astNodesMainTree, final AbstractAST productAST,
4747
final CustomHashSet<Feature> features) {
4848
this.name = name;
4949
this.astNodesMainTree = astNodesMainTree;
@@ -59,7 +59,7 @@ public Product(final String name, final CustomHashSet<ASTNode> astNodesMainTree,
5959
* @throws UnsupportedOperationException if the productAST type is not JavaAST
6060
* or LineAST
6161
*/
62-
public Product(final Product other) {
62+
public Variant(final Variant other) {
6363
// Copy the name from the other Product object
6464
this.name = other.name;
6565

@@ -287,10 +287,10 @@ private static ASTNode copyNode(final ASTNode node) {
287287
public boolean equals(final Object o) {
288288
if (this == o)
289289
return true;
290-
if (!(o instanceof Product))
290+
if (!(o instanceof Variant))
291291
return false;
292-
final Product product = (Product) o;
293-
return features.equals(product.features);
292+
final Variant variant = (Variant) o;
293+
return features.equals(variant.features);
294294
}
295295

296296
@Override

src/main/java/org/variantsync/boosting/product/ProductInitializationTask.java renamed to src/main/java/org/variantsync/boosting/product/VariantInitTask.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* A Callable task for initializing a product with the given parameters.
2323
*
2424
*/
25-
public class ProductInitializationTask implements Callable<ProductInitializationTask.InitResult> {
25+
public class VariantInitTask implements Callable<VariantInitTask.InitResult> {
2626
private final int productNumber;
2727
private final String productName;
2828
private final File configPath;
@@ -39,8 +39,8 @@ public class ProductInitializationTask implements Callable<ProductInitialization
3939
* product
4040
* @param targetLanguage the target language for the task
4141
*/
42-
public ProductInitializationTask(final int productNumber, final ProductPassport passport,
43-
final ESupportedLanguages targetLanguage) {
42+
public VariantInitTask(final int productNumber, final VariantPassport passport,
43+
final ESupportedLanguages targetLanguage) {
4444
this.productNumber = productNumber;
4545
this.productName = passport.getName();
4646
this.configPath = passport.getConfiguration().toFile();
@@ -52,7 +52,7 @@ public ProductInitializationTask(final int productNumber, final ProductPassport
5252
/**
5353
* Parses the sources and creates an InitResult with the created product.
5454
*
55-
* This method reads a configuration file specified by the configPath parameter,
55+
* This method reads a feature configuration file specified by the configPath parameter,
5656
* parses the features listed in the file,
5757
* creates a product AST based on the target language specified, and returns an
5858
* InitResult object containing the parsed information.
@@ -99,7 +99,7 @@ public InitResult call() throws Exception {
9999
}
100100

101101
return new InitResult(productNumber, allFeatures,
102-
new Product(productName, new CustomHashSet<>(), productAst, productFeatures));
102+
new Variant(productName, new CustomHashSet<>(), productAst, productFeatures));
103103
}
104104

105105
/**
@@ -121,20 +121,20 @@ public static class InitResult {
121121
/**
122122
* The product associated with the initialization.
123123
*/
124-
public final Product product;
124+
public final Variant variant;
125125

126126
/**
127127
* Constructs a new InitResult with the specified ID, set of all features, and
128128
* product.
129129
*
130130
* @param id The ID of the initialization.
131131
* @param allFeatures A set of all features associated with the initialization.
132-
* @param product The product associated with the initialization.
132+
* @param variant The product associated with the initialization.
133133
*/
134-
public InitResult(final int id, final CustomHashSet<Feature> allFeatures, final Product product) {
134+
public InitResult(final int id, final CustomHashSet<Feature> allFeatures, final Variant variant) {
135135
this.id = id;
136136
this.allFeatures = allFeatures;
137-
this.product = product;
137+
this.variant = variant;
138138
}
139139
}
140140

src/main/java/org/variantsync/boosting/product/ProductPassport.java renamed to src/main/java/org/variantsync/boosting/product/VariantPassport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* The ProductPassport collects the information about the product name,
77
* sources root, and configuration path.
88
*/
9-
public class ProductPassport {
9+
public class VariantPassport {
1010
private final String name;
1111
private final Path sourcesRoot;
1212
private final Path configuration;
@@ -19,7 +19,7 @@ public class ProductPassport {
1919
* @param sourcesRoot the root path for the product sources
2020
* @param configuration the path to the product configuration
2121
*/
22-
public ProductPassport(final String name, final Path sourcesRoot, final Path configuration) {
22+
public VariantPassport(final String name, final Path sourcesRoot, final Path configuration) {
2323
this.name = name;
2424
this.sourcesRoot = sourcesRoot;
2525
this.configuration = configuration;

0 commit comments

Comments
 (0)