@VisibleForTesting
    static <V> List<Router<V>> routers(Iterable<V> values, Function<V, PathMapping> pathMappingResolver,
                                       BiConsumer<PathMapping, PathMapping> rejectionHandler) {
        rejectDuplicateMapping(values, pathMappingResolver, rejectionHandler);

        final ImmutableList.Builder<Router<V>> builder = ImmutableList.builder();
        final List<V> group = new ArrayList<>();

        boolean addingTrie = true;

        for (V value : values) {
            final PathMapping mapping = pathMappingResolver.apply(value);
            final boolean triePathPresent = mapping.triePath().isPresent();
            if (addingTrie && triePathPresent || !addingTrie && !triePathPresent) {
                // We are adding the same type of PathMapping to 'group'.
                group.add(value);
                continue;
            }

            // Changed the router type.
            if (!group.isEmpty()) {
                builder.add(router(addingTrie, group, pathMappingResolver));
            }
            addingTrie = !addingTrie;
            group.add(value);
        }
        if (!group.isEmpty()) {
            builder.add(router(addingTrie, group, pathMappingResolver));
        }
        return builder.build();
    }
@ VisibleForTesting static < V > List < Router < V > > routers ( Iterable < V > values , Function < V , PathMapping > pathMappingResolver , BiConsumer < PathMapping , PathMapping > rejectionHandler ) { rejectDuplicateMapping ( values , pathMappingResolver , rejectionHandler ) ; final ImmutableList . Builder < Router < V > > builder = ImmutableList . builder ( ) ; final List < V > group = new ArrayList < > ( ) ; boolean addingTrie = true ; for ( V value : values ) { final PathMapping mapping = pathMappingResolver . apply ( value ) ; final boolean triePathPresent = mapping . triePath ( ) . isPresent ( ) ; if ( addingTrie && triePathPresent || ! addingTrie && ! triePathPresent ) { group . add ( value ) ; continue ; } if ( ! group . isEmpty ( ) ) { builder . add ( router ( addingTrie , group , pathMappingResolver ) ) ; } addingTrie = ! addingTrie ; group . add ( value ) ; } if ( ! group . isEmpty ( ) ) { builder . add ( router ( addingTrie , group , pathMappingResolver ) ) ; } return builder . build ( ) ; }
Returns a list of {@link Router}s.