@Test public void when_extracting_from_stream_with_single_address__then_latest_correct_state_is_returned() { int numStateChanges = 10; List<Particle> particles = new ArrayList<>(numStateChanges); ValidatorRegistrationState currentState = populateStateChanges(ADDRESS_1, numStateChanges, particles); ValidatorRegistrationState extractedState = ValidatorRegistrationState.from(particles.stream(), ADDRESS_1); assertThat(extractedState).isEqualTo(currentState); }
static ValidatorRegistrationState from(Stream<Particle> store, RadixAddress address) { Objects.requireNonNull(store, "store"); Objects.requireNonNull(address, "address"); return store .map(ValidatorRegistrationState::from) .filter(state -> state.getAddress().equals(address)) .max(Comparator.comparing(ValidatorRegistrationState::getNonce)) .orElseGet(() -> ValidatorRegistrationState.initial(address)); }
ValidatorRegistrationState { static ValidatorRegistrationState from(Stream<Particle> store, RadixAddress address) { Objects.requireNonNull(store, "store"); Objects.requireNonNull(address, "address"); return store .map(ValidatorRegistrationState::from) .filter(state -> state.getAddress().equals(address)) .max(Comparator.comparing(ValidatorRegistrationState::getNonce)) .orElseGet(() -> ValidatorRegistrationState.initial(address)); } }
ValidatorRegistrationState { static ValidatorRegistrationState from(Stream<Particle> store, RadixAddress address) { Objects.requireNonNull(store, "store"); Objects.requireNonNull(address, "address"); return store .map(ValidatorRegistrationState::from) .filter(state -> state.getAddress().equals(address)) .max(Comparator.comparing(ValidatorRegistrationState::getNonce)) .orElseGet(() -> ValidatorRegistrationState.initial(address)); } private  ValidatorRegistrationState(Particle particle, RadixAddress address, boolean registered, long nonce); }
ValidatorRegistrationState { static ValidatorRegistrationState from(Stream<Particle> store, RadixAddress address) { Objects.requireNonNull(store, "store"); Objects.requireNonNull(address, "address"); return store .map(ValidatorRegistrationState::from) .filter(state -> state.getAddress().equals(address)) .max(Comparator.comparing(ValidatorRegistrationState::getNonce)) .orElseGet(() -> ValidatorRegistrationState.initial(address)); } private  ValidatorRegistrationState(Particle particle, RadixAddress address, boolean registered, long nonce); @Override boolean equals(Object o); @Override int hashCode(); }
ValidatorRegistrationState { static ValidatorRegistrationState from(Stream<Particle> store, RadixAddress address) { Objects.requireNonNull(store, "store"); Objects.requireNonNull(address, "address"); return store .map(ValidatorRegistrationState::from) .filter(state -> state.getAddress().equals(address)) .max(Comparator.comparing(ValidatorRegistrationState::getNonce)) .orElseGet(() -> ValidatorRegistrationState.initial(address)); } private  ValidatorRegistrationState(Particle particle, RadixAddress address, boolean registered, long nonce); @Override boolean equals(Object o); @Override int hashCode();  }