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


Java TupleBuilder类代码示例

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


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

示例1: toTuple

import org.springframework.tuple.TupleBuilder; //导入依赖的package包/类
public static Tuple toTuple(Tensor tensor) {
	ByteBuffer buffer = ByteBuffer.allocate(tensor.numBytes());
	tensor.writeTo(buffer);

	// Retrieve all bytes in the buffer
	buffer.clear();
	byte[] bytes = new byte[buffer.capacity()];

       buffer.get(bytes, 0, bytes.length);

	return TupleBuilder.tuple()
			.put(TF_DATA_TYPE, tensor.dataType().name())
			.put(TF_SHAPE, tensor.shape())
			.put(TF_VALUE, bytes)
			.build();
}
 
开发者ID:tzolov,项目名称:tensorflow-spring-cloud-stream-app-starters,代码行数:17,代码来源:TensorTupleConverter.java

示例2: toTuple

import org.springframework.tuple.TupleBuilder; //导入依赖的package包/类
public static Tuple toTuple(Tensor tensor) {
	ByteBuffer buffer = ByteBuffer.allocate(tensor.numBytes());
	tensor.writeTo(buffer);

	// Retrieve all bytes in the buffer
	buffer.clear();
	byte[] bytes = new byte[buffer.capacity()];

	buffer.get(bytes, 0, bytes.length);

	return TupleBuilder.tuple()
			.put(TF_DATA_TYPE, tensor.dataType().name())
			.put(TF_SHAPE, tensor.shape())
			.put(TF_VALUE, bytes)
			.build();
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:tensorflow,代码行数:17,代码来源:TensorTupleConverter.java

示例3: testInsertion

import org.springframework.tuple.TupleBuilder; //导入依赖的package包/类
@Test
public void testInsertion() {
	Tuple tupleA = TupleBuilder.tuple().of("a", "hello1", "b", 42);
	Tuple tupleB = TupleBuilder.tuple().of("a", "hello2", "b", null);
	Tuple tupleC = TupleBuilder.tuple().of("a", "hello3");
	channels.input().send(MessageBuilder.withPayload(tupleA).build());
	channels.input().send(MessageBuilder.withPayload(tupleB).build());
	channels.input().send(MessageBuilder.withPayload(tupleC).build());
	Assert.assertThat(jdbcOperations.queryForObject(
			"select count(*) from messages where a = ? and b = ?",
			Integer.class, tupleA.getString("a"), tupleA.getInt("b")), is(1));
	Assert.assertThat(jdbcOperations.queryForObject(
			"select count(*) from messages where a = ? and b IS NULL",
			Integer.class, tupleB.getString("a")), is(1));
	Assert.assertThat(jdbcOperations.queryForObject(
			"select count(*) from messages where a = ? and b IS NULL",
			Integer.class, tupleC.getString("a")), is(1));
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:jdbc,代码行数:19,代码来源:JdbcSinkIntegrationTests.java

示例4: convertToMutable

import org.springframework.tuple.TupleBuilder; //导入依赖的package包/类
private MutableMessage<?> convertToMutable(Message<?> input) throws Exception{
    Object payload = input.getPayload();
    if (payload instanceof Tuple && !(payload instanceof MutableTuple)) {
            payload = TupleBuilder.mutableTuple().putAll((Tuple) payload).build();
    }
    else if (payload instanceof String){
		String strPayload = input.getPayload().toString();
		Iterator<Entry<String, Object>> objects = new ObjectMapper().readValue(strPayload, Map.class).entrySet().iterator();
		TupleBuilder tuples = TupleBuilder.mutableTuple();
		while (objects.hasNext()){
			Entry<String,Object> entry = objects.next();
			tuples.put(entry.getKey(), entry.getValue());
		}        	
		payload = tuples.build();
    }
    return new MutableMessage<>(payload, input.getHeaders());
}
 
开发者ID:melofred,项目名称:FraudDetection-Microservices,代码行数:18,代码来源:EnrichProcessor.java

示例5: testPojoTupleFieldName

import org.springframework.tuple.TupleBuilder; //导入依赖的package包/类
@Test
public void testPojoTupleFieldName() {
	TestPojoTuple testPojo = new TestPojoTuple();
	testPojo.setTest(TupleBuilder.tuple().of("test1", "Hi"));
	assertNotNull(this.sink.input());
	Message<TestPojoTuple> message1 = MessageBuilder.withPayload(testPojo).build();
	sink.input().send(message1);
	TestPojoTuple testPojo2 = new TestPojoTuple();
	testPojo2.setTest(TupleBuilder.tuple().of("test2", "Hello"));
	Message<TestPojoTuple> message2 = MessageBuilder.withPayload(testPojo2).build();
	sink.input().send(message2);
	TestPojoTuple testPojo3 = new TestPojoTuple();
	testPojo3.setTest(TupleBuilder.tuple().of("test1", "Hi"));
	Message<TestPojoTuple> message3 = MessageBuilder.withPayload(testPojo3).build();
	sink.input().send(message3);
	assertEquals(2, this.fieldValueCounterRepository.findOne(FVC_NAME).getFieldValueCounts().get("{\"test1\":\"Hi\"}").longValue());
	assertEquals(1, this.fieldValueCounterRepository.findOne(FVC_NAME).getFieldValueCounts().get("{\"test2\":\"Hello\"}").longValue());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:19,代码来源:FieldValueCounterSinkTests.java

示例6: testSendTuple

import org.springframework.tuple.TupleBuilder; //导入依赖的package包/类
@Test
public void testSendTuple() throws Exception {
	try (ConfigurableApplicationContext context = SpringApplication.run(
			SourceApplication.class, "--server.port=0",
			"--spring.jmx.enabled=false",
			"--spring.cloud.stream.bindings.output.contentType=application/x-spring-tuple")) {
		MessageCollector collector = context.getBean(MessageCollector.class);
		Source source = context.getBean(Source.class);
		Tuple tuple = TupleBuilder.tuple().of("foo","bar");
		source.output().send(MessageBuilder.withPayload(tuple).build());
		Message<byte[]> message = (Message<byte[]>) collector
				.forChannel(source.output()).poll(1, TimeUnit.SECONDS);
		assertThat(message.getHeaders().get(MessageHeaders.CONTENT_TYPE, MimeType.class)
				.includes(MessageConverterUtils.X_SPRING_TUPLE));
		assertThat(TupleBuilder.fromString(new String(message.getPayload()))).isEqualTo(tuple);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:18,代码来源:ContentTypeTests.java

示例7: testEvaluationIncorrectTupleInput

import org.springframework.tuple.TupleBuilder; //导入依赖的package包/类
@Test(expected = MessageHandlingException.class)
public void testEvaluationIncorrectTupleInput() {
	Tuple incompleteInputTuple = TupleBuilder.tuple()
			//	missing data type
			.put(TF_SHAPE, new long[0])
			.put(TF_VALUE, new byte[0])
			.build();
	testEvaluation(incompleteInputTuple);
}
 
开发者ID:tzolov,项目名称:tensorflow-spring-cloud-stream-app-starters,代码行数:10,代码来源:LinearRegressionTensorflowProcessorIntegrationTests.java

示例8: testEvaluationIncorrectTupleInput

import org.springframework.tuple.TupleBuilder; //导入依赖的package包/类
@Test(expected = MessageHandlingException.class)
public void testEvaluationIncorrectTupleInput() throws InterruptedException {
	Tuple incompleteInputTuple = TupleBuilder.tuple()
			//	missing data type
			.put(TF_SHAPE, new long[0])
			.put(TF_VALUE, new byte[0])
			.build();
	testEvaluation(incompleteInputTuple);
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:tensorflow,代码行数:10,代码来源:LinearRegressionTensorflowProcessorIntegrationTests.java

示例9: testTupleSerialization

import org.springframework.tuple.TupleBuilder; //导入依赖的package包/类
@Test
public void testTupleSerialization() {
	Tuple t = TupleBuilder.tuple().of("foo", "bar");
	byte[] bytes = serializer.serialize(t);

	Tuple obj = (Tuple) serializer.deserialize(bytes);
	assertEquals("bar", obj.getString("foo"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:9,代码来源:AbstractRedisSerializerTests.java

示例10: convertToMutable

import org.springframework.tuple.TupleBuilder; //导入依赖的package包/类
private MutableMessage<?> convertToMutable(Message<?> input) {
	Object payload = input.getPayload();
	if (payload instanceof Tuple && !(payload instanceof MutableTuple)) {
		payload = TupleBuilder.mutableTuple().putAll((Tuple) payload).build();
	}
	return new MutableMessage<>(payload, input.getHeaders());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:8,代码来源:PmmlProcessorConfiguration.java

示例11: convertFromInternal

import org.springframework.tuple.TupleBuilder; //导入依赖的package包/类
@Override
public Object convertFromInternal(Message<?> message, Class<?> targetClass, Object conversionHint) {
	String source;
	if (message.getPayload() instanceof byte[]) {
		source = new String((byte[]) message.getPayload(), Charset.forName("UTF-8"));
	}
	else {
		source = message.getPayload().toString();
	}
	return TupleBuilder.fromString(source);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:12,代码来源:TupleJsonMessageConverter.java

示例12: testInboundJsonTupleConversion

import org.springframework.tuple.TupleBuilder; //导入依赖的package包/类
@Test
public void testInboundJsonTupleConversion() throws Exception {
	testProcessor.input().send(MessageBuilder.withPayload("{'name':'foo'}")
			.build());
	@SuppressWarnings("unchecked")
	Message<String> received = (Message<String>) ((TestSupportBinder) binderFactory.getBinder(null, MessageChannel.class))
			.messageCollector().forChannel(testProcessor.output()).poll(1, TimeUnit.SECONDS);
	assertThat(received).isNotNull();

	assertThat(TupleBuilder.fromString(new String(received.getPayload()))).isEqualTo(TupleBuilder.tuple().of("name", "foo"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:12,代码来源:InboundJsonToTupleConversionTest.java

示例13: testEvaluation

import org.springframework.tuple.TupleBuilder; //导入依赖的package包/类
@Override
protected void testEvaluation(Object input) throws InterruptedException {

	Map<String, Object> inMap = new HashMap<>();
	inMap.put("Placeholder", input);

	Tuple inTuple = TupleBuilder.tuple().of("testTupleValue", inMap);
	Message<?> inputMessage = MessageBuilder
			.withPayload(inTuple)
			.build();

	channels.input().send(inputMessage);

	Message<?> outputMessage = messageCollector.forChannel(channels.output()).poll(10, TimeUnit.SECONDS);

	assertThat(((Tuple) outputMessage.getPayload()).getFloat("add"), equalTo(0.29999298f));

	assertThat((Tuple) inputMessage.getPayload(), equalTo(inTuple));
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:tensorflow,代码行数:20,代码来源:LinearRegressionTensorflowProcessorIntegrationTests.java

示例14: evaluate

import org.springframework.tuple.TupleBuilder; //导入依赖的package包/类
@ServiceActivator(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
public Object evaluate(Message<?> input) {

	Object inputData =
			this.properties.getExpression() == null
					? input.getPayload()
					: this.properties.getExpression().getValue(this.evaluationContext, input, Object.class);

	// The processorContext allows to convey metadata from the Input to Output converter.
	Map<String, Object> processorContext = new ConcurrentHashMap<>();

	Map<String, Object> inputDataMap = this.tensorflowInputConverter.convert(inputData, processorContext);

	Tensor outputTensor = this.tensorFlowService.evaluate(inputDataMap, this.properties.getModelFetch(),
			this.properties.getModelFetchIndex());

	Object outputData = tensorflowOutputConverter.convert(outputTensor, processorContext);

	switch (this.properties.getMode()) {

		case tuple:
			TupleBuilder outTupleBuilder = TupleBuilder.tuple().put(properties.getOutputName(), outputData);

			Object payload = input.getPayload();

			if (payload instanceof Tuple && ((Tuple) payload).hasFieldName(ORIGINAL_INPUT_DATA)) {
				// If the payload is already a tuple that contains ORIGINAL_INPUT_DATA entry then copy the
				// content of the input tuple in the new tuple to be returned.
				outTupleBuilder.putAll((Tuple) payload);
			}
			else {
				// This is a new tuple so preserve the input data.
				outTupleBuilder.put(ORIGINAL_INPUT_DATA, payload);
			}

			return outTupleBuilder.build();

		case header:
			return MessageBuilder
					.withPayload(input.getPayload())
					.setHeader(this.properties.getOutputName(), outputData);

		default:
			return outputData;
	}

}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:tensorflow,代码行数:48,代码来源:TensorflowCommonProcessorConfiguration.java

示例15: main

import org.springframework.tuple.TupleBuilder; //导入依赖的package包/类
public static void main(String[] args) {
	Tuple tuple = TupleBuilder.tuple().of("foo", "bar");
	System.out.println(tuple.getString(0));

	System.out.println(tuple.toString());
}
 
开发者ID:haogrgr,项目名称:haogrgr-test,代码行数:7,代码来源:SpringTupleMain.java


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