com.openxc.sinks.BaseVehicleDataSink Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openxc-it Show documentation
Show all versions of openxc-it Show documentation
Instrumentation test suite for OpenXC library
The newest version!
package com.openxc.sinks;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import com.openxc.remote.RawMeasurement;
/**
* A common parent class for all vehicle data sinks.
*
* Many sinks require a reference to last known value of all measurements. This
* class encapsulates the functionality require to store a reference to the
* measurements data structure and query it for values.
*/
public class BaseVehicleDataSink implements VehicleDataSink {
private Map mMeasurements =
new ConcurrentHashMap();
/**
* Receive a raw measurement, deserialized to primatives.
*
* Children of this class can call super.receive() if they need to store
* copies of received measurements to access via the get(String) method.
*/
public boolean receive(RawMeasurement measurement) throws DataSinkException {
mMeasurements.put(measurement.getName(), measurement);
return true;
}
public boolean containsMeasurement(String measurementId) {
return mMeasurements.containsKey(measurementId);
}
public RawMeasurement get(String measurementId) {
return mMeasurements.get(measurementId);
}
public Set> getMeasurements() {
return mMeasurements.entrySet();
}
public void stop() {
// do nothing unless you need it
}
}