-
Notifications
You must be signed in to change notification settings - Fork 1
/
Converter.java
28 lines (23 loc) · 888 Bytes
/
Converter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.*;
import java.io.*;
public class Converter extends StandardFilter
{
protected HashMap<Integer, ConversionFunction> conversionFunction;
public Converter(PipedInputStream inputReadPort[], PipedOutputStream outputWritePort[], HashMap<Integer, ConversionFunction> IDsAndFuncs)
{
super(inputReadPort, outputWritePort, (new ArrayList<Integer>(IDsAndFuncs.keySet())).toArray(new Integer[]{}) );//, Arrays.asList(IDsAndFuncs.keySet()).toArray(new Integer[]{}));
conversionFunction = IDsAndFuncs;
}
public void processIDAndMeasurement(int id, double measurement)
{
ConversionFunction func = conversionFunction.get(id);
double result;
if(func == null)
result = measurement;
else
result = func.execute(measurement);
long longResult = Double.doubleToLongBits(result);
writeID(id, currentPort);
writeMeasurement(longResult, currentPort);
}
}