/*
 * This file is part of ClassGraph.
 *
 * Author: Luke Hutchison
 *
 * Hosted at: https://github.com/classgraph/classgraph
 *
 * --
 *
 * The MIT License (MIT)
 *
 * Copyright (c) 2018 Luke Hutchison
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without
 * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial
 * portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
 * EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
 * OR OTHER DEALINGS IN THE SOFTWARE.
 */
package io.github.classgraph;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/** A list of {@link AnnotationParameterValue} objects. */
public class AnnotationParameterValueList extends ArrayList<AnnotationParameterValue> {
    AnnotationParameterValueList() {
        super();
    }

    AnnotationParameterValueList(final int sizeHint) {
        super(sizeHint);
    }

    AnnotationParameterValueList(final Collection<AnnotationParameterValue> AnnotationParameterValueCollection) {
        super(AnnotationParameterValueCollection);
    }

    static final AnnotationParameterValueList EMPTY_LIST = new AnnotationParameterValueList() {
        @Override
        public boolean add(final AnnotationParameterValue e) {
            throw new IllegalArgumentException("List is immutable");
        }

        @Override
        public void add(final int index, final AnnotationParameterValue element) {
            throw new IllegalArgumentException("List is immutable");
        }

        @Override
        public boolean remove(final Object o) {
            throw new IllegalArgumentException("List is immutable");
        }

        @Override
        public AnnotationParameterValue remove(final int index) {
            throw new IllegalArgumentException("List is immutable");
        }

        @Override
        public boolean addAll(final Collection<? extends AnnotationParameterValue> c) {
            throw new IllegalArgumentException("List is immutable");
        }

        @Override
        public boolean addAll(final int index, final Collection<? extends AnnotationParameterValue> c) {
            throw new IllegalArgumentException("List is immutable");
        }

        @Override
        public boolean removeAll(final Collection<?> c) {
            throw new IllegalArgumentException("List is immutable");
        }

        @Override
        public boolean retainAll(final Collection<?> c) {
            throw new IllegalArgumentException("List is immutable");
        }

        @Override
        public void clear() {
            throw new IllegalArgumentException("List is immutable");
        }

        @Override
        public AnnotationParameterValue set(final int index, final AnnotationParameterValue element) {
            throw new IllegalArgumentException("List is immutable");
        }
    };

    // -------------------------------------------------------------------------------------------------------------

    /**
     * @return The names of all {@link AnnotationParameterValue} objects in this list, by calling
     *         {@link AnnotationParameterValue#getName()} for each item in the list.
     */
    public List<String> getNames() {
        if (this.isEmpty()) {
            return Collections.<String> emptyList();
        } else {
            final List<String> classNames = new ArrayList<>(this.size());
            for (final AnnotationParameterValue apv : this) {
                classNames.add(apv.getName());
            }
            return classNames;
        }
    }

    /**
     * @return The string representations of all annotation parameter values in this list, by calling
     *         {@link AnnotationParameterValue#toString()} for each item in the list.
     */
    public List<String> getAsStrings() {
        if (this.isEmpty()) {
            return Collections.<String> emptyList();
        } else {
            final List<String> toStringVals = new ArrayList<>(this.size());
            for (final AnnotationParameterValue apv : this) {
                toStringVals.add(apv.toString());
            }
            return toStringVals;
        }
    }

    /**
     * @return This {@link AnnotationParameterValueList} as a map from annotation parameter name to
     *         {@link AnnotationParameterValue} object.
     */
    public Map<String, AnnotationParameterValue> asMap() {
        final Map<String, AnnotationParameterValue> annotationNameToAnnotationParameterValue = new HashMap<>();
        for (final AnnotationParameterValue apv : this) {
            annotationNameToAnnotationParameterValue.put(apv.getName(), apv);
        }
        return annotationNameToAnnotationParameterValue;
    }

    // -------------------------------------------------------------------------------------------------------------

    /**
     * @param parameterName
     *            The name of an annotation parameter.
     * @return true if this list contains an annotation parameter with the given name.
     */
    public boolean containsName(final String parameterName) {
        for (final AnnotationParameterValue apv : this) {
            if (apv.getName().equals(parameterName)) {
                return true;
            }
        }
        return false;
    }

    /**
     * @param parameterName
     *            The name of an annotation parameter.
     * @return The {@link AnnotationParameterValue} object in the list with the given name, or null if not found.
     */
    public AnnotationParameterValue get(final String parameterName) {
        for (final AnnotationParameterValue apv : this) {
            if (apv.getName().equals(parameterName)) {
                return apv;
            }
        }
        return null;
    }
}

@@ -6228,16 +6228,29 @@
 urn The 
+value of the 
 %7B@link A
@@ -6324,16 +6324,31 @@
  null if
+%0A     *        
  not fou
@@ -6374,32 +6374,14 @@
 lic 
-AnnotationParameterValue
+Object
  get
@@ -6550,16 +6550,27 @@
 turn apv
+.getValue()
 ;%0A      

Return `AnnotationParameterValue#getValue()` from `get(String)`