io.github.palexdev.mfxcore.filter.FloatFilter Maven / Gradle / Ivy
Show all versions of materialfx-all Show documentation
/*
* Copyright (C) 2022 Parisi Alessandro - [email protected]
* This file is part of MaterialFX (https://github.com/palexdev/MaterialFX)
*
* MaterialFX is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 3 of the License,
* or (at your option) any later version.
*
* MaterialFX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MaterialFX. If not, see .
*/
package io.github.palexdev.mfxcore.filter;
import io.github.palexdev.mfxcore.base.beans.BiPredicateBean;
import io.github.palexdev.mfxcore.filter.base.NumberFilter;
import io.github.palexdev.mfxcore.utils.fx.FXCollectors;
import io.github.palexdev.mfxlocalization.I18N;
import javafx.collections.ObservableList;
import javafx.util.StringConverter;
import javafx.util.converter.FloatStringConverter;
import java.util.Collections;
import java.util.function.Function;
import java.util.stream.Stream;
/**
* Extension of {@link NumberFilter} for float fields.
*
* Offers the following default {@link BiPredicateBean}s:
* - "is": checks for floats equality
*
- "is not": checks for floats inequality
*
- "greater than": checks if a float is greater than another float
*
- "greater or equal to": checks if a float is greater or equal to another float
*
- "lesser than": checks if a float is lesser than another float
*
- "lesser or equal to": checks if a float is lesser or equal to another float
*/
public class FloatFilter extends NumberFilter {
//================================================================================
// Constructors
//================================================================================
public FloatFilter(String name, Function extractor) {
this(name, extractor, new FloatStringConverter());
}
public FloatFilter(String name, Function extractor, StringConverter converter) {
super(name, extractor, converter);
}
//================================================================================
// Overridden Methods
//================================================================================
@Override
protected ObservableList> defaultPredicates() {
return Stream.>of(
new BiPredicateBean<>(I18N.getOrDefault("filter.is"), Float::equals),
new BiPredicateBean<>(I18N.getOrDefault("filter.isNot"), (aFloat, aFloat2) -> !aFloat.equals(aFloat2)),
new BiPredicateBean<>(I18N.getOrDefault("filter.greater"), (aFloat, aFloat2) -> aFloat > aFloat2),
new BiPredicateBean<>(I18N.getOrDefault("filter.greaterEqual"), (aFloat, aFloat2) -> aFloat >= aFloat2),
new BiPredicateBean<>(I18N.getOrDefault("filter.lesser"), (aFloat, aFloat2) -> aFloat < aFloat2),
new BiPredicateBean<>(I18N.getOrDefault("filter.lesserEqual"), (aFloat, aFloat2) -> aFloat <= aFloat2)
).collect(FXCollectors.toList());
}
@SafeVarargs
@Override
protected final FloatFilter extend(BiPredicateBean... predicateBeans) {
Collections.addAll(super.predicates, predicateBeans);
return this;
}
}