TerminalBlock (Operation orig, Operation replacement) { int idx = ArrayUtil.indexOf(myOperations, orig); if(idx == -1) { throw new NoSuchElementException(orig.toString()); } Operation[] ops = myOperations.clone(); ops[idx] = replacement; return new TerminalBlock(ops, myVariable, myStatements); }