Circuit { public Map<Wire, SpecificValue> signals() { Circuit that = this; return circuit.stream() .collect(toMap(Instruction::getWire, i -> i.getSignalCarrier().resolve(that).get())); } Circuit(String circuit); Optional<SpecificValue> signalOf(SignalCarrier signalCarrier); Map<Wire, SpecificValue> signals();  }
@Test public void should_read_two_instructions() { Circuit circuit = new Circuit( "123 -> x\n" + "456 -> y"); Map<Wire, SpecificValue> signals = circuit.signals(); assertThat(signals).containsExactly( entry(new Wire("x"), new SpecificValue(123)), entry(new Wire("y"), new SpecificValue(456))); }