ArgFilters { public static Predicate<Field> selectAllPackagesUnderHere(final Package pkg) { Preconditions.checkNotNull(pkg); final String prefix = pkg.getName() + '.'; return Predicates.or(selectPackage(pkg), field -> { return field.getDeclaringClass().getPackage().getName().startsWith(prefix); }); } private  ArgFilters(); static Predicate<Field> selectPackage(final Package pkg); static Predicate<Field> selectAllPackagesUnderHere(final Package pkg); static Predicate<Field> selectClass(final Class<?> clazz); static Predicate<Field> selectClasses(final Class<?> ... cls); static Predicate<Field> selectCmdLineArg(Class<?> clazz, final String name); static final Predicate<Field> SELECT_ALL; }
@Test public void testAllPackagesUnderHere() throws IOException { testFilter(ArgFilters.selectAllPackagesUnderHere(ArgsRoot.class.getPackage()), fieldInfo(ArgsRoot.class, "ARGS_ROOT"), fieldInfo(ArgsA.class, "ARGS_A"), fieldInfo(ArgsB.class, "ARGS_B"), fieldInfo(ArgsA1.class, "ARGS_A1"), fieldInfo(ArgsBWithSuffix.class, "ARGS_B_WITH_SUFFIX")); testFilter(ArgFilters.selectAllPackagesUnderHere(ArgsB.class.getPackage()), fieldInfo(ArgsB.class, "ARGS_B")); }