StreamEventBuilder { public StreamEventBuilder() { instance = new StreamEvent(); } StreamEventBuilder(); StreamEventBuilder schema(StreamDefinition streamDefinition); StreamEventBuilder streamId(String streamId); StreamEventBuilder attributes(Map<String, Object> data, StreamDefinition streamDefinition); StreamEventBuilder attributes(Map<String, Object> data); StreamEventBuilder attributes(Object... data); StreamEventBuilder timestamep(long timestamp); StreamEventBuilder metaVersion(String metaVersion); StreamEvent build(); StreamEventBuilder copyFrom(StreamEvent event);  }
@Test public void testStreamEventBuilder() { List<StreamColumn> streamColumns = new ArrayList<>(); streamColumns.add(new StreamColumn.Builder().name("name").type(StreamColumn.Type.STRING).build()); streamColumns.add(new StreamColumn.Builder().name("host").type(StreamColumn.Type.STRING).build()); streamColumns.add(new StreamColumn.Builder().name("flag").type(StreamColumn.Type.BOOL).build()); streamColumns.add(new StreamColumn.Builder().name("value").type(StreamColumn.Type.DOUBLE).build()); streamColumns.add(new StreamColumn.Builder().name("data").type(StreamColumn.Type.LONG).build()); streamColumns.add(new StreamColumn.Builder().name("salary").type(StreamColumn.Type.FLOAT).build()); streamColumns.add(new StreamColumn.Builder().name("object").type(StreamColumn.Type.OBJECT).build()); streamColumns.add(new StreamColumn.Builder().name("int").type(StreamColumn.Type.INT).build()); StreamDefinition streamDefinition = new StreamDefinition(); streamDefinition.setColumns(streamColumns); StreamEventBuilder streamEventBuilder = new StreamEventBuilder(); StreamEvent streamEvent = streamEventBuilder.schema(streamDefinition).streamId("streamId").metaVersion("metaVersion").timestamep(1478667686971l).build(); Assert.assertEquals("StreamEvent[stream=STREAMID,timestamp=2016-11-09 05:01:26,971,data=[],metaVersion=metaVersion]", streamEvent.toString()); Object[] data = new Object[]{"namevalue", "hostvalue", "1", 10.0, 1, -0.2, "{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}", 4}; streamEvent = streamEventBuilder.schema(streamDefinition).attributes(data).streamId("streamId").metaVersion("metaVersion").timestamep(1478667686971l).build(); Assert.assertEquals("StreamEvent[stream=STREAMID,timestamp=2016-11-09 05:01:26,971,data=[namevalue,hostvalue,1,10.0,1,-0.2,{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"},4],metaVersion=metaVersion]", streamEvent.toString()); Map<String, Object> mapdata = new HashMap<>(); mapdata.put("name", "namevalue"); mapdata.put("host", "hostvalue"); mapdata.put("flag", "1"); mapdata.put("value", 10.0); mapdata.put("data", 1); mapdata.put("salary", -0.2); mapdata.put("object", "{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"}"); mapdata.put("int", 4); StreamEvent streamEvent1 = streamEventBuilder.schema(streamDefinition).attributes(mapdata, streamDefinition).streamId("streamId").metaVersion("metaVersion").timestamep(1478667686971l).build(); Assert.assertEquals("StreamEvent[stream=STREAMID,timestamp=2016-11-09 05:01:26,971,data=[namevalue,hostvalue,1,10.0,1,-0.2,{\"name\":\"heap.COMMITTED\", \"Value\":\"175636480\"},4],metaVersion=metaVersion]", streamEvent.toString()); Assert.assertTrue(streamEvent1 == streamEvent); Assert.assertTrue(streamEvent1.equals(streamEvent)); Assert.assertTrue(streamEvent1.hashCode() == streamEvent.hashCode()); StreamEventBuilder streamEventBuilder1 = new StreamEventBuilder(); streamEvent1 = streamEventBuilder1.schema(streamDefinition).attributes(mapdata, streamDefinition).streamId("streamId").metaVersion("metaVersion").timestamep(1478667686971l).build(); Assert.assertFalse(streamEvent1 == streamEvent); Assert.assertTrue(streamEvent1.equals(streamEvent)); Assert.assertTrue(streamEvent1.hashCode() == streamEvent.hashCode()); }