@Test public void declinesDirectoriesWithNonIntegerName() { String[] illegalNames = { "/proc/sys/kernel", "/", "src/main", "-ölok", "1241abc", "asb5123", "XIV", "24F2A" }; for (String illegalName : illegalNames) { boolean result = procPathFilter.accept(true, illegalName); assertFalse("Expected filter to decline file \"" + illegalName + "\"", result); } }
boolean accept(boolean isDirectory, String fileName) { if (!isDirectory) { return false; } Integer numericalPid = tryParseInt(fileName); return numericalPid != null && numericalPid >= LinuxConstants.LOWEST_LEGAL_PID && numericalPid < pidMax; }
ProcPathFilter implements BiPredicate<Path, BasicFileAttributes> { boolean accept(boolean isDirectory, String fileName) { if (!isDirectory) { return false; } Integer numericalPid = tryParseInt(fileName); return numericalPid != null && numericalPid >= LinuxConstants.LOWEST_LEGAL_PID && numericalPid < pidMax; } }
ProcPathFilter implements BiPredicate<Path, BasicFileAttributes> { boolean accept(boolean isDirectory, String fileName) { if (!isDirectory) { return false; } Integer numericalPid = tryParseInt(fileName); return numericalPid != null && numericalPid >= LinuxConstants.LOWEST_LEGAL_PID && numericalPid < pidMax; } ProcPathFilter(int pidMax); }
ProcPathFilter implements BiPredicate<Path, BasicFileAttributes> { boolean accept(boolean isDirectory, String fileName) { if (!isDirectory) { return false; } Integer numericalPid = tryParseInt(fileName); return numericalPid != null && numericalPid >= LinuxConstants.LOWEST_LEGAL_PID && numericalPid < pidMax; } ProcPathFilter(int pidMax); @Override boolean test(Path path, BasicFileAttributes basicFileAttributes); }
ProcPathFilter implements BiPredicate<Path, BasicFileAttributes> { boolean accept(boolean isDirectory, String fileName) { if (!isDirectory) { return false; } Integer numericalPid = tryParseInt(fileName); return numericalPid != null && numericalPid >= LinuxConstants.LOWEST_LEGAL_PID && numericalPid < pidMax; } ProcPathFilter(int pidMax); @Override boolean test(Path path, BasicFileAttributes basicFileAttributes);  }