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

com.github.richardballard.arbeeutils.id.ByIdSpecifiers Maven / Gradle / Ivy

There is a newer version: 2.0
Show newest version
/*
 * (C) Copyright 2016 Richard Ballard.
 *
 * 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 com.github.richardballard.arbeeutils.id;


import com.google.common.collect.ImmutableSet;
import net.jcip.annotations.Immutable;
import org.jetbrains.annotations.NotNull;

/**
 * This class has static methods for obtaining the various flavours of {@link ByIdSpecifier}.
 */
@Immutable
public enum ByIdSpecifiers {
    ;

    private static final ByIdSpecifier EXCLUDE_NONE = new AllBasedByIdSpecifier<>(ImmutableSet.of());
    private static final ByIdSpecifier INCLUDE_NONE = new NoneBasedByIdSpecifier<>(ImmutableSet.of());


    /**
     * @return an instance that excludes nothing (i.e. includes everything)
     */
    @SuppressWarnings("unchecked")
    @NotNull
    public static  ByIdSpecifier excludeNone() {
        return (ByIdSpecifier)EXCLUDE_NONE;
    }

    /**
     * @return an instance that excludes everything (i.e. includes nothing)
     */
    @NotNull
    public static  ByIdSpecifier excludeAll() {
        return includeNone();
    }

    /**
     * @return an instance that excludes only the specified ids
     */
    @NotNull
    public static  ByIdSpecifier excludeOnly(@NotNull final Iterable exclusions) {
        assert exclusions != null;

        return new AllBasedByIdSpecifier(ImmutableSet.copyOf(exclusions));
    }

    /**
     * @return an instance that excludes only the specified id
     */
    @NotNull
    public static  ByIdSpecifier excludeOnly(@NotNull final T exclusion) {
        assert exclusion != null;

        return new AllBasedByIdSpecifier(ImmutableSet.of(exclusion));
    }

    /**
     * @return an instance that includes nothing (i.e. excludes everything)
     */
    @SuppressWarnings("unchecked")
    @NotNull
    public static  ByIdSpecifier includeNone() {
        return (ByIdSpecifier)INCLUDE_NONE;
    }

    /**
     * @return an instance that includes everything (i.e. excludes nothing)
     */
    @NotNull
    public static  ByIdSpecifier includeAll() {
        return excludeNone();
    }

    /**
     * @return an instance that includes only the specified ids
     */
    @NotNull
    public static  ByIdSpecifier includeOnly(@NotNull final Iterable inclusions) {
        assert inclusions != null;

        return new NoneBasedByIdSpecifier(ImmutableSet.copyOf(inclusions));
    }

    /**
     * @return an instance that includes only the specified id
     */
    @NotNull
    public static  ByIdSpecifier includeOnly(@NotNull final T inclusion) {
        assert inclusion != null;

        return new NoneBasedByIdSpecifier(ImmutableSet.of(inclusion));
    }
}