[ http://issues.apache.org/jira/browse/IO-89?page=comments#action_12423215
]
Niall Pemberton commented on IO-89:
-----------------------------------
OK so this needs re-thinking. IMO it should be easy to use any of the five
compare operators (i.e. <, <=, =, >=, >) with the size or age filters.
So maybe we should have a constructor which takes the size and operator - and
deprecate the existing boolean parameter constructors:
public SizeFileFilter(long size, boolean acceptLarger) {
this(size, acceptLarger ? ">=" : "<");
}
public SizeFileFilter(long size, String operator) {
this.size = size;
this.operator = operator;
}
public boolean accept(File file) {
if ("<".equals(operator)) {
return file.length() < size;
} else if ("<=".equals(operator)) {
return file.length() <= size;
} else if ("=".equals(operator)) {
return file.length() == size;
} else if (">=".equals(operator)) {
return file.length() >= size;
} else if (">".equals(operator)) {
return file.length() > size;
}
}
When I get time I'll put together a patch for review
> Inconsistency in SizeFileFilter and AgeFileFilter implementations
> -----------------------------------------------------------------
>
> Key: IO-89
> URL: http://issues.apache.org/jira/browse/IO-89
> Project: Commons IO
> Issue Type: Bug
> Components: Filters
> Affects Versions: 1.2
> Reporter: Niall Pemberton
> Priority: Minor
> Fix For: 1.3
>
>
> Theres an inconsistency (bug?) in the implementation of SizeFileFilter and
> AgeFileFilter.
> In SizeFileFilter, using an "acceptLarger" parameter of true actually accepts
> files with a size equal to and larger, whereas
> specifying an "acceptLarger" parameter of false only accepts smaller files.
> The same is true for AgeFileFilter, using an "acceptOlder" parameter of true
> actually accepts files either the same age or older, whereas
> specifying an "acceptOlder" parameter of false only accepts newer files.
> A big benefit of resolving these inconsistencies would mean that creating
> filters for any condition (i.e. <, >, <=, >= or =) becomes
> alot easier. For example if the AgeFileFilter did only do either newer or
> older, then creating a filters for "the same age or older"
> or "the same age or younger" could be done in the following way:
> IOFileFilter equalOlder = new NotFileFilter(new AgeFileFilter(cutoff,
> false));
> IOFileFilter equalYounger = new NotFileFilter(new AgeFileFilter(cutoff,
> true));
> For SizeFileFilter I propose changing the logic to the following:
> if (acceptLarger) {
> return file.length() >= size;
> } else {
> return file.length() <= size;
> }
> (This would mean that "new SizeFileFilter(cutoff)" would operate the same way)
> I have added isOlderFile() methods to FileUtils and propose that
> AgeFileFilter is changed to the following:
> if (acceptOlder) {
> return FileUtils.isFileOlder(file, cutoff);
> } else {
> return FileUtils.isFileNewer(file, cutoff);
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]