All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.eris.notnull.Configuration Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
/*
 * Copyright 2013-2016 Eris IT AB
 *
 * 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 se.eris.notnull;

import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Configuration {

    private final boolean implicit;
    @NotNull
    private final AnnotationConfiguration annotationConfiguration;
    @NotNull
    private final ExcludeConfiguration excludeConfiguration;

    @SuppressWarnings("BooleanParameter")
    public Configuration(
            final boolean implicit,
            @NotNull final AnnotationConfiguration annotationConfiguration,
            @NotNull final ExcludeConfiguration excludeConfiguration) {
        this.implicit = implicit;
        if (annotationConfiguration.isAnnotationsConfigured()) {
            this.annotationConfiguration = annotationConfiguration;
        } else {
            this.annotationConfiguration = new AnnotationConfiguration(getDefaultNotNull(), getDefaultNullable());
        }
        this.excludeConfiguration = excludeConfiguration;
    }

    @NotNull
    private Set getDefaultNotNull() {
        return new HashSet<>(Arrays.asList(
                org.jetbrains.annotations.NotNull.class.getName(),
                se.eris.notnull.NotNull.class.getName())
        );
    }

    @NotNull
    private Set getDefaultNullable() {
        return new HashSet<>(Arrays.asList(
                org.jetbrains.annotations.Nullable.class.getName(),
                se.eris.notnull.Nullable.class.getName())
        );
    }

    public boolean isImplicit() {
        return implicit;
    }

    @NotNull
    public Set getNotNullAnnotations() {
        return annotationConfiguration.getNotNull();
    }

    @NotNull
    public Set getNullableAnnotations() {
        return annotationConfiguration.getNullable();
    }

    public boolean isImplicitInstrumentation(final String className) {
        return implicit && excludeConfiguration.isClassImplicitInstrumentation(className);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy