@Test public void testOpIsLessThan() throws Exception { FileSizeFileFilterRule filterRule = new FileSizeFileFilterRule(new SizeValue("1000 Bytes"), FileSizeFileFilterRule.OP_IS_LESS_THAN); assertFalse(filterRule.match(foobarTxt)); foobarTxt.setSize(2000); assertFalse(filterRule.match(foobarTxt)); foobarTxt.setSize(999); assertTrue(filterRule.match(foobarTxt)); }
@Override public boolean match(File file) throws FilterRuleNotAppliableException { long filesize = file.getSize(); if (-1 == filesize) { throw new FilterRuleNotAppliableException("The file doesn't have any size attribute"); } switch (op) { case OP_IS: return filesize == size.getBytes(); case OP_ISNT: return filesize != size.getBytes(); case OP_IS_GREATER_THAN: return filesize > size.getBytes(); case OP_IS_LESS_THAN: return filesize < size.getBytes(); default: return false; } }
FileSizeFileFilterRule implements FileFilterRule { @Override public boolean match(File file) throws FilterRuleNotAppliableException { long filesize = file.getSize(); if (-1 == filesize) { throw new FilterRuleNotAppliableException("The file doesn't have any size attribute"); } switch (op) { case OP_IS: return filesize == size.getBytes(); case OP_ISNT: return filesize != size.getBytes(); case OP_IS_GREATER_THAN: return filesize > size.getBytes(); case OP_IS_LESS_THAN: return filesize < size.getBytes(); default: return false; } } }
FileSizeFileFilterRule implements FileFilterRule { @Override public boolean match(File file) throws FilterRuleNotAppliableException { long filesize = file.getSize(); if (-1 == filesize) { throw new FilterRuleNotAppliableException("The file doesn't have any size attribute"); } switch (op) { case OP_IS: return filesize == size.getBytes(); case OP_ISNT: return filesize != size.getBytes(); case OP_IS_GREATER_THAN: return filesize > size.getBytes(); case OP_IS_LESS_THAN: return filesize < size.getBytes(); default: return false; } } FileSizeFileFilterRule(SizeValue size, int operator); }
FileSizeFileFilterRule implements FileFilterRule { @Override public boolean match(File file) throws FilterRuleNotAppliableException { long filesize = file.getSize(); if (-1 == filesize) { throw new FilterRuleNotAppliableException("The file doesn't have any size attribute"); } switch (op) { case OP_IS: return filesize == size.getBytes(); case OP_ISNT: return filesize != size.getBytes(); case OP_IS_GREATER_THAN: return filesize > size.getBytes(); case OP_IS_LESS_THAN: return filesize < size.getBytes(); default: return false; } } FileSizeFileFilterRule(SizeValue size, 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(); }
FileSizeFileFilterRule implements FileFilterRule { @Override public boolean match(File file) throws FilterRuleNotAppliableException { long filesize = file.getSize(); if (-1 == filesize) { throw new FilterRuleNotAppliableException("The file doesn't have any size attribute"); } switch (op) { case OP_IS: return filesize == size.getBytes(); case OP_ISNT: return filesize != size.getBytes(); case OP_IS_GREATER_THAN: return filesize > size.getBytes(); case OP_IS_LESS_THAN: return filesize < size.getBytes(); default: return false; } } FileSizeFileFilterRule(SizeValue size, 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_IS_GREATER_THAN; static final int OP_IS_LESS_THAN; }