/*
 * Copyright 2015 Michael Rozumyanskiy
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.michaelrocks.lightsaber.processor.annotations;

import org.apache.commons.lang3.Validate;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@ParametersAreNonnullByDefault
class AnnotationArrayParser extends AbstractAnnotationParser {
    private final List<Object> values = new ArrayList<>();

    public List<Object> getValues() {
        return Collections.unmodifiableList(values);
    }

    @Override
    protected void addValue(final String name, final Object value) {
    protected void addValue(@Nullable final String name, final Object value) {
        Validate.isTrue(name == null);
        values.add(value);
    }
}

/*
 * Copyright 2015 Michael Rozumyanskiy
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.michaelrocks.lightsaber.processor.annotations;

import org.apache.commons.lang3.Validate;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@ParametersAreNonnullByDefault
class AnnotationArrayParser extends AbstractAnnotationParser {
    @Nullable
    private List<Object> values;

    public List<Object> getValues() {
        return values == null ? Collections.emptyList() : Collections.unmodifiableList(values);
    }

    @Override
    protected void addValue(@Nullable final String name, final Object value) {
        Validate.isTrue(name == null);
        if (values == null) {
            values = new ArrayList<>();
        }
        values.add(value);
    }
}

Create a list lazily in AnnotationArrayParser