@Test public void fromEventTest() { String name = "TestName"; int count = 10; CountEventBuilder countEventBuilder = new CountEventBuilder(name, count); GobblinTrackingEvent event = countEventBuilder.build(); CountEventBuilder builderFromEvent = CountEventBuilder.fromEvent(event); Assert.assertEquals(CountEventBuilder.isCountEvent(event), true); Assert.assertNotNull(builderFromEvent); Assert.assertEquals(builderFromEvent.getName(), name); Assert.assertEquals(builderFromEvent.getCount(), count); event = new GobblinTrackingEvent(); countEventBuilder = CountEventBuilder.fromEvent(event); Assert.assertEquals(CountEventBuilder.isCountEvent(event), false); Assert.assertEquals(countEventBuilder, null); }
public static CountEventBuilder fromEvent(GobblinTrackingEvent event) { if(!isCountEvent(event)) { return null; } Map<String, String> metadata = event.getMetadata(); long count = Long.parseLong(metadata.getOrDefault(COUNT_KEY, "0")); CountEventBuilder countEventBuilder = new CountEventBuilder(event.getName(), event.getNamespace(), count); metadata.forEach((key, value) -> { switch (key) { case COUNT_KEY: break; default: countEventBuilder.addMetadata(key, value); break; } }); return countEventBuilder; }
CountEventBuilder extends GobblinEventBuilder { public static CountEventBuilder fromEvent(GobblinTrackingEvent event) { if(!isCountEvent(event)) { return null; } Map<String, String> metadata = event.getMetadata(); long count = Long.parseLong(metadata.getOrDefault(COUNT_KEY, "0")); CountEventBuilder countEventBuilder = new CountEventBuilder(event.getName(), event.getNamespace(), count); metadata.forEach((key, value) -> { switch (key) { case COUNT_KEY: break; default: countEventBuilder.addMetadata(key, value); break; } }); return countEventBuilder; } }
CountEventBuilder extends GobblinEventBuilder { public static CountEventBuilder fromEvent(GobblinTrackingEvent event) { if(!isCountEvent(event)) { return null; } Map<String, String> metadata = event.getMetadata(); long count = Long.parseLong(metadata.getOrDefault(COUNT_KEY, "0")); CountEventBuilder countEventBuilder = new CountEventBuilder(event.getName(), event.getNamespace(), count); metadata.forEach((key, value) -> { switch (key) { case COUNT_KEY: break; default: countEventBuilder.addMetadata(key, value); break; } }); return countEventBuilder; } CountEventBuilder(String name, long count);  CountEventBuilder(String name, String namespace, long count); }
CountEventBuilder extends GobblinEventBuilder { public static CountEventBuilder fromEvent(GobblinTrackingEvent event) { if(!isCountEvent(event)) { return null; } Map<String, String> metadata = event.getMetadata(); long count = Long.parseLong(metadata.getOrDefault(COUNT_KEY, "0")); CountEventBuilder countEventBuilder = new CountEventBuilder(event.getName(), event.getNamespace(), count); metadata.forEach((key, value) -> { switch (key) { case COUNT_KEY: break; default: countEventBuilder.addMetadata(key, value); break; } }); return countEventBuilder; } CountEventBuilder(String name, long count);  CountEventBuilder(String name, String namespace, long count); @Override GobblinTrackingEvent build(); static boolean isCountEvent(GobblinTrackingEvent event); static CountEventBuilder fromEvent(GobblinTrackingEvent event); }
CountEventBuilder extends GobblinEventBuilder { public static CountEventBuilder fromEvent(GobblinTrackingEvent event) { if(!isCountEvent(event)) { return null; } Map<String, String> metadata = event.getMetadata(); long count = Long.parseLong(metadata.getOrDefault(COUNT_KEY, "0")); CountEventBuilder countEventBuilder = new CountEventBuilder(event.getName(), event.getNamespace(), count); metadata.forEach((key, value) -> { switch (key) { case COUNT_KEY: break; default: countEventBuilder.addMetadata(key, value); break; } }); return countEventBuilder; } CountEventBuilder(String name, long count);  CountEventBuilder(String name, String namespace, long count); @Override GobblinTrackingEvent build(); static boolean isCountEvent(GobblinTrackingEvent event); static CountEventBuilder fromEvent(GobblinTrackingEvent event); static final String COUNT_EVENT_TYPE; static final String COUNT_KEY; }