Skip to content

Commit af2cc2a

Browse files
committed
refactor: convert to record, avoid serializing derived properties
1 parent 08371c5 commit af2cc2a

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

metadata/src/main/java/net/laprun/sustainability/power/SensorUnit.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import java.util.Objects;
77

88
import com.fasterxml.jackson.annotation.JsonCreator;
9-
import com.fasterxml.jackson.annotation.JsonProperty;
9+
import com.fasterxml.jackson.annotation.JsonIgnore;
1010

11-
public class SensorUnit {
11+
public record SensorUnit(String symbol, SensorUnit base, double factor) {
1212

1313
/**
1414
* Note that for simplicity's sake, we're not supporting deca prefix since it would make the prefix identification logic
15-
* more complex and it's not a very used prefix. Might revisit as needed.
15+
* more complex, and it's not a very used prefix. Might revisit as needed.
1616
*/
1717
private final static Map<String, Double> prefixesToFactors = Map.of(
1818
"n", 1e-9,
@@ -31,9 +31,6 @@ public class SensorUnit {
3131
private final static Map<String, SensorUnit> knownUnits = new HashMap<>();
3232
public static final SensorUnit mW = SensorUnit.of("mW");
3333
public static final SensorUnit µJ = SensorUnit.of("µJ");
34-
private final String symbol;
35-
private final SensorUnit base;
36-
private final double factor;
3734

3835
public SensorUnit(String symbol, SensorUnit base, double factor) {
3936
this.symbol = Objects.requireNonNull(symbol).trim();
@@ -97,15 +94,14 @@ public double conversionFactorTo(SensorUnit other) {
9794
}
9895
}
9996

100-
@JsonProperty("symbol")
101-
public String symbol() {
102-
return symbol;
103-
}
104-
97+
@Override
98+
@JsonIgnore
10599
public SensorUnit base() {
106100
return base;
107101
}
108102

103+
@Override
104+
@JsonIgnore
109105
public double factor() {
110106
return factor;
111107
}

0 commit comments

Comments
 (0)