当前位置: 首页>>代码示例>>Java>>正文


Java Predicate类代码示例

本文整理汇总了Java中org.apache.edgent.function.Predicate的典型用法代码示例。如果您正苦于以下问题:Java Predicate类的具体用法?Java Predicate怎么用?Java Predicate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Predicate类属于org.apache.edgent.function包,在下文中一共展示了Predicate类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.apache.edgent.function.Predicate; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	GenericSensor sensor = new GenericSensor();
	DirectProvider dp = new DirectProvider();
	Topology topology = dp.newTopology();
	TStream<String> tempReadings = topology.poll(sensor, 1, TimeUnit.MILLISECONDS);
	
	String condition = "@.d.temp>=60 || @.d.temp<=20";
	Predicate<String> p = new SamplePredicate(condition);
	// TStream<Double> filteredReadings = tempReadings.filter(reading -> reading <
	// 50 || reading > 80);
	TStream<String> filteredReadings = tempReadings.filter(p);
	filteredReadings.print();
	dp.submit(topology);
}
 
开发者ID:osswangxining,项目名称:iot-edge-greengrass,代码行数:15,代码来源:TempSensorSampleApplication.java

示例2: traceTuplesFn

import org.apache.edgent.function.Predicate; //导入依赖的package包/类
private <T> Predicate<T> traceTuplesFn(String label) {
    return tuple -> true; // TODO make dynamic config; affected by "label" value
    // check label for match against csv or regex from props
}
 
开发者ID:osswangxining,项目名称:iot-edge-greengrass,代码行数:5,代码来源:ApplicationUtilities.java

示例3: onTrigger

import org.apache.edgent.function.Predicate; //导入依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
	// TODO Auto-generated method stub
	resultMap = new HashMap<String,String>();
	System.out.println("Started Nifi");
	FlowFile flowfile = session.get();
	String jsonDir = flowfile.getAttribute("sourceDir");
	String batchID = flowfile.getAttribute("batchID");

	// why are they being removed?
	//if(batchMap.containsKey(batchID)) {
	//	session.remove(flowfile);
	//	return;
	//}
	batchMap.put(batchID, 1);
	DirectProvider dp = new DirectProvider();
	
	Topology topology = dp.newTopology("Edgent Application");
	String objectClass = context.getProperty(OBJECT_CLASS).getValue();
       
	getLogger().info("Created Edgent Topology: "+topology.getName());
	TempSource source = new TempSource(jsonDir +"/out");
	
	TStream<Pair<String,String>> sourceStream = topology.source(source);
	TStream<Pair<String,String>> filteredStream = sourceStream.filter(new Predicate<Pair<String,String>>() {

		@Override
		public boolean test(Pair<String,String> map) {
			boolean isValid = false;
			String jsonString = map.getRight();
			JsonArray jsonArray = (new Gson()).fromJson(jsonString, JsonArray.class);
			for(int i=0;i<jsonArray.size();i++)
			{
				JsonObject jsonObject = jsonArray.get(i).getAsJsonObject();
				if(jsonObject.get("label").getAsString().equals(objectClass)) {
					isValid = true;
					break;
				}
			}
			return isValid;
			
		}
	});
	filteredStream.sink(tuple -> update(tuple));
	dp.submit(topology);
	System.out.println("Submitted Topology");

	// Why are we sleeping here?
	try {
		Thread.sleep(1000);
	} catch (InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
    System.out.println(resultMap.size());
    // To write the results back out ot flow file
    session.remove(flowfile);
    
    //for(Map.Entry<String, String> entry:resultMap.entrySet())
    
    if(resultMap.size()>0){
    	FlowFile flowFile = session.create();
    	flowFile = session.putAttribute(flowFile, "batchID", batchID);
    	// should imageID be a NULL string?
    	flowFile = session.putAttribute(flowFile, "imageID", "");
           flowFile = session.putAttribute(flowFile, "fromEdgent", "1");
    	session.transfer(flowFile,REL_SUCCESS);
    }
}
 
开发者ID:dream-lab,项目名称:echo,代码行数:70,代码来源:FilterImagesEdgent.java


注:本文中的org.apache.edgent.function.Predicate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。