Skip to content

Commit

Permalink
Updated Qualifier and Factory
Browse files Browse the repository at this point in the history
  • Loading branch information
gr812b committed Dec 23, 2024
1 parent d206438 commit bc0bb2c
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public RestResponse<File> runAnalyzer(@BeanParam AnalyzerParams params) {

// TODO: Can't pass in null to createAnalyzer, this if statement feels redundant
if (params.getType() != null) {
Analyzer analyzer = analyzerFactory.createAnalyzer(params.getType());
Analyzer analyzer = analyzerFactory.getAnalyzer(params.getType());
try {
analyzer.analyze(params); // No need to pass params; it's injected
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mcmasterbaja.analyzer;

import com.mcmasterbaja.model.AnalyzerType;
import com.mcmasterbaja.model.AnalyzerParams;
import com.mcmasterbaja.model.AnalyzerType;
import com.opencsv.exceptions.CsvException;
import jakarta.enterprise.context.Dependent;
import jakarta.inject.Inject;
Expand All @@ -15,7 +15,7 @@
import org.jboss.logging.Logger;

@Dependent
@AnalyzerTypeQualifier(AnalyzerType.ACCEL_CURVE)
@AnalyzerQualifier(AnalyzerType.ACCEL_CURVE)
public class AccelCurveAnalyzer extends Analyzer {

@Inject Logger logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,38 @@

import com.mcmasterbaja.model.AnalyzerType;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Any;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
import java.util.EnumMap;
import java.util.Map;
import org.jboss.logging.Logger;

@ApplicationScoped
public class AnalyzerFactory {

@Inject Logger logger;

@Inject
@AnalyzerTypeQualifier(AnalyzerType.ACCEL_CURVE)
Analyzer accelCurveAnalyzer;

@Inject
@AnalyzerTypeQualifier(AnalyzerType.AVERAGE)
Analyzer averageAnalyzer;

@Inject
@AnalyzerTypeQualifier(AnalyzerType.CONSTANT_ADDER)
Analyzer constantAdderAnalyzer;
@Inject @Any Instance<Analyzer> analyzers;

@Inject
@AnalyzerTypeQualifier(AnalyzerType.CUBIC)
Analyzer cubicAnalyzer;
private Map<AnalyzerType, Analyzer> analyzerMap;

@Inject
@AnalyzerTypeQualifier(AnalyzerType.INTERPOLATER_PRO)
Analyzer interpolaterProAnalyzer;

@Inject
@AnalyzerTypeQualifier(AnalyzerType.LINEAR_MULTIPLY)
Analyzer linearMultiplyAnalyzer;

@Inject
@AnalyzerTypeQualifier(AnalyzerType.RDP_COMPRESSION)
Analyzer rdpCompressionAnalyzer;

@Inject
@AnalyzerTypeQualifier(AnalyzerType.ROLL_AVG)
Analyzer rollAvgAnalyzer;

@Inject
@AnalyzerTypeQualifier(AnalyzerType.SGOLAY)
Analyzer sgolayAnalyzer;

@Inject
@AnalyzerTypeQualifier(AnalyzerType.SPLIT)
Analyzer splitAnalyzer;
public void init() {
analyzerMap = new EnumMap<>(AnalyzerType.class);
for (Analyzer analyzer : analyzers) {
AnalyzerQualifier qualifier = analyzer.getClass().getAnnotation(AnalyzerQualifier.class);
if (qualifier != null) {
analyzerMap.put(qualifier.value(), analyzer);
}
}
}

public Analyzer createAnalyzer(AnalyzerType type) {
switch (type) {
case ACCEL_CURVE:
return accelCurveAnalyzer;
case AVERAGE:
return averageAnalyzer;
case CONSTANT_ADDER:
return constantAdderAnalyzer;
case CUBIC:
return cubicAnalyzer;
case INTERPOLATER_PRO:
return interpolaterProAnalyzer;
case LINEAR_MULTIPLY:
return linearMultiplyAnalyzer;
case RDP_COMPRESSION:
return rdpCompressionAnalyzer;
case ROLL_AVG:
return rollAvgAnalyzer;
case SGOLAY:
return sgolayAnalyzer;
case SPLIT:
return splitAnalyzer;
default:
throw new IllegalArgumentException("Invalid analyzer type");
public Analyzer getAnalyzer(AnalyzerType type) {
Analyzer analyzer = analyzerMap.get(type);
if (analyzer == null) {
logger.errorf("No Analyzer found for type: %s", type);
throw new IllegalArgumentException("No Analyzer found for type: " + type);
}
return analyzer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
@Qualifier
@Retention(RUNTIME)
@Target({TYPE, METHOD, FIELD, PARAMETER})
public @interface AnalyzerTypeQualifier {
public @interface AnalyzerQualifier {
AnalyzerType value();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mcmasterbaja.analyzer;

import com.mcmasterbaja.model.AnalyzerType;
import com.mcmasterbaja.model.AnalyzerParams;
import com.mcmasterbaja.model.AnalyzerType;
import com.opencsv.CSVReader;
import com.opencsv.ICSVWriter;
import com.opencsv.exceptions.CsvException;
Expand All @@ -12,7 +12,7 @@
import org.jboss.logging.Logger;

@Dependent
@AnalyzerTypeQualifier(AnalyzerType.AVERAGE)
@AnalyzerQualifier(AnalyzerType.AVERAGE)
public class AverageAnalyzer extends Analyzer {
// This class takes the average of a range of a column and returns it as a double
@Inject Logger logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mcmasterbaja.analyzer;

import com.mcmasterbaja.model.AnalyzerType;
import com.mcmasterbaja.model.AnalyzerParams;
import com.mcmasterbaja.model.AnalyzerType;
import com.opencsv.CSVReader;
import com.opencsv.ICSVWriter;
import com.opencsv.exceptions.CsvValidationException;
Expand All @@ -11,7 +11,7 @@
import org.jboss.logging.Logger;

@Dependent
@AnalyzerTypeQualifier(AnalyzerType.CONSTANT_ADDER)
@AnalyzerQualifier(AnalyzerType.CONSTANT_ADDER)
public class ConstantAdderAnalyzer extends Analyzer {
private double a;
private double b;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mcmasterbaja.analyzer;

import com.mcmasterbaja.model.AnalyzerType;
import com.mcmasterbaja.model.AnalyzerParams;
import com.mcmasterbaja.model.AnalyzerType;
import com.opencsv.CSVReader;
import com.opencsv.ICSVWriter;
import com.opencsv.exceptions.CsvValidationException;
Expand All @@ -11,7 +11,7 @@
import org.jboss.logging.Logger;

@Dependent
@AnalyzerTypeQualifier(AnalyzerType.CUBIC)
@AnalyzerQualifier(AnalyzerType.CUBIC)
public class CubicAnalyzer extends Analyzer {
// Form of y = ax^3 + bx^2 + cx + d
private double a;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mcmasterbaja.analyzer;

import com.mcmasterbaja.model.AnalyzerType;
import com.mcmasterbaja.model.AnalyzerParams;
import com.mcmasterbaja.model.AnalyzerType;
import com.opencsv.CSVReader;
import com.opencsv.ICSVWriter;
import com.opencsv.exceptions.CsvValidationException;
Expand All @@ -18,7 +18,7 @@
// file based on the timestamp

@Dependent
@AnalyzerTypeQualifier(AnalyzerType.INTERPOLATER_PRO)
@AnalyzerQualifier(AnalyzerType.INTERPOLATER_PRO)
public class InterpolaterProAnalyzer extends Analyzer {

@Inject Logger logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mcmasterbaja.analyzer;

import com.mcmasterbaja.model.AnalyzerType;
import com.mcmasterbaja.model.AnalyzerParams;
import com.mcmasterbaja.model.AnalyzerType;
import com.opencsv.CSVReader;
import com.opencsv.ICSVWriter;
import com.opencsv.exceptions.CsvException;
Expand All @@ -11,7 +11,7 @@
import org.jboss.logging.Logger;

@Dependent
@AnalyzerTypeQualifier(AnalyzerType.LINEAR_MULTIPLY)
@AnalyzerQualifier(AnalyzerType.LINEAR_MULTIPLY)
public class LinearMultiplyAnalyzer extends Analyzer {
private double m;
private double b;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mcmasterbaja.analyzer;

import com.mcmasterbaja.model.AnalyzerType;
import com.mcmasterbaja.model.AnalyzerParams;
import com.mcmasterbaja.model.AnalyzerType;
import com.opencsv.CSVReader;
import com.opencsv.ICSVWriter;
import com.opencsv.exceptions.CsvException;
Expand All @@ -13,7 +13,7 @@
import org.jboss.logging.Logger;

@Dependent
@AnalyzerTypeQualifier(AnalyzerType.RDP_COMPRESSION)
@AnalyzerQualifier(AnalyzerType.RDP_COMPRESSION)
public class RDPCompressionAnalyzer extends Analyzer {

// Epsilon is the maximum distance between a point and the line between the start and end points
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mcmasterbaja.analyzer;

import com.mcmasterbaja.model.AnalyzerType;
import com.mcmasterbaja.model.AnalyzerParams;
import com.mcmasterbaja.model.AnalyzerType;
import com.opencsv.CSVReader;
import com.opencsv.ICSVWriter;
import com.opencsv.exceptions.CsvException;
Expand All @@ -13,7 +13,7 @@
import org.jboss.logging.Logger;

@Dependent
@AnalyzerTypeQualifier(AnalyzerType.ROLL_AVG)
@AnalyzerQualifier(AnalyzerType.ROLL_AVG)
public class RollingAvgAnalyzer extends Analyzer {
private int windowSize;
@Inject Logger logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mcmasterbaja.analyzer;

import com.mcmasterbaja.model.AnalyzerType;
import com.mcmasterbaja.model.AnalyzerParams;
import com.mcmasterbaja.model.AnalyzerType;
import com.opencsv.CSVReader;
import com.opencsv.ICSVWriter;
import com.opencsv.exceptions.CsvException;
Expand All @@ -15,7 +15,7 @@
import org.jboss.logging.Logger;

@Dependent
@AnalyzerTypeQualifier(AnalyzerType.SGOLAY)
@AnalyzerQualifier(AnalyzerType.SGOLAY)
public class SGolayFilter extends Analyzer {
private int windowSize;
private int polynomialDegree;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mcmasterbaja.analyzer;

import com.mcmasterbaja.model.AnalyzerType;
import com.mcmasterbaja.model.AnalyzerParams;
import com.mcmasterbaja.model.AnalyzerType;
import com.opencsv.CSVReader;
import com.opencsv.ICSVWriter;
import com.opencsv.exceptions.CsvException;
Expand All @@ -11,7 +11,7 @@
import org.jboss.logging.Logger;

@Dependent
@AnalyzerTypeQualifier(AnalyzerType.SPLIT)
@AnalyzerQualifier(AnalyzerType.SPLIT)
public class SplitAnalyzer extends Analyzer {
private int start;
private int end;
Expand Down

0 comments on commit bc0bb2c

Please sign in to comment.