Skip to content

Commit

Permalink
refactor: move missing measure to metadata package so clients can use it
Browse files Browse the repository at this point in the history
  • Loading branch information
metacosm committed May 23, 2024
1 parent dd8d752 commit ac6daab
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@
* @param tick the ordinal tick associated with this measure
*/
public record SensorMeasure(double[] components, long tick) {
/**
* Represents an invalid or somehow missed measure.
*/
public static final SensorMeasure missing = new SensorMeasure(new double[] { -1.0 }, -1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class MapMeasures implements Measures {
@Override
public RegisteredPID register(long pid) {
final var key = new RegisteredPID(pid);
measures.put(key, missing);
measures.put(key, SensorMeasure.missing);
return key;
}

Expand All @@ -38,6 +38,6 @@ public void record(RegisteredPID pid, SensorMeasure sensorMeasure) {

@Override
public SensorMeasure getOrDefault(RegisteredPID pid) {
return measures.getOrDefault(pid, missing);
return measures.getOrDefault(pid, SensorMeasure.missing);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
* A representation of ongoing {@link PowerSensor} measures.
*/
public interface Measures {
/**
* Represents an invalid or somehow missed measure.
*/
SensorMeasure missing = new SensorMeasure(new double[] { -1.0 }, -1);

/**
* Tracks the provided process identifier (pid) in the measures. For sensors that only provide system-wide measures, this
Expand Down Expand Up @@ -58,7 +54,8 @@ public interface Measures {
* Retrieves the last recorded {@link SensorMeasure} associated with the specified {@link RegisteredPID}
*
* @param pid the tracked process identifier which measure we want to retrieve
* @return the last recorded {@link SensorMeasure} associated with the specified process or {@link #missing} if it cannot be
* @return the last recorded {@link SensorMeasure} associated with the specified process or {@link SensorMeasure#missing} if
* it cannot be
* retrieved for any reason
*/
SensorMeasure getOrDefault(RegisteredPID pid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public void record(RegisteredPID pid, SensorMeasure sensorMeasure) {

@Override
public SensorMeasure getOrDefault(RegisteredPID pid) {
return trackedPIDs.contains(pid) && measure != null ? measure : Measures.missing;
return trackedPIDs.contains(pid) && measure != null ? measure : SensorMeasure.missing;
}
}

0 comments on commit ac6daab

Please sign in to comment.