/** * Finds an actor that fulfills the given predicate, starting the search in * the given root * * @return the actor found. Could be {@code null} if no actor matched the * predicate */ public static Actor findActor(Group root, Predicate<Actor> predicate) { if (predicate.evaluate(root)) { return root; } for (Actor child : root.getChildren()) { if (predicate.evaluate(child)) { return child; } else if (child instanceof Group) { Actor actor = findActor((Group) child, predicate); if (actor != null) { return actor; } } } return null; }
public static <T extends ITargetOwner> TargetChecker<T> withName(final String name, IVisualizer<? super T> visualizer) { return new TargetChecker<T>(new Predicate<Creature>() { @Override public boolean evaluate(Creature creature) { return name.equals(creature.description.name); } }, visualizer); }
public static <T extends ITargetOwner> TargetChecker<T> withProfession(final ProfessionDescription profession, IVisualizer<? super T> visualizer) { return new TargetChecker<T>(new Predicate<Creature>() { @Override public boolean evaluate(Creature creature) { return profession == creature.description.profession; } }, visualizer); }
public static <T> Predicate<T> eq(final T value) { return new Predicate<T>() { @Override public boolean evaluate(T arg0) { return arg0 == value; } }; }
/** * Returns an iterable for the selected items in the array. Remove is * supported, but not between hasNext() and next(). Note that the same * iterable instance is returned each time this method is called. Use the * {@link Predicate.PredicateIterable} constructor for nested or * multithreaded iteration. */ public Iterable<T> select(Predicate<T> predicate) { if (predicateIterable == null) predicateIterable = new Predicate.PredicateIterable<T>(this, predicate); else predicateIterable.set(this, predicate); return predicateIterable; }
public Iterable<AbstractCache> select(Predicate<AbstractCache> predicate) { synchronized ((Object) this.items) { //must cast to Object otherwise it gives a classcastexception at runtime return super.select(predicate); } }
private TargetChecker(Predicate<Creature> predicate, IVisualizer<? super T> visualizer) { this.predicate = predicate; this.visualizer = visualizer; }
public static <T extends ITargetOwner> TargetChecker<T> make(Predicate<Creature> predicate, IVisualizer<? super T> visualizer) { return new TargetChecker<T>(predicate, visualizer); }
private AbilityChecker(Predicate<Ability> predicate, IVisualizer<? super T> visualizer) { this.predicate = predicate; this.visualizer = visualizer; }
public static <T extends IAbilityOwner> AbilityChecker<T> make(Predicate<Ability> predicate, IVisualizer<? super T> visualizer) { return new AbilityChecker<T>(predicate, visualizer); }