Traum Posted January 28, 2016 Share Posted January 28, 2016 (edited) Adapts an OSBot Filter to work as a Java Util Predicate and vice versa. Useful if you don't wan't to rewrite your Predicate and / or Filter libraries but still want to enjoy the benefits provided by both worlds. If someone has a cleaner method, please do let me know! public class FilterPredicate<V> implements Filter<V>, Predicate<V> { protected boolean _test(V value) { return false; } @Override public boolean match(V value) { return _test(value); } @Override public boolean test(V value) { return _test(value); } // Virtual constructor for OSBot Filter. public FilterPredicate<V> fromFilter(Filter<V> filter) { return new FilterPredicate<V>() { @Override protected boolean _test(V value) { return filter.match(value); } }; } // Virtual constructor for Java Util Predicate. public FilterPredicate<V> fromPredicate(Predicate<V> predicate) { return new FilterPredicate<V>() { @Override protected boolean _test(V value) { return predicate.test(value); } }; } } Examples: * EXAMPLE A: Predicate<V> predicate = ... Filter<V> filter = new FilterPredicate<V>().fromPredicate(predicate); * EXAMPLE B: Filter<V> filter = ... Predicate<V> predicate = new FilterPredicate<V>().fromFilter(filter); * EXAMPLE C: PredicateFilter<V> god = new PredicateFilter<V>().fromPredicate(lambda); god.predicate_specific_method(); god.filter_specific_method(); Edited January 28, 2016 by Traum 1 Quote Link to comment Share on other sites More sharing options...