X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Futils%2FIntegerRangePredicate.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Futils%2FIntegerRangePredicate.java;h=db6a841d965b0c02585ca1065aea274f102a4522;hb=03946e6554d5a59f54058fbf89b407ef327344ca;hp=0000000000000000000000000000000000000000;hpb=0cc3f122d58e3da8be819e571fd654be463b9f88;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/utils/IntegerRangePredicate.java b/src/main/java/net/pterodactylus/sone/utils/IntegerRangePredicate.java new file mode 100644 index 0000000..db6a841 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/utils/IntegerRangePredicate.java @@ -0,0 +1,62 @@ +/* + * Sone - IntegerRangePredicate.java - Copyright © 2013 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.utils; + +import com.google.common.base.Predicate; + +/** + * {@link Predicate} that verifies that an {@link Integer} value is not + * {@code null} and is between a lower and an upper bound. Both bounds are + * inclusive. + * + * @author David ‘Bombe’ Roden + */ +public class IntegerRangePredicate implements Predicate { + + /** The lower bound. */ + private final int lowerBound; + + /** The upper bound. */ + private final int upperBound; + + /** + * Creates a new integer range predicate. + * + * @param lowerBound + * The lower bound + * @param upperBound + * The upper bound + */ + public IntegerRangePredicate(int lowerBound, int upperBound) { + this.lowerBound = lowerBound; + this.upperBound = upperBound; + } + + // + // PREDICATE METHODS + // + + /** + * {@inheritDoc} + */ + @Override + public boolean apply(Integer value) { + return (value != null) && (value >= lowerBound) && (value <= upperBound); + } + +}