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

com.gs.collections.impl.block.factory.primitive.IntPredicates Maven / Gradle / Ivy

Go to download

GS Collections is a collections framework for Java. It has JDK-compatible List, Set and Map implementations with a rich API and set of utility classes that work with any JDK compatible Collections, Arrays, Maps or Strings. The iteration protocol was inspired by the Smalltalk collection framework.

There is a newer version: 7.0.3
Show newest version
/*
 * Copyright 2014 Goldman Sachs.
 *
 * 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.gs.collections.impl.block.factory.primitive;

import com.gs.collections.api.block.predicate.primitive.IntPredicate;

/**
 * Provides a set of common predicates for int values.
 * This file was automatically generated from template file primitivePredicates.stg.
 */
public final class IntPredicates
{
    private static final IntIsEvenPredicate IS_EVEN = new IntIsEvenPredicate();
    private static final IntIsOddPredicate IS_ODD = new IntIsOddPredicate();
    private static final IntPredicate ALWAYS_TRUE = new AlwaysTrueIntPredicate();
    private static final IntPredicate ALWAYS_FALSE = new AlwaysFalseIntPredicate();

    private IntPredicates()
    {
        throw new AssertionError("Suppress default constructor for noninstantiability");
    }

    @SuppressWarnings("MisspelledEquals")
    public static IntPredicate equal(int expected)
    {
        return new EqualsIntPredicate(expected);
    }

    public static IntPredicate lessThan(int expected)
    {
        return new LessThanIntPredicate(expected);
    }

    public static IntPredicate greaterThan(int expected)
    {
        return new GreaterThanIntPredicate(expected);
    }

    public static IntPredicate isEven()
    {
        return IS_EVEN;
    }

    public static IntPredicate isOdd()
    {
        return IS_ODD;
    }

    public static IntPredicate alwaysTrue()
    {
        return ALWAYS_TRUE;
    }

    public static IntPredicate alwaysFalse()
    {
        return ALWAYS_FALSE;
    }

    public static IntPredicate and(IntPredicate one, IntPredicate two)
    {
        return new AndIntPredicate(one, two);
    }

    public static IntPredicate or(IntPredicate one, IntPredicate two)
    {
        return new OrIntPredicate(one, two);
    }

    public static IntPredicate not(IntPredicate negate)
    {
        return new NotIntPredicate(negate);
    }

    private static final class EqualsIntPredicate implements IntPredicate
    {
        private static final long serialVersionUID = 1L;
        private final int expected;

        private EqualsIntPredicate(int expected)
        {
            this.expected = expected;
        }

        public boolean accept(int actual)
        {
            return actual == this.expected;
        }
    }

    private static final class LessThanIntPredicate implements IntPredicate
    {
        private static final long serialVersionUID = 1L;

        private final int expected;

        private LessThanIntPredicate(int expected)
        {
            this.expected = expected;
        }

        public boolean accept(int actual)
        {
            return actual < this.expected;
        }
    }

    private static final class GreaterThanIntPredicate implements IntPredicate
    {
        private static final long serialVersionUID = 1L;

        private final int expected;

        private GreaterThanIntPredicate(int expected)
        {
            this.expected = expected;
        }

        public boolean accept(int actual)
        {
            return actual > this.expected;
        }
    }

    private static final class AndIntPredicate implements IntPredicate
    {
        private static final long serialVersionUID = 1L;

        private final IntPredicate one;
        private final IntPredicate two;

        private AndIntPredicate(IntPredicate one, IntPredicate two)
        {
            this.one = one;
            this.two = two;
        }

        public boolean accept(int actual)
        {
            return this.one.accept(actual) && this.two.accept(actual);
        }
    }

    private static final class OrIntPredicate implements IntPredicate
    {
        private static final long serialVersionUID = 1L;

        private final IntPredicate one;
        private final IntPredicate two;

        private OrIntPredicate(IntPredicate one, IntPredicate two)
        {
            this.one = one;
            this.two = two;
        }

        public boolean accept(int actual)
        {
            return this.one.accept(actual) || this.two.accept(actual);
        }
    }

    private static final class NotIntPredicate implements IntPredicate
    {
        private static final long serialVersionUID = 1L;

        private final IntPredicate negate;

        private NotIntPredicate(IntPredicate negate)
        {
            this.negate = negate;
        }

        public boolean accept(int actual)
        {
            return !this.negate.accept(actual);
        }
    }

    private static final class IntIsEvenPredicate implements IntPredicate
    {
        private static final long serialVersionUID = 1L;

        public boolean accept(int integral)
        {
            return integral % 2 == 0;
        }
    }

    private static final class IntIsOddPredicate implements IntPredicate
    {
        private static final long serialVersionUID = 1L;

        public boolean accept(int integral)
        {
            return integral % 2 != 0;
        }
    }

    private static final class AlwaysTrueIntPredicate implements IntPredicate
    {
        private static final long serialVersionUID = 1L;

        public boolean accept(int value)
        {
            return true;
        }
    }

    private static final class AlwaysFalseIntPredicate implements IntPredicate
    {
        private static final long serialVersionUID = 1L;

        public boolean accept(int value)
        {
            return false;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy