Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonIgnore;

public class SensorUnit {
public record SensorUnit(String symbol, SensorUnit base, double factor) {

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

public SensorUnit(String symbol, SensorUnit base, double factor) {
this.symbol = Objects.requireNonNull(symbol).trim();
Expand Down Expand Up @@ -97,15 +94,14 @@ public double conversionFactorTo(SensorUnit other) {
}
}

@JsonProperty("symbol")
public String symbol() {
return symbol;
}

@Override
@JsonIgnore
public SensorUnit base() {
return base;
}

@Override
@JsonIgnore
public double factor() {
return factor;
}
Expand Down