Skip to content
This repository was archived by the owner on Nov 15, 2019. It is now read-only.

Direct Measure

Alin Stefanescu edited this page Sep 7, 2017 · 2 revisions

Direct Measure API

A direct measure is used to collect data in physical world. This kind of measure can be executed on the platform on Client Side.

To defined a Direct Measure, implement the IDirectMeasure interface. This interface will be called by the MeasurePlatform to retrieve the measurements.


public interface IDirectMeasure {
  public List<IMeasurement> getMeasurement() throws Exception;
  public Map<String,String> getProperties();
}

  • getMeasurement(): calculates and returns a list of measurements.
  • getProperties(): provides a way for the Measure platform to communicate properties to DirectMeasure implementation.

To implement a direct measure, please extend the DirectMeasure class.

Direct Measure Example

RandomGenerator : A toy measure which returns a random number between MinRange and MaxRange value at each call.

public class RandomGenerator extends DirectMeasure {

	@Override
	public List<IMeasurement> getMeasurement() throws Exception {
		List<IMeasurement> result = new ArrayList<>();
		
                // Retrive Platform Properties by her name
		int maxRange =  Integer.valueOf(getProperty("MaxRange"));
		int minRange = Integer.valueOf(getProperty("MinRange"));

                // Collect Measure
		Random gen = new Random();
		int value = gen.nextInt(maxRange - minRange) + minRange;
		
                // Create Measurement :  In this case, a simple IntegerMeasurement
		IntegerMeasurement measurement = new IntegerMeasurement();
		measurement.setValue(value);		
		result.add(measurement);

		return result;
	}
}

Clone this wiki locally