@Test public void when_extracting_from_stream_with_multiple_addresses__then_latest_correct_state_is_returned_for_each() { List<Particle> particles = new ArrayList<>(); ValidatorRegistrationState currentState1 = populateStateChanges(ADDRESS_1, 5, particles); ValidatorRegistrationState currentState2 = populateStateChanges(ADDRESS_2, 6, particles); ValidatorRegistrationState extractedState1 = ValidatorRegistrationState.from(particles.stream(), ADDRESS_1); assertThat(extractedState1).isEqualTo(currentState1); ValidatorRegistrationState extractedState2 = ValidatorRegistrationState.from(particles.stream(), ADDRESS_2); assertThat(extractedState2).isEqualTo(currentState2); }
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();  }