@Test public void testAccept() { final PathCondition TRUE = new FixedCondition(true); final PathCondition FALSE = new FixedCondition(false); assertTrue(IfAll.createAndCondition(TRUE, TRUE).accept(null, null, null)); assertFalse(IfAll.createAndCondition(FALSE, TRUE).accept(null, null, null)); assertFalse(IfAll.createAndCondition(TRUE, FALSE).accept(null, null, null)); assertFalse(IfAll.createAndCondition(FALSE, FALSE).accept(null, null, null)); }
@Test public void testBeforeTreeWalk() { final CountingCondition counter = new CountingCondition(true); final IfAll and = IfAll.createAndCondition(counter, counter, counter); and.beforeFileTreeWalk(); assertEquals(3, counter.getBeforeFileTreeWalkCount()); }
@Override public void beforeFileTreeWalk() { count = 0; IfAll.beforeFileTreeWalk(nestedConditions); }
@Override public boolean accept(final Path baseDir, final Path relativePath, final BasicFileAttributes attrs) { if (components == null || components.length == 0) { return false; // unconditional delete not supported } return accept(components, baseDir, relativePath, attrs); }
/** * Create a Composite PathCondition whose components all need to accept before this condition accepts. * * @param components The component filters. * @return A Composite PathCondition. */ @PluginFactory public static IfAll createAndCondition( @PluginElement("PathConditions") final PathCondition... components) { return new IfAll(components); }
@Override public void beforeFileTreeWalk() { accumulatedSize = 0; IfAll.beforeFileTreeWalk(nestedConditions); }
@Override public boolean accept(final Path basePath, final Path relativePath, final BasicFileAttributes attrs) { final boolean result = ++count > threshold; final String match = result ? ">" : "<="; final String accept = result ? "ACCEPTED" : "REJECTED"; LOGGER.trace("IfAccumulatedFileCount {}: {} count '{}' {} threshold '{}'", accept, relativePath, count, match, threshold); if (result) { return IfAll.accept(nestedConditions, basePath, relativePath, attrs); } return result; }
@Override public void beforeFileTreeWalk() { IfAll.beforeFileTreeWalk(nestedConditions); }
@Override public boolean accept(final Path basePath, final Path relativePath, final BasicFileAttributes attrs) { final boolean result = pathMatcher.matches(relativePath); final String match = result ? "matches" : "does not match"; final String accept = result ? "ACCEPTED" : "REJECTED"; LOGGER.trace("IfFileName {}: '{}' {} relative path '{}'", accept, syntaxAndPattern, match, relativePath); if (result) { return IfAll.accept(nestedConditions, basePath, relativePath, attrs); } return result; }
@Test public void testEmptyIsFalse() { assertFalse(IfAll.createAndCondition().accept(null, null, null)); }
@Override public void beforeFileTreeWalk() { IfAll.beforeFileTreeWalk(nestedConditions); }
@Override public boolean accept(final Path basePath, final Path relativePath, final BasicFileAttributes attrs) { accumulatedSize += attrs.size(); final boolean result = accumulatedSize > thresholdBytes; final String match = result ? ">" : "<="; final String accept = result ? "ACCEPTED" : "REJECTED"; LOGGER.trace("IfAccumulatedFileSize {}: {} accumulated size '{}' {} thresholdBytes '{}'", accept, relativePath, accumulatedSize, match, thresholdBytes); if (result) { return IfAll.accept(nestedConditions, basePath, relativePath, attrs); } return result; }
@Override public void beforeFileTreeWalk() { beforeFileTreeWalk(components); }
@Override public boolean accept(final Path basePath, final Path relativePath, final BasicFileAttributes attrs) { final FileTime fileTime = attrs.lastModifiedTime(); final long millis = fileTime.toMillis(); final long ageMillis = CLOCK.currentTimeMillis() - millis; final boolean result = ageMillis >= age.toMillis(); final String match = result ? ">=" : "<"; final String accept = result ? "ACCEPTED" : "REJECTED"; LOGGER.trace("IfLastModified {}: {} ageMillis '{}' {} '{}'", accept, relativePath, ageMillis, match, age); if (result) { return IfAll.accept(nestedConditions, basePath, relativePath, attrs); } return result; }