List<DfaInstructionState> (Set<Instruction> joinInstructions) { DfaInstructionState state = myQueue.remove(); final Instruction instruction = state.getInstruction(); myMap.remove(state); DfaInstructionState next = myQueue.peek(); if (next == null || next.compareTo(state) != 0) return Collections.singletonList(state); List<DfaMemoryState> memoryStates = new ArrayList<>(); memoryStates.add(state.getMemoryState()); while (!myQueue.isEmpty() && myQueue.peek().compareTo(state) == 0) { DfaInstructionState anotherInstructionState = myQueue.poll(); myMap.remove(anotherInstructionState); memoryStates.add(anotherInstructionState.getMemoryState()); } memoryStates = forceMerge(memoryStates); if (memoryStates.size() > 1 && joinInstructions.contains(instruction)) { squash(memoryStates); } return ContainerUtil.map(memoryStates, state1 -> new DfaInstructionState(instruction, state1)); }