@Test public void shouldIncrement() { final FilteredBroadcastMessenger<TaggedTelemetryEvent> bus = new FilteredBroadcastMessenger<>(); final LapFlagDecoder<LapFlagDecodable> decoder = new LapFlagDecoder<>(bus); final int[] res = new int[1]; bus.addListener(LapUpdate.class, new BroadcastListener<LapUpdate>() { @Override public void receiveMessage(LapUpdate lapUpdate) { res[0] = lapUpdate.getLaps(); } }); assertEquals(0, res[0]); decoder.update(toggled); assertEquals(0, res[0]); decoder.update(untoggled); assertEquals(1, res[0]); decoder.update(untoggled); assertEquals(1, res[0]); decoder.update(toggled); assertEquals(2, res[0]); }
@Override public void update(T newPage) { if (prev == null) {prev = newPage; return;} final boolean prevState = prev.isLapToggled(); final boolean state = newPage.isLapToggled(); prev = newPage; if (state == prevState) return; laps += 1; bus.send(new LapUpdate(newPage,laps)); }
LapFlagDecoder implements Decoder<T> { @Override public void update(T newPage) { if (prev == null) {prev = newPage; return;} final boolean prevState = prev.isLapToggled(); final boolean state = newPage.isLapToggled(); prev = newPage; if (state == prevState) return; laps += 1; bus.send(new LapUpdate(newPage,laps)); } }
LapFlagDecoder implements Decoder<T> { @Override public void update(T newPage) { if (prev == null) {prev = newPage; return;} final boolean prevState = prev.isLapToggled(); final boolean state = newPage.isLapToggled(); prev = newPage; if (state == prevState) return; laps += 1; bus.send(new LapUpdate(newPage,laps)); } LapFlagDecoder(FilteredBroadcastMessenger<TaggedTelemetryEvent> bus); }
LapFlagDecoder implements Decoder<T> { @Override public void update(T newPage) { if (prev == null) {prev = newPage; return;} final boolean prevState = prev.isLapToggled(); final boolean state = newPage.isLapToggled(); prev = newPage; if (state == prevState) return; laps += 1; bus.send(new LapUpdate(newPage,laps)); } LapFlagDecoder(FilteredBroadcastMessenger<TaggedTelemetryEvent> bus); @Override void update(T newPage); @Override void invalidate(); @Override void reset(); }
LapFlagDecoder implements Decoder<T> { @Override public void update(T newPage) { if (prev == null) {prev = newPage; return;} final boolean prevState = prev.isLapToggled(); final boolean state = newPage.isLapToggled(); prev = newPage; if (state == prevState) return; laps += 1; bus.send(new LapUpdate(newPage,laps)); } LapFlagDecoder(FilteredBroadcastMessenger<TaggedTelemetryEvent> bus); @Override void update(T newPage); @Override void invalidate(); @Override void reset();  }