Java 为什么不是';过滤方法不起作用吗?
如中所示,我尝试过滤掉传感器读数,其中温度传感器的值必须在80到85华氏度之间 但当我尝试连接传感器时,读数为75华氏度,没有显示类似以下信息:温度超出范围 是不是过滤方法不起作用?如果是的话,请试着帮助我。谢谢 范围值设置为:Java 为什么不是';过滤方法不起作用吗?,java,apache,apache-edgent,Java,Apache,Apache Edgent,如中所示,我尝试过滤掉传感器读数,其中温度传感器的值必须在80到85华氏度之间 但当我尝试连接传感器时,读数为75华氏度,没有显示类似以下信息:温度超出范围 是不是过滤方法不起作用?如果是的话,请试着帮助我。谢谢 范围值设置为: static double OPTIMAL_TEMP_LOW = 80.0; static double OPTIMAL_TEMP_HIGH = 85.0; static Range<Double> optimalTempRange = Ranges.clo
static double OPTIMAL_TEMP_LOW = 80.0;
static double OPTIMAL_TEMP_HIGH = 85.0;
static Range<Double> optimalTempRange = Ranges.closed(OPTIMAL_TEMP_LOW, OPTIMAL_TEMP_HIGH);
过滤部分:
TStream<Double> simpleFiltered = temp.filter(tuple ->
tuple < OPTIMAL_TEMP_LOW || tuple > OPTIMAL_TEMP_HIGH);
simpleFiltered.sink(tuple -> System.out.println("Temperature is out of range! "
+ "It is " + tuple + "\u00b0F!"));
/*TStream<Double> simpleFiltered = temp.filter(tuple ->
!optimalTempRange.contains(tuple));
simpleFiltered.sink(tuple -> System.out.println("Temperature is out of range! "
+ "It is " + tuple + "\u00b0F!"));*/
// See what the temperatures look like
simpleFiltered.print();
dp.submit(top);
我认为发生这种情况是因为您的过滤器和接收器已分配给另一个TStream对象,而不是您正在打印的对象。
可能您需要尝试以下方法:
TempSensor ts = new TempSensor();
TStream<Double> temp = top.poll(ts, 1, TimeUnit.MILLISECONDS).filter(tuple ->
tuple < OPTIMAL_TEMP_LOW || tuple > OPTIMAL_TEMP_HIGH);
temp.sink(tuple -> System.out.println("Temperature is out of range! "
+ "It is " + tuple + "\u00b0F!"));
// See what the temperatures look like
temp.print();
dp.submit(top);
TempSensor ts=新的TempSensor();
TStream temp=top.poll(ts,1,TimeUnit.millides).过滤器(元组->
元组<最佳温度|低|元组>最佳温度|高);
温度接收器(元组->系统输出.println(“温度超出范围!”
+它是“+tuple+”\u00b0F!”);
//看看温度是什么样子
临时打印();
dp.提交(顶部);
嗯,您的代码与文档中的示例相匹配,但看起来好像我们正在创建一个过滤流,然后在temp.print()
中忽略它
您可以尝试将该行更改为
simplefilted.print()
使用“optimalTempRange”时发生了什么?(已被注释掉)@mangusta输出保持不变。请检查下面的答案并给出答案feedback@ArunSubba在任何情况下,您都可能同意打印过滤流而不是“temp”:)如何将过滤器重新分配给“temp”而不是“simplefilted”?temp=temp.filter(tuple->tupleTempSensor
类的get()
方法上,该类有一个,而循环不断打印接收到的数据lol:)
Selet a port:
1: ttyACM0 Port opened succesefully.
7373.40
73.40
73.40 ...
TempSensor ts = new TempSensor();
TStream<Double> temp = top.poll(ts, 1, TimeUnit.MILLISECONDS).filter(tuple ->
tuple < OPTIMAL_TEMP_LOW || tuple > OPTIMAL_TEMP_HIGH);
temp.sink(tuple -> System.out.println("Temperature is out of range! "
+ "It is " + tuple + "\u00b0F!"));
// See what the temperatures look like
temp.print();
dp.submit(top);