api/maven-api-xml/src/main/java/org/apache/maven/api/xml/ImmutableCollections.java [125:487]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    @SuppressWarnings("unchecked")
    static <K, V> Map<K, V> emptyMap() {
        return (Map<K, V>) EMPTY_MAP;
    }

    static <K, V> Map<K, V> singletonMap(K key, V value) {
        return new Map1<>(key, value);
    }

    static Properties copy(Properties properties) {
        if (properties instanceof ROProperties) {
            return properties;
        }
        return new ROProperties(properties);
    }

    private static class List1<E> extends AbstractImmutableList<E> {
        private final E element;

        private List1(E element) {
            this.element = element;
        }

        @Override
        public E get(int index) {
            if (index == 0) {
                return element;
            }
            throw outOfBounds(index);
        }

        @Override
        public int size() {
            return 1;
        }
    }

    private static class List2<E> extends AbstractImmutableList<E> {
        private final E element1;
        private final E element2;

        private List2(E element1, E element2) {
            this.element1 = element1;
            this.element2 = element2;
        }

        @Override
        public E get(int index) {
            if (index == 0) {
                return element1;
            } else if (index == 1) {
                return element2;
            }
            throw outOfBounds(index);
        }

        @Override
        public int size() {
            return 2;
        }
    }

    private static class ListN<E> extends AbstractImmutableList<E> {
        private final Object[] elements;

        private ListN(Collection<E> elements) {
            this.elements = elements.toArray();
        }

        @SuppressWarnings("unchecked")
        @Override
        public E get(int index) {
            return (E) elements[index];
        }

        @Override
        public int size() {
            return elements.length;
        }
    }

    private abstract static class AbstractImmutableList<E> extends AbstractList<E>
            implements RandomAccess, Serializable {
        @Override
        public boolean add(E e) {
            throw uoe();
        }

        @Override
        public boolean remove(Object o) {
            throw uoe();
        }

        @Override
        public boolean addAll(Collection<? extends E> c) {
            throw uoe();
        }

        @Override
        public boolean removeAll(Collection<?> c) {
            throw uoe();
        }

        @Override
        public boolean retainAll(Collection<?> c) {
            throw uoe();
        }

        @Override
        public void clear() {
            throw uoe();
        }

        @Override
        public boolean removeIf(Predicate<? super E> filter) {
            throw uoe();
        }

        @Override
        public void replaceAll(UnaryOperator<E> operator) {
            throw uoe();
        }

        @Override
        public void sort(Comparator<? super E> c) {
            throw uoe();
        }

        @Override
        public Iterator<E> iterator() {
            return new Itr(0);
        }

        @Override
        public ListIterator<E> listIterator() {
            return new Itr(0);
        }

        @Override
        public ListIterator<E> listIterator(int index) {
            if (index < 0 || index > size()) {
                throw outOfBounds(index);
            }
            return new Itr(index);
        }

        @Override
        public List<E> subList(int fromIndex, int toIndex) {
            if (fromIndex < 0) {
                throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
            }
            if (toIndex > size()) {
                throw new IndexOutOfBoundsException("toIndex = " + toIndex);
            }
            if (fromIndex > toIndex) {
                throw new IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")");
            }
            return new SubList(fromIndex, toIndex);
        }

        protected IndexOutOfBoundsException outOfBounds(int index) {
            return new IndexOutOfBoundsException("Index: " + index + ", Size: " + size());
        }

        private class SubList extends AbstractImmutableList<E> {
            private final int fromIndex;
            private final int toIndex;

            private SubList(int fromIndex, int toIndex) {
                this.fromIndex = fromIndex;
                this.toIndex = toIndex;
            }

            @Override
            public E get(int index) {
                if (index < 0 || index > size()) {
                    throw outOfBounds(index);
                }
                return AbstractImmutableList.this.get(fromIndex + index);
            }

            @Override
            public int size() {
                return toIndex - fromIndex;
            }
        }

        private class Itr implements ListIterator<E> {
            int index;

            private Itr(int index) {
                this.index = index;
            }

            @Override
            public boolean hasNext() {
                return index < size();
            }

            @Override
            public E next() {
                return get(index++);
            }

            @Override
            public boolean hasPrevious() {
                return index > 0;
            }

            @Override
            public E previous() {
                return get(--index);
            }

            @Override
            public int nextIndex() {
                return index;
            }

            @Override
            public int previousIndex() {
                return index - 1;
            }

            @Override
            public void remove() {
                throw uoe();
            }

            @Override
            public void set(E e) {
                throw uoe();
            }

            @Override
            public void add(E e) {
                throw uoe();
            }
        }
    }

    private static class ROProperties extends Properties {
        private ROProperties(Properties props) {
            super();
            if (props != null) {
                // Do not use super.putAll, as it may delegate to put which throws an UnsupportedOperationException
                for (Map.Entry<Object, Object> e : props.entrySet()) {
                    super.put(e.getKey(), e.getValue());
                }
            }
        }

        @Override
        public Object put(Object key, Object value) {
            throw uoe();
        }

        @Override
        public Object remove(Object key) {
            throw uoe();
        }

        @Override
        public void putAll(Map<?, ?> t) {
            throw uoe();
        }

        @Override
        public void clear() {
            throw uoe();
        }

        @Override
        public void replaceAll(BiFunction<? super Object, ? super Object, ?> function) {
            throw uoe();
        }

        @Override
        public Object putIfAbsent(Object key, Object value) {
            throw uoe();
        }

        @Override
        public boolean remove(Object key, Object value) {
            throw uoe();
        }

        @Override
        public boolean replace(Object key, Object oldValue, Object newValue) {
            throw uoe();
        }

        @Override
        public Object replace(Object key, Object value) {
            throw uoe();
        }

        @Override
        public Object computeIfAbsent(Object key, Function<? super Object, ?> mappingFunction) {
            throw uoe();
        }

        @Override
        public Object computeIfPresent(Object key, BiFunction<? super Object, ? super Object, ?> remappingFunction) {
            throw uoe();
        }

        @Override
        public Object compute(Object key, BiFunction<? super Object, ? super Object, ?> remappingFunction) {
            throw uoe();
        }

        @Override
        public Object merge(Object key, Object value, BiFunction<? super Object, ? super Object, ?> remappingFunction) {
            throw uoe();
        }
    }

    private static class Map1<K, V> extends AbstractImmutableMap<K, V> {
        private final Entry<K, V> entry;

        private Map1(K key, V value) {
            this.entry = new SimpleImmutableEntry<>(key, value);
        }

        @Override
        public Set<Entry<K, V>> entrySet() {
            return new AbstractImmutableSet<Entry<K, V>>() {
                @Override
                public Iterator<Entry<K, V>> iterator() {
                    return new Iterator<Entry<K, V>>() {
                        int index = 0;

                        @Override
                        public boolean hasNext() {
                            return index == 0;
                        }

                        @Override
                        public Entry<K, V> next() {
                            if (index++ == 0) {
                                return entry;
                            }
                            throw new NoSuchElementException();
                        }
                    };
                }

                @Override
                public int size() {
                    return 1;
                }
            };
        }
    }

    private static class MapN<K, V> extends AbstractImmutableMap<K, V> {
        private final Object[] entries;

        private MapN(Map<K, V> map) {
            if (map != null) {
                entries = new Object[map.size()];
                int idx = 0;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



src/mdo/java/ImmutableCollections.java [128:490]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    @SuppressWarnings("unchecked")
    static <K, V> Map<K, V> emptyMap() {
        return (Map<K, V>) EMPTY_MAP;
    }

    static <K, V> Map<K, V> singletonMap(K key, V value) {
        return new Map1<>(key, value);
    }

    static Properties copy(Properties properties) {
        if (properties instanceof ROProperties) {
            return properties;
        }
        return new ROProperties(properties);
    }

    private static class List1<E> extends AbstractImmutableList<E> {
        private final E element;

        private List1(E element) {
            this.element = element;
        }

        @Override
        public E get(int index) {
            if (index == 0) {
                return element;
            }
            throw outOfBounds(index);
        }

        @Override
        public int size() {
            return 1;
        }
    }

    private static class List2<E> extends AbstractImmutableList<E> {
        private final E element1;
        private final E element2;

        private List2(E element1, E element2) {
            this.element1 = element1;
            this.element2 = element2;
        }

        @Override
        public E get(int index) {
            if (index == 0) {
                return element1;
            } else if (index == 1) {
                return element2;
            }
            throw outOfBounds(index);
        }

        @Override
        public int size() {
            return 2;
        }
    }

    private static class ListN<E> extends AbstractImmutableList<E> {
        private final Object[] elements;

        private ListN(Collection<E> elements) {
            this.elements = elements.toArray();
        }

        @SuppressWarnings("unchecked")
        @Override
        public E get(int index) {
            return (E) elements[index];
        }

        @Override
        public int size() {
            return elements.length;
        }
    }

    private abstract static class AbstractImmutableList<E> extends AbstractList<E>
            implements RandomAccess, Serializable {
        @Override
        public boolean add(E e) {
            throw uoe();
        }

        @Override
        public boolean remove(Object o) {
            throw uoe();
        }

        @Override
        public boolean addAll(Collection<? extends E> c) {
            throw uoe();
        }

        @Override
        public boolean removeAll(Collection<?> c) {
            throw uoe();
        }

        @Override
        public boolean retainAll(Collection<?> c) {
            throw uoe();
        }

        @Override
        public void clear() {
            throw uoe();
        }

        @Override
        public boolean removeIf(Predicate<? super E> filter) {
            throw uoe();
        }

        @Override
        public void replaceAll(UnaryOperator<E> operator) {
            throw uoe();
        }

        @Override
        public void sort(Comparator<? super E> c) {
            throw uoe();
        }

        @Override
        public Iterator<E> iterator() {
            return new Itr(0);
        }

        @Override
        public ListIterator<E> listIterator() {
            return new Itr(0);
        }

        @Override
        public ListIterator<E> listIterator(int index) {
            if (index < 0 || index > size()) {
                throw outOfBounds(index);
            }
            return new Itr(index);
        }

        @Override
        public List<E> subList(int fromIndex, int toIndex) {
            if (fromIndex < 0) {
                throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
            }
            if (toIndex > size()) {
                throw new IndexOutOfBoundsException("toIndex = " + toIndex);
            }
            if (fromIndex > toIndex) {
                throw new IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")");
            }
            return new SubList(fromIndex, toIndex);
        }

        protected IndexOutOfBoundsException outOfBounds(int index) {
            return new IndexOutOfBoundsException("Index: " + index + ", Size: " + size());
        }

        private class SubList extends AbstractImmutableList<E> {
            private final int fromIndex;
            private final int toIndex;

            private SubList(int fromIndex, int toIndex) {
                this.fromIndex = fromIndex;
                this.toIndex = toIndex;
            }

            @Override
            public E get(int index) {
                if (index < 0 || index > size()) {
                    throw outOfBounds(index);
                }
                return AbstractImmutableList.this.get(fromIndex + index);
            }

            @Override
            public int size() {
                return toIndex - fromIndex;
            }
        }

        private class Itr implements ListIterator<E> {
            int index;

            private Itr(int index) {
                this.index = index;
            }

            @Override
            public boolean hasNext() {
                return index < size();
            }

            @Override
            public E next() {
                return get(index++);
            }

            @Override
            public boolean hasPrevious() {
                return index > 0;
            }

            @Override
            public E previous() {
                return get(--index);
            }

            @Override
            public int nextIndex() {
                return index;
            }

            @Override
            public int previousIndex() {
                return index - 1;
            }

            @Override
            public void remove() {
                throw uoe();
            }

            @Override
            public void set(E e) {
                throw uoe();
            }

            @Override
            public void add(E e) {
                throw uoe();
            }
        }
    }

    private static class ROProperties extends Properties {
        private ROProperties(Properties props) {
            super();
            if (props != null) {
                // Do not use super.putAll, as it may delegate to put which throws an UnsupportedOperationException
                for (Map.Entry<Object, Object> e : props.entrySet()) {
                    super.put(e.getKey(), e.getValue());
                }
            }
        }

        @Override
        public Object put(Object key, Object value) {
            throw uoe();
        }

        @Override
        public Object remove(Object key) {
            throw uoe();
        }

        @Override
        public void putAll(Map<?, ?> t) {
            throw uoe();
        }

        @Override
        public void clear() {
            throw uoe();
        }

        @Override
        public void replaceAll(BiFunction<? super Object, ? super Object, ?> function) {
            throw uoe();
        }

        @Override
        public Object putIfAbsent(Object key, Object value) {
            throw uoe();
        }

        @Override
        public boolean remove(Object key, Object value) {
            throw uoe();
        }

        @Override
        public boolean replace(Object key, Object oldValue, Object newValue) {
            throw uoe();
        }

        @Override
        public Object replace(Object key, Object value) {
            throw uoe();
        }

        @Override
        public Object computeIfAbsent(Object key, Function<? super Object, ?> mappingFunction) {
            throw uoe();
        }

        @Override
        public Object computeIfPresent(Object key, BiFunction<? super Object, ? super Object, ?> remappingFunction) {
            throw uoe();
        }

        @Override
        public Object compute(Object key, BiFunction<? super Object, ? super Object, ?> remappingFunction) {
            throw uoe();
        }

        @Override
        public Object merge(Object key, Object value, BiFunction<? super Object, ? super Object, ?> remappingFunction) {
            throw uoe();
        }
    }

    private static class Map1<K, V> extends AbstractImmutableMap<K, V> {
        private final Entry<K, V> entry;

        private Map1(K key, V value) {
            this.entry = new SimpleImmutableEntry<>(key, value);
        }

        @Override
        public Set<Entry<K, V>> entrySet() {
            return new AbstractImmutableSet<Entry<K, V>>() {
                @Override
                public Iterator<Entry<K, V>> iterator() {
                    return new Iterator<Entry<K, V>>() {
                        int index = 0;

                        @Override
                        public boolean hasNext() {
                            return index == 0;
                        }

                        @Override
                        public Entry<K, V> next() {
                            if (index++ == 0) {
                                return entry;
                            }
                            throw new NoSuchElementException();
                        }
                    };
                }

                @Override
                public int size() {
                    return 1;
                }
            };
        }
    }

    private static class MapN<K, V> extends AbstractImmutableMap<K, V> {
        private final Object[] entries;

        private MapN(Map<K, V> map) {
            if (map != null) {
                entries = new Object[map.size()];
                int idx = 0;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



