I wrote a wrapper around FEST's ComponentFinder. It does the same thing as the delegate, looks for java.awt.Components in GUI, but in a more convenient manner for its clients (e.g. you don't have to build and pass those ugly clumsy GenericTypeMatchers).
What should I name it?
ComponentFinder. Bad. May cause confusion as to which finder it is, the wrapper or the original FEST one.ComponentFinderWrapper. Bad. The fact that it wraps aComponentFinderis simply an implementation detail.Component[something](ComponentTraverser,ComponentInspector...). Dubious. A vocab exercise that doesn't convey any meaningful semantics.
More generally, having a convenience wrapper like this, how do I choose a good name for it?
import com.google.common.base.Predicates; import org.fest.swing.core.Robot; import java.awt.Component; import java.awt.Container; import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.function.Predicate; public class ComponentFinder { private final org.fest.swing.core.ComponentFinder delegate; public ComponentFinder() { this(Robots.getRobot()); } public ComponentFinder(Robot robot) { this.delegate = robot.finder(); } public <T extends Component> Optional<T> find(Container container, Class<T> childType) { return find(container, childType, Predicates.alwaysTrue()); } public <T extends Component> Optional<T> find(Container container, Class<T> childType, Predicate<T> additionalCondition) { return findAll(container, childType, additionalCondition).stream().findFirst(); } public <T extends Component> List<T> findAll(Container container, Class<T> childType) { return findAll(container, childType, Predicates.alwaysTrue()); } public <T extends Component> List<T> findAll(Container container, Class<T> childType, Predicate<T> additionalCondition) { ChainableTypeMatcher<T> matcher = Matchers.forType(childType).andCondition(additionalCondition); List<T> matchingComponents = new ArrayList<>(delegate.findAll(container, matcher)); return matchingComponents; } } import java.awt.Component; public class Matchers { private Matchers() { } public static <T extends Component> ChainableTypeMatcher<T> forType(Class<T> type) { return ChainableTypeMatcher.forType(type); } } import com.google.common.base.Predicates; import org.fest.swing.core.GenericTypeMatcher; import java.awt.Component; import java.util.function.Predicate; public class ChainableTypeMatcher<T extends Component> extends GenericTypeMatcher<T> { private Predicate<T> predicate; private ChainableTypeMatcher(Class<T> type) { super(type, false); predicate = Predicates.alwaysTrue(); } static <T extends Component> ChainableTypeMatcher<T> forType(Class<T> type) { return new ChainableTypeMatcher<>(type); } public ChainableTypeMatcher<T> andCondition(Predicate<T> condition) { predicate = predicate.and(condition); return this; } @Override protected boolean isMatching(T component) { return predicate.test(component); } }