本文整理匯總了Java中org.apache.edgent.function.Function類的典型用法代碼示例。如果您正苦於以下問題:Java Function類的具體用法?Java Function怎麽用?Java Function使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Function類屬於org.apache.edgent.function包,在下文中一共展示了Function類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: newConsumer
import org.apache.edgent.function.Function; //導入依賴的package包/類
<T> Consumer<JsonObject> newConsumer(Class<T> datatype, Function<JsonObject,String> addressFn, Function<JsonObject,T> valueFn) {
PlcConnectionAdapter.checkDatatype(datatype);
return new Consumer<JsonObject>() {
private static final long serialVersionUID = 1L;
@Override
public void accept(JsonObject jo) {
PlcConnection connection = null;
Address address = null;
try {
connection = getConnection();
String addressStr = addressFn.apply(jo);
address = connection.parseAddress(addressStr);
T value = valueFn.apply(jo);
PlcWriter writer = connection.getWriter().get();
PlcWriteRequest writeReq = newPlcWriteRequest(address, value);
writer.write(writeReq).get();
}
catch (Exception e) {
logger.error("writing to plc device {} {} failed", connection, address, e);
}
}
};
}
示例2: testNewConsumer2Neg
import org.apache.edgent.function.Function; //導入依賴的package包/類
@Test
@Tag("fast")
public void testNewConsumer2Neg() throws Exception {
String addressStr = "MyReadWriteAddress/0";
MockAddress address = new MockAddress(addressStr);
PlcConnectionAdapter adapter = new PlcConnectionAdapter(getMockConnection());
MockConnection connection = (MockConnection) adapter.getConnection();
Consumer<JsonObject> consumer;
Function<JsonObject,String> addressFn = t -> t.get("address").getAsString();
consumer = adapter.newConsumer(String.class, addressFn, t -> t.get("value").getAsString());
checkConsumerJson(2, connection, address, consumer, "one", "two", "three");
adapter.close();
}
示例3: testNewConsumer2
import org.apache.edgent.function.Function; //導入依賴的package包/類
@Test
@Tag("fast")
public void testNewConsumer2() throws Exception {
String addressStr = "MyReadWriteAddress/0";
MockAddress address = new MockAddress(addressStr);
PlcConnectionAdapter adapter = new PlcConnectionAdapter(getMockConnection());
MockConnection connection = (MockConnection) adapter.getConnection();
Consumer<JsonObject> consumer;
Function<JsonObject,String> addressFn = t -> t.get("address").getAsString();
consumer = PlcFunctions.booleanConsumer(adapter, addressFn, t -> t.get("value").getAsBoolean());
PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, true, false);
consumer = PlcFunctions.byteConsumer(adapter, addressFn, t -> t.get("value").getAsByte());
PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, (byte)0x1, (byte)0x2, (byte)0x3);
consumer = PlcFunctions.shortConsumer(adapter, addressFn, t -> t.get("value").getAsShort());
PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, (short)1, (short)2, (short)3);
consumer = PlcFunctions.integerConsumer(adapter, addressFn, t -> t.get("value").getAsInt());
PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, 1000, 1001, 1002);
consumer = PlcFunctions.floatConsumer(adapter, addressFn, t -> t.get("value").getAsFloat());
PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, 1000.5f, 1001.5f, 1002.5f);
consumer = PlcFunctions.stringConsumer(adapter, addressFn, t -> t.get("value").getAsString());
PlcConnectionAdapterTest.checkConsumerJson(connection, address, consumer, "one", "two", "three");
adapter.close();
}
示例4: testNewConsumer2
import org.apache.edgent.function.Function; //導入依賴的package包/類
@Test
@Tag("fast")
public void testNewConsumer2() throws Exception {
String addressStr = "MyReadWriteAddress/0";
MockAddress address = new MockAddress(addressStr);
PlcConnectionAdapter adapter = new PlcConnectionAdapter(getMockConnection());
MockConnection connection = (MockConnection) adapter.getConnection();
Consumer<JsonObject> consumer;
Function<JsonObject,String> addressFn = t -> t.get("address").getAsString();
consumer = adapter.newConsumer(Boolean.class, addressFn, t -> t.get("value").getAsBoolean());
checkConsumerJson(connection, address, consumer, true, false);
consumer = adapter.newConsumer(Byte.class, addressFn, t -> t.get("value").getAsByte());
checkConsumerJson(connection, address, consumer, (byte)0x1, (byte)0x2, (byte)0x3);
consumer = adapter.newConsumer(Short.class, addressFn, t -> t.get("value").getAsShort());
checkConsumerJson(connection, address, consumer, (short)1, (short)2, (short)3);
consumer = adapter.newConsumer(Integer.class, addressFn, t -> t.get("value").getAsInt());
checkConsumerJson(connection, address, consumer, 1000, 1001, 1002);
consumer = adapter.newConsumer(Float.class, addressFn, t -> t.get("value").getAsFloat());
checkConsumerJson(connection, address, consumer, 1000.5f, 1001.5f, 1002.5f);
consumer = adapter.newConsumer(String.class, addressFn, t -> t.get("value").getAsString());
checkConsumerJson(connection, address, consumer, "one", "two", "three");
adapter.close();
}
示例5: byteConsumer
import org.apache.edgent.function.Function; //導入依賴的package包/類
public static Consumer<JsonObject> byteConsumer(PlcConnectionAdapter adapter, Function<JsonObject,String> addressFn, Function<JsonObject,Byte> valueFn) {
return adapter.newConsumer(Byte.class, addressFn, valueFn);
}
示例6: shortConsumer
import org.apache.edgent.function.Function; //導入依賴的package包/類
public static Consumer<JsonObject> shortConsumer(PlcConnectionAdapter adapter, Function<JsonObject,String> addressFn, Function<JsonObject,Short> valueFn) {
return adapter.newConsumer(Short.class, addressFn, valueFn);
}
示例7: integerConsumer
import org.apache.edgent.function.Function; //導入依賴的package包/類
public static Consumer<JsonObject> integerConsumer(PlcConnectionAdapter adapter, Function<JsonObject,String> addressFn, Function<JsonObject,Integer> valueFn) {
return adapter.newConsumer(Integer.class, addressFn, valueFn);
}
示例8: floatConsumer
import org.apache.edgent.function.Function; //導入依賴的package包/類
public static Consumer<JsonObject> floatConsumer(PlcConnectionAdapter adapter, Function<JsonObject,String> addressFn, Function<JsonObject,Float> valueFn) {
return adapter.newConsumer(Float.class, addressFn, valueFn);
}
示例9: stringConsumer
import org.apache.edgent.function.Function; //導入依賴的package包/類
public static Consumer<JsonObject> stringConsumer(PlcConnectionAdapter adapter, Function<JsonObject,String> addressFn, Function<JsonObject,String> valueFn) {
return adapter.newConsumer(String.class, addressFn, valueFn);
}
示例10: calendarConsumer
import org.apache.edgent.function.Function; //導入依賴的package包/類
public static Consumer<JsonObject> calendarConsumer(PlcConnectionAdapter adapter, Function<JsonObject,String> addressFn, Function<JsonObject,Calendar> valueFn) {
return adapter.newConsumer(Calendar.class, addressFn, valueFn);
}
示例11: keyFn
import org.apache.edgent.function.Function; //導入依賴的package包/類
/**
* The partition key function for wrapped sensor samples.
* <p>
* The {@code KEY_ID} property is returned for the key.
* @return the function
*/
public static Function<JsonObject,String> keyFn() {
return sample -> sample.get(KEY_ID).getAsString();
}
示例12: booleanConsumer
import org.apache.edgent.function.Function; //導入依賴的package包/類
/**
* Create a new Edgent {@link Consumer} to write data to the
* plc device.
* <p>
* TODO: Is it premature to supply this?
* <p>
* Every call to the returned {@link Consumer#accept(Object)}
* <ul>
* <li>calls {@code addressFn} to get the device address string</li>
* <li>calls {@code valueFn} to get the {@code T} to write</li>
* <li>writes the value to the device address using the connection
* associated with the {@code PlcConnectionAdapter}.</li>
* </ul>
*
* @param adapter the @{link PlcConnectionAdapter}
* @param addressFn {@code Function} the returns a device {@code Address} from a {@code JsonObject}
* @param valueFn {@code Function} the returns a {@code Value} from a {@code JsonObject}
* @return the {@code Consumer<JsonObject>}
*
* @see org.apache.edgent.topology.TStream#sink(Consumer)
*/
public static Consumer<JsonObject> booleanConsumer(PlcConnectionAdapter adapter, Function<JsonObject,String> addressFn, Function<JsonObject,Boolean> valueFn) {
return adapter.newConsumer(Boolean.class, addressFn, valueFn);
}