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

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

/*
 * 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.LongPredicate;

/**
 * Provides a set of common predicates for long values.
 * This file was automatically generated from template file primitivePredicates.stg.
 */
public final class LongPredicates
{
    private static final LongIsEvenPredicate IS_EVEN = new LongIsEvenPredicate();
    private static final LongIsOddPredicate IS_ODD = new LongIsOddPredicate();
    private static final LongPredicate ALWAYS_TRUE = new AlwaysTrueLongPredicate();
    private static final LongPredicate ALWAYS_FALSE = new AlwaysFalseLongPredicate();

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

    @SuppressWarnings("MisspelledEquals")
    public static LongPredicate equal(long expected)
    {
        return new EqualsLongPredicate(expected);
    }

    public static LongPredicate lessThan(long expected)
    {
        return new LessThanLongPredicate(expected);
    }

    public static LongPredicate greaterThan(long expected)
    {
        return new GreaterThanLongPredicate(expected);
    }

    public static LongPredicate isEven()
    {
        return IS_EVEN;
    }

    public static LongPredicate isOdd()
    {
        return IS_ODD;
    }


    public static LongPredicate alwaysTrue()
    {
        return ALWAYS_TRUE;
    }

    public static LongPredicate alwaysFalse()
    {
        return ALWAYS_FALSE;
    }

    public static LongPredicate and(LongPredicate one, LongPredicate two)
    {
        return new AndLongPredicate(one, two);
    }

    public static LongPredicate or(LongPredicate one, LongPredicate two)
    {
        return new OrLongPredicate(one, two);
    }

    public static LongPredicate not(LongPredicate negate)
    {
        return new NotLongPredicate(negate);
    }

    private static final class EqualsLongPredicate implements LongPredicate
    {
        private static final long serialVersionUID = 1L;
        private final long expected;

        private EqualsLongPredicate(long expected)
        {
            this.expected = expected;
        }

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

    private static final class LessThanLongPredicate implements LongPredicate
    {
        private static final long serialVersionUID = 1L;

        private final long expected;

        private LessThanLongPredicate(long expected)
        {
            this.expected = expected;
        }

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

    private static final class GreaterThanLongPredicate implements LongPredicate
    {
        private static final long serialVersionUID = 1L;

        private final long expected;

        private GreaterThanLongPredicate(long expected)
        {
            this.expected = expected;
        }

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

    private static final class AndLongPredicate implements LongPredicate
    {
        private static final long serialVersionUID = 1L;

        private final LongPredicate one;
        private final LongPredicate two;

        private AndLongPredicate(LongPredicate one, LongPredicate two)
        {
            this.one = one;
            this.two = two;
        }

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

    private static final class OrLongPredicate implements LongPredicate
    {
        private static final long serialVersionUID = 1L;

        private final LongPredicate one;
        private final LongPredicate two;

        private OrLongPredicate(LongPredicate one, LongPredicate two)
        {
            this.one = one;
            this.two = two;
        }

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

    private static final class NotLongPredicate implements LongPredicate
    {
        private static final long serialVersionUID = 1L;

        private final LongPredicate negate;

        private NotLongPredicate(LongPredicate negate)
        {
            this.negate = negate;
        }

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

    private static final class LongIsEvenPredicate implements LongPredicate
    {
        private static final long serialVersionUID = 1L;

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

    private static final class LongIsOddPredicate implements LongPredicate
    {
        private static final long serialVersionUID = 1L;

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

    private static final class AlwaysTrueLongPredicate implements LongPredicate
    {
        private static final long serialVersionUID = 1L;

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

    private static final class AlwaysFalseLongPredicate implements LongPredicate
    {
        private static final long serialVersionUID = 1L;

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy