From bd53f05d3995324499ec341f3c37f036772b1478 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 4 Jun 2013 21:14:08 +0200 Subject: [PATCH] Remove now obsolete predicate filter. --- .../sonitus/data/filter/PredicateFilter.java | 122 --------------------- 1 file changed, 122 deletions(-) delete mode 100644 src/main/java/net/pterodactylus/sonitus/data/filter/PredicateFilter.java diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/PredicateFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/PredicateFilter.java deleted file mode 100644 index 20840a8..0000000 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/PredicateFilter.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Sonitus - PredicateFilter.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.sonitus.data.filter; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.io.IOException; -import java.util.concurrent.atomic.AtomicBoolean; - -import net.pterodactylus.sonitus.data.AbstractFilter; -import net.pterodactylus.sonitus.data.Filter; -import net.pterodactylus.sonitus.data.Metadata; - -import com.google.common.base.Predicate; - -/** - * {@link Filter} implementation that uses a {@link Predicate} to determine - * whether a filter will be used or the data will only be passed through. - * - * @author David ‘Bombe’ Roden - */ -public class PredicateFilter extends AbstractFilter implements Filter { - - /** The predicate. */ - private final Predicate metadataPredicate; - - /** The filter to use if the predicate matches. */ - private final Filter filter; - - /** Whether the predicate currently matches. */ - private final AtomicBoolean metadataMatches = new AtomicBoolean(false); - - /** - * Creates a new predicate filter. - * - * @param metadataPredicate - * The predicate to evaluate every time the metadata changes - * @param filter - */ - public PredicateFilter(Predicate metadataPredicate, Filter filter) { - super(String.format("%s (maybe)", filter.name())); - this.metadataPredicate = metadataPredicate; - this.filter = filter; - } - - // - // FILTER METHODS - // - - @Override - public void open(Metadata metadata) throws IOException { - checkNotNull(metadata, "metadata must not be null"); - - metadataMatches.set(metadataPredicate.apply(metadata)); - if (metadataMatches.get()) { - filter.open(metadata); - } else { - super.open(metadata); - } - } - - @Override - public void close() { - if (metadataMatches.get()) { - filter.close(); - } else { - super.close(); - } - } - - @Override - public Metadata metadata() { - if (metadataMatches.get()) { - return filter.metadata(); - } - return super.metadata(); - } - - @Override - public void metadataUpdated(Metadata metadata) { - metadataMatches.set(metadataPredicate.apply(metadata)); - if (metadataMatches.get()) { - filter.metadataUpdated(metadata); - } else { - super.metadataUpdated(metadata); - } - } - - @Override - public void process(byte[] buffer) throws IOException { - if (metadataMatches.get()) { - filter.process(buffer); - } else { - super.process(buffer); - } - } - - @Override - public byte[] get(int bufferSize) throws IOException { - if (metadataMatches.get()) { - return filter.get(bufferSize); - } else { - return super.get(bufferSize); - } - } - -} -- 2.7.4