T () { switch (myState) { case FINISHED: throw new IllegalStateException("Matching is already finished"); case NOT_MATCHED: myState = State.FINISHED; throw new NoSuchElementException("Requested key '" + myKey + "' is not matched"); case MATCHED: myState = State.FINISHED; return myValue; default: throw new IllegalStateException("'then'/'thenGet'/'or' call is expected"); } }