Botre Posted April 3, 2016 Share Posted April 3, 2016 (edited) Updated from: http://osbot.org/forum/topic/91630-snippet-predicate-filter-adapter/ 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! Example: package utils; import java.util.function.Predicate; import org.osbot.rs07.api.filter.Filter; import org.osbot.rs07.api.model.NPC; public class Example { public static void main(String[] args) { Filter<NPC> filter = npc -> npc.exists(); Predicate<NPC> predicate = FilterPredicate.fromFilter(filter); filter = FilterPredicate.fromPredicate(predicate); } } Snippet: package utils; import java.util.function.Predicate; import org.osbot.rs07.api.filter.Filter; /* * Adapts an OSBot Filter to work as a Java Util Predicate and vice versa. * */ 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); } public static final <T> FilterPredicate<T> fromFilter(Filter<T> filter) { return new FilterPredicate<T>() { @Override protected boolean _test(T value) { return filter.match(value); } }; } public static final <T> FilterPredicate<T> fromPredicate(Predicate<T> predicate) { return new FilterPredicate<T>() { @Override protected boolean _test(T value) { return predicate.test(value); } }; } } Edited April 3, 2016 by Botre 1 Quote Link to comment Share on other sites More sharing options...
Pegasus Posted July 24, 2018 Share Posted July 24, 2018 My IDE shows Cannot resolve symbol 'FilterPredicate' How to use it? @Botre Quote Link to comment Share on other sites More sharing options...