com.gs.collections.impl.block.factory.primitive.FloatPredicates Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gs-collections Show documentation
Show all versions of gs-collections Show documentation
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.
/*
* 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.FloatPredicate;
/**
* Provides a set of common predicates for float values.
* This file was automatically generated from template file primitivePredicates.stg.
*/
public final class FloatPredicates
{
private static final FloatPredicate ALWAYS_TRUE = new AlwaysTrueFloatPredicate();
private static final FloatPredicate ALWAYS_FALSE = new AlwaysFalseFloatPredicate();
private FloatPredicates()
{
throw new AssertionError("Suppress default constructor for noninstantiability");
}
@SuppressWarnings("MisspelledEquals")
public static FloatPredicate equal(float expected)
{
return new EqualsFloatPredicate(expected);
}
public static FloatPredicate equal(float expected, float delta)
{
return new EqualsWithDeltaFloatPredicate(expected, delta);
}
public static FloatPredicate lessThan(float expected)
{
return new LessThanFloatPredicate(expected);
}
public static FloatPredicate greaterThan(float expected)
{
return new GreaterThanFloatPredicate(expected);
}
public static FloatPredicate alwaysTrue()
{
return ALWAYS_TRUE;
}
public static FloatPredicate alwaysFalse()
{
return ALWAYS_FALSE;
}
public static FloatPredicate and(FloatPredicate one, FloatPredicate two)
{
return new AndFloatPredicate(one, two);
}
public static FloatPredicate or(FloatPredicate one, FloatPredicate two)
{
return new OrFloatPredicate(one, two);
}
public static FloatPredicate not(FloatPredicate negate)
{
return new NotFloatPredicate(negate);
}
private static final class EqualsFloatPredicate implements FloatPredicate
{
private static final long serialVersionUID = 1L;
private final float expected;
private EqualsFloatPredicate(float expected)
{
this.expected = expected;
}
public boolean accept(float actual)
{
return Float.compare(actual, this.expected) == 0;
}
}
private static final class EqualsWithDeltaFloatPredicate implements FloatPredicate
{
private static final long serialVersionUID = 1L;
private final float expected;
private final float delta;
private EqualsWithDeltaFloatPredicate(float expected, float delta)
{
this.expected = expected;
this.delta = delta;
}
public boolean accept(float actual)
{
return Math.abs(this.expected - actual) <= this.delta;
}
}
private static final class LessThanFloatPredicate implements FloatPredicate
{
private static final long serialVersionUID = 1L;
private final float expected;
private LessThanFloatPredicate(float expected)
{
this.expected = expected;
}
public boolean accept(float actual)
{
return actual < this.expected;
}
}
private static final class GreaterThanFloatPredicate implements FloatPredicate
{
private static final long serialVersionUID = 1L;
private final float expected;
private GreaterThanFloatPredicate(float expected)
{
this.expected = expected;
}
public boolean accept(float actual)
{
return actual > this.expected;
}
}
private static final class AndFloatPredicate implements FloatPredicate
{
private static final long serialVersionUID = 1L;
private final FloatPredicate one;
private final FloatPredicate two;
private AndFloatPredicate(FloatPredicate one, FloatPredicate two)
{
this.one = one;
this.two = two;
}
public boolean accept(float actual)
{
return this.one.accept(actual) && this.two.accept(actual);
}
}
private static final class OrFloatPredicate implements FloatPredicate
{
private static final long serialVersionUID = 1L;
private final FloatPredicate one;
private final FloatPredicate two;
private OrFloatPredicate(FloatPredicate one, FloatPredicate two)
{
this.one = one;
this.two = two;
}
public boolean accept(float actual)
{
return this.one.accept(actual) || this.two.accept(actual);
}
}
private static final class NotFloatPredicate implements FloatPredicate
{
private static final long serialVersionUID = 1L;
private final FloatPredicate negate;
private NotFloatPredicate(FloatPredicate negate)
{
this.negate = negate;
}
public boolean accept(float actual)
{
return !this.negate.accept(actual);
}
}
private static final class AlwaysTrueFloatPredicate implements FloatPredicate
{
private static final long serialVersionUID = 1L;
public boolean accept(float value)
{
return true;
}
}
private static final class AlwaysFalseFloatPredicate implements FloatPredicate
{
private static final long serialVersionUID = 1L;
public boolean accept(float value)
{
return false;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy