public static Predicate[] acceptVisitor(Predicate[] predicates, Visitor visitor, IndexRegistry indexes) {
        Predicate[] target = predicates;
        boolean copyCreated = false;
        for (int i = 0; i < predicates.length; i++) {
            Predicate predicate = predicates[i];
            if (predicate instanceof VisitablePredicate visitablePredicate) {
                Predicate transformed = visitablePredicate.accept(visitor, indexes);
                if (transformed != predicate) {
                    if (!copyCreated) {
                        copyCreated = true;
                        target = createCopy(target);
                    }
                    target[i] = transformed;
                }
            }
        }
        return target;
    }
@Test
    public void acceptVisitor_whenThereIsNonVisitablePredicateAndNewArraysIsCreated_thenJustCopyTheNonVisitablePredicate() {
        Visitor mockVisitor = mock(Visitor.class);

        Predicate[] predicates = new Predicate[3];
        Predicate p1 = mock(Predicate.class);
        predicates[0] = p1;

        Predicate transformed = mock(Predicate.class);
        Predicate p2 = createMockVisitablePredicate(transformed);
        predicates[1] = p2;

        Predicate p3 = mock(Predicate.class);
        predicates[2] = p3;

        Predicate[] result = VisitorUtils.acceptVisitor(predicates, mockVisitor, mockIndexes);
        assertThat(result).isNotSameAs(predicates);
        assertThat(result).hasSize(3);
        assertThat(result).containsExactlyInAnyOrder(p1, transformed, p3);
    }