Skip to content

Commit 3bf77a2

Browse files
docs: add JavaDocs for threading classes
1 parent 9e73de3 commit 3bf77a2

3 files changed

Lines changed: 119 additions & 10 deletions

File tree

src/main/java/de/hub/mse/variantsync/ecco/threading/ProductInitializationTask.java

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,58 @@
1515
import java.util.List;
1616
import java.util.concurrent.Callable;
1717

18+
/**
19+
* A Callable task for initializing a product with the given parameters.
20+
*
21+
* @param productNumber The number of the product to initialize.
22+
* @param productName The name of the product to initialize.
23+
* @param configPath The path to the configuration file for the product.
24+
* @param sourcePath The path to the source files for the product.
25+
* @param allFeatures The set of all features implemented by the product.
26+
* @param usedLanguage The primary language used in the product.
27+
* @return An InitResult object representing the result of the initialization
28+
* task.
29+
* @throws Exception If an error occurs during the initialization process.
30+
*/
1831
public class ProductInitializationTask implements Callable<ProductInitializationTask.InitResult> {
1932
private final int productNumber;
2033
private final String productName;
2134
private final File configPath;
2235
private final File sourcePath;
2336
private final EccoSet<Feature> allFeatures;
24-
private final ESupportedLanguages targetLanguage;
37+
private final ESupportedLanguages usedLanguage;
2538

26-
public ProductInitializationTask(final int productNumber, final ProductPassport passport, final ESupportedLanguages targetLanguage) {
39+
/**
40+
* Initializes a ProductInitializationTask with the given product number,
41+
* product passport, and target language.
42+
*
43+
* @param productNumber the product number to assign to the task
44+
* @param passport the product passport containing information about the
45+
* product
46+
* @param targetLanguage the target language for the task
47+
*/
48+
public ProductInitializationTask(final int productNumber, final ProductPassport passport,
49+
final ESupportedLanguages targetLanguage) {
2750
this.productNumber = productNumber;
2851
this.productName = passport.getName();
2952
this.configPath = passport.getConfiguration().toFile();
3053
this.sourcePath = passport.getSourcesRoot().toFile();
3154
this.allFeatures = new EccoSet<>();
32-
this.targetLanguage = targetLanguage;
55+
this.usedLanguage = targetLanguage;
3356
}
3457

58+
/**
59+
* Parses the sources and creates an InitResult with the created product.
60+
*
61+
* This method reads a configuration file specified by the configPath parameter,
62+
* parses the features listed in the file,
63+
* creates a product AST based on the target language specified, and returns an
64+
* InitResult object containing the parsed information.
65+
*
66+
* @return InitResult - an object containing the parsed information
67+
* @throws Exception - if an error occurs during parsing or creating the
68+
* InitResult object
69+
*/
3570
@Override
3671
public InitResult call() throws Exception {
3772
Logger.info("Parsing variant " + productNumber + "...");
@@ -52,7 +87,7 @@ public InitResult call() throws Exception {
5287
}
5388
final AbstractAST productAst;
5489
try {
55-
switch (targetLanguage) {
90+
switch (usedLanguage) {
5691
case C:
5792
productAst = new CAST(sourcePath);
5893
break;
@@ -63,20 +98,45 @@ public InitResult call() throws Exception {
6398
productAst = new LineAST(sourcePath);
6499
break;
65100
default:
66-
throw new IllegalStateException("Unexpected value: " + targetLanguage);
101+
throw new IllegalStateException("Unexpected value: " + usedLanguage);
67102
}
68103
} catch (final Exception e) {
69104
throw new RuntimeException("Was not able to parse " + sourcePath, e);
70105
}
71106

72-
return new InitResult(productNumber, allFeatures, new Product(productName, new EccoSet<>(), productAst, productFeatures));
107+
return new InitResult(productNumber, allFeatures,
108+
new Product(productName, new EccoSet<>(), productAst, productFeatures));
73109
}
74110

111+
/**
112+
* Represents the result of initializing a product.
113+
* Contains the ID of the initialization, a set of all features, and the product
114+
* associated with the initialization.
115+
*/
75116
public static class InitResult {
117+
/**
118+
* The ID of the initialization.
119+
*/
76120
public final int id;
121+
122+
/**
123+
* A set of all features associated with the initialization.
124+
*/
77125
public final EccoSet<Feature> allFeatures;
126+
127+
/**
128+
* The product associated with the initialization.
129+
*/
78130
public final Product product;
79131

132+
/**
133+
* Constructs a new InitResult with the specified ID, set of all features, and
134+
* product.
135+
*
136+
* @param id The ID of the initialization.
137+
* @param allFeatures A set of all features associated with the initialization.
138+
* @param product The product associated with the initialization.
139+
*/
80140
public InitResult(final int id, final EccoSet<Feature> allFeatures, final Product product) {
81141
this.id = id;
82142
this.allFeatures = allFeatures;

src/main/java/de/hub/mse/variantsync/ecco/threading/ProductLoadTask.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,45 @@
1010
import java.nio.file.Path;
1111
import java.util.concurrent.Callable;
1212

13+
/**
14+
* A Callable task that loads a product from a given file path.
15+
* The task reads the product object from the file using ObjectInputStream and
16+
* returns a LoadResult object.
17+
*
18+
* @param productPath The file path of the product to load
19+
* @return LoadResult An object containing the loaded product ID and product
20+
* object
21+
* @throws UncheckedIOException If an IOException occurs while reading the file
22+
* @throws RuntimeException If the Product class is not found
23+
*/
1324
public class ProductLoadTask implements Callable<ProductLoadTask.LoadResult> {
1425
private static int processedCount = 0;
1526
private final Path productPath;
1627
private final int id;
1728

29+
/**
30+
* Constructs a ProductLoadTask with the given product file path.
31+
* Parses the product ID from the file name.
32+
*
33+
* @param productPath The file path of the product to load
34+
*/
1835
public ProductLoadTask(final Path productPath) {
1936
this.productPath = productPath;
20-
// Retrieve the products index in the product array from the file name
2137
this.id = Integer.parseInt(productPath.getFileName().toString().split("\\.")[0].split("-")[1]);
2238
}
2339

40+
/**
41+
* Loads the product from the file and returns a LoadResult object.
42+
*
43+
* @return LoadResult An object containing the loaded product ID and product
44+
* object
45+
* @throws UncheckedIOException If an IOException occurs while reading the file
46+
* @throws RuntimeException If the Product class is not found
47+
*/
2448
@Override
2549
public LoadResult call() throws Exception {
2650
try (final ObjectInputStream in = new ObjectInputStream(new FileInputStream(productPath.toFile()))) {
27-
synchronized (ProductLoadTask.class){
51+
synchronized (ProductLoadTask.class) {
2852
Logger.info("#" + processedCount + ": Loading product " + id + " from " + productPath);
2953
processedCount++;
3054
}
@@ -38,10 +62,17 @@ public LoadResult call() throws Exception {
3862
}
3963
}
4064

65+
/**
66+
* Resets the processed count to zero.
67+
*/
4168
public static void resetProcessedCount() {
4269
ProductLoadTask.processedCount = 0;
4370
}
4471

72+
/**
73+
* Represents the result of loading a product, containing the product ID and
74+
* product object.
75+
*/
4576
public static class LoadResult {
4677
public final int id;
4778
public final Product product;

src/main/java/de/hub/mse/variantsync/ecco/threading/ProductSaveTask.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,38 @@
1010
import java.nio.file.Files;
1111
import java.nio.file.Paths;
1212

13+
/**
14+
* A class representing a task to save a product to a file.
15+
* This class implements the Runnable interface to be executed as a thread.
16+
*/
1317
public class ProductSaveTask implements Runnable {
1418
private static int processedCount = 0;
1519
private final Product product;
1620
private final String folderName;
1721
private final int id;
1822

23+
/**
24+
* Constructor for ProductSaveTask.
25+
*
26+
* @param product The product to be saved.
27+
* @param folderName The name of the folder where the product will be saved.
28+
* @param id The unique identifier of the product.
29+
*/
1930
public ProductSaveTask(final Product product, final String folderName, final int id) {
2031
this.product = product;
2132
this.folderName = folderName;
2233
this.id = id;
2334
}
2435

25-
36+
/**
37+
* Saves the product to a file.
38+
* Creates directories if they do not exist and writes the product object to a
39+
* file.
40+
*/
2641
@Override
2742
public void run() {
2843
final String filePath = folderName + "/" + product.getName().replaceAll("Variant", "product-") + ".product";
29-
synchronized (ProductSaveTask.class){
44+
synchronized (ProductSaveTask.class) {
3045
Logger.info("#" + processedCount + ": Saving product " + id + " to " + filePath);
3146
processedCount++;
3247
}
@@ -44,6 +59,9 @@ public void run() {
4459
}
4560
}
4661

62+
/**
63+
* Reset the processed count to zero.
64+
*/
4765
public static void resetProcessedCount() {
4866
ProductSaveTask.processedCount = 0;
4967
}

0 commit comments

Comments
 (0)