@Test public void testOpIs() throws Exception { FileNameFileFilterRule filterRule = new FileNameFileFilterRule(new TextValue("foobar.txt"), FileNameFileFilterRule.OP_IS); assertTrue(filterRule.match(createTestNode("foobar.txt"))); assertFalse(filterRule.match(createTestNode("afoobar.txt"))); assertFalse(filterRule.match(createTestNode("foobar.txta"))); assertFalse(filterRule.match(createTestNode("foobara.txt"))); assertFalse(filterRule.match(createTestNode("fooba.txt"))); }
@Override public boolean match(File file) { String name = file.getName(); switch (op) { case OP_IS: return name.equals(pattern.getValue()); case OP_ISNT: return !name.equals(pattern.getValue()); case OP_CONTAINS: return name.indexOf(pattern.getValue()) >= 0; case OP_DOESNT_CONTAINS: return name.indexOf(pattern.getValue()) < 0; case OP_BEGINS_WITH: return name.startsWith(pattern.getValue()); case OP_DOESNT_BEGINS_WITH: return !name.startsWith(pattern.getValue()); case OP_ENDS_WITH: return name.endsWith(pattern.getValue()); case OP_DOESNT_ENDS_WITH: return !name.endsWith(pattern.getValue()); case OP_MATCHES_REGEXP: return regexppattern.matcher(name).matches(); case OP_DOESNT_MATCHES_REGEXP: return !regexppattern.matcher(name).matches(); default: return false; } }
FileNameFileFilterRule implements FileFilterRule { @Override public boolean match(File file) { String name = file.getName(); switch (op) { case OP_IS: return name.equals(pattern.getValue()); case OP_ISNT: return !name.equals(pattern.getValue()); case OP_CONTAINS: return name.indexOf(pattern.getValue()) >= 0; case OP_DOESNT_CONTAINS: return name.indexOf(pattern.getValue()) < 0; case OP_BEGINS_WITH: return name.startsWith(pattern.getValue()); case OP_DOESNT_BEGINS_WITH: return !name.startsWith(pattern.getValue()); case OP_ENDS_WITH: return name.endsWith(pattern.getValue()); case OP_DOESNT_ENDS_WITH: return !name.endsWith(pattern.getValue()); case OP_MATCHES_REGEXP: return regexppattern.matcher(name).matches(); case OP_DOESNT_MATCHES_REGEXP: return !regexppattern.matcher(name).matches(); default: return false; } } }
FileNameFileFilterRule implements FileFilterRule { @Override public boolean match(File file) { String name = file.getName(); switch (op) { case OP_IS: return name.equals(pattern.getValue()); case OP_ISNT: return !name.equals(pattern.getValue()); case OP_CONTAINS: return name.indexOf(pattern.getValue()) >= 0; case OP_DOESNT_CONTAINS: return name.indexOf(pattern.getValue()) < 0; case OP_BEGINS_WITH: return name.startsWith(pattern.getValue()); case OP_DOESNT_BEGINS_WITH: return !name.startsWith(pattern.getValue()); case OP_ENDS_WITH: return name.endsWith(pattern.getValue()); case OP_DOESNT_ENDS_WITH: return !name.endsWith(pattern.getValue()); case OP_MATCHES_REGEXP: return regexppattern.matcher(name).matches(); case OP_DOESNT_MATCHES_REGEXP: return !regexppattern.matcher(name).matches(); default: return false; } } FileNameFileFilterRule(TextValue pattern, int operator); }
FileNameFileFilterRule implements FileFilterRule { @Override public boolean match(File file) { String name = file.getName(); switch (op) { case OP_IS: return name.equals(pattern.getValue()); case OP_ISNT: return !name.equals(pattern.getValue()); case OP_CONTAINS: return name.indexOf(pattern.getValue()) >= 0; case OP_DOESNT_CONTAINS: return name.indexOf(pattern.getValue()) < 0; case OP_BEGINS_WITH: return name.startsWith(pattern.getValue()); case OP_DOESNT_BEGINS_WITH: return !name.startsWith(pattern.getValue()); case OP_ENDS_WITH: return name.endsWith(pattern.getValue()); case OP_DOESNT_ENDS_WITH: return !name.endsWith(pattern.getValue()); case OP_MATCHES_REGEXP: return regexppattern.matcher(name).matches(); case OP_DOESNT_MATCHES_REGEXP: return !regexppattern.matcher(name).matches(); default: return false; } } FileNameFileFilterRule(TextValue pattern, int operator); @Override String getRuleType(); static String[] getAllOperators(); @Override int getOperator(); @Override String getOperatorName(); @Override OperandValue getValue(); @Override boolean match(File file); @Override String toString(); }
FileNameFileFilterRule implements FileFilterRule { @Override public boolean match(File file) { String name = file.getName(); switch (op) { case OP_IS: return name.equals(pattern.getValue()); case OP_ISNT: return !name.equals(pattern.getValue()); case OP_CONTAINS: return name.indexOf(pattern.getValue()) >= 0; case OP_DOESNT_CONTAINS: return name.indexOf(pattern.getValue()) < 0; case OP_BEGINS_WITH: return name.startsWith(pattern.getValue()); case OP_DOESNT_BEGINS_WITH: return !name.startsWith(pattern.getValue()); case OP_ENDS_WITH: return name.endsWith(pattern.getValue()); case OP_DOESNT_ENDS_WITH: return !name.endsWith(pattern.getValue()); case OP_MATCHES_REGEXP: return regexppattern.matcher(name).matches(); case OP_DOESNT_MATCHES_REGEXP: return !regexppattern.matcher(name).matches(); default: return false; } } FileNameFileFilterRule(TextValue pattern, int operator); @Override String getRuleType(); static String[] getAllOperators(); @Override int getOperator(); @Override String getOperatorName(); @Override OperandValue getValue(); @Override boolean match(File file); @Override String toString(); static final String TYPE_NAME; static final int OP_IS; static final int OP_ISNT; static final int OP_CONTAINS; static final int OP_DOESNT_CONTAINS; static final int OP_BEGINS_WITH; static final int OP_DOESNT_BEGINS_WITH; static final int OP_ENDS_WITH; static final int OP_DOESNT_ENDS_WITH; static final int OP_MATCHES_REGEXP; static final int OP_DOESNT_MATCHES_REGEXP; }