CompareResult (@NotNull OperationChain left, @NotNull OperationChain right) { if (left.length() == 0 || right.length() == 0) { throw new IllegalStateException("chains can't be empty"); } int leftCurrentIdx = 0; int rightCurrentIdx = 0; while (leftCurrentIdx < left.length() && rightCurrentIdx < right.length()) { ChainOperation thisNext = left.myReverseOperations[leftCurrentIdx]; ChainOperation thatNext = right.myReverseOperations[leftCurrentIdx]; if (!lookSimilar(thisNext, thatNext)) { return CompareResult.NOT_EQUAL; } leftCurrentIdx++; rightCurrentIdx++; } if (leftCurrentIdx < left.length() && rightCurrentIdx == right.length()) { return CompareResult.LEFT_CONTAINS_RIGHT; } if (leftCurrentIdx == left.length() && rightCurrentIdx < right.length()) { return CompareResult.RIGHT_CONTAINS_LEFT; } return CompareResult.EQUAL; }