net.lucidviews.util.io
Class FileDateComparator

java.lang.Object
  extended by net.lucidviews.util.io.AbstractFileComparator
      extended by net.lucidviews.util.io.FileDateComparator
All Implemented Interfaces:
Comparator, FileComparator

public class FileDateComparator
extends AbstractFileComparator

A FileComparator that compares files using their last-modified timestamp.
By default this comparator places files in chronological order. I.e: more recent files would be pushed to the end of a list and older files would rise to the top.
This logic can be switched by constructing an instance with a DateComparator that sorts dates in a reverse chronological order.

Since:
1.0
Version:
$Revision: 1.1 $
Author:
Stephen Battey
See Also:
Comparator, FileComparator, DateComparator

Field Summary
protected  DateComparator _dateComparator
          The comparator used to compare file timestamps.
static FileDateComparator CHRONOLOGICAL
          A FileDateComparator that puts files into chronological order, based on their (last-modified) timestamp.
static FileDateComparator REVERSE_CHRONOLOGICAL
          A FileDateComparator that puts files into reverse chronological order, based on their (last-modified) timestamp.
 
Constructor Summary
protected FileDateComparator()
          The default constructor.
protected FileDateComparator(DateComparator dateComparator)
          Create a comparator that will order files according to their (last modified) timestamp.
 
Method Summary
 int compare(File file1, File file2)
          Compares two Files for order.
 boolean equals(Object obj)
           
 
Methods inherited from class net.lucidviews.util.io.AbstractFileComparator
compare
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHRONOLOGICAL

public static final FileDateComparator CHRONOLOGICAL
A FileDateComparator that puts files into chronological order, based on their (last-modified) timestamp.


REVERSE_CHRONOLOGICAL

public static final FileDateComparator REVERSE_CHRONOLOGICAL
A FileDateComparator that puts files into reverse chronological order, based on their (last-modified) timestamp.


_dateComparator

protected DateComparator _dateComparator
The comparator used to compare file timestamps.

Constructor Detail

FileDateComparator

protected FileDateComparator()
The default constructor.
A comparator that will put files in chronological order according to their (last modified) timestamp.


FileDateComparator

protected FileDateComparator(DateComparator dateComparator)
Create a comparator that will order files according to their (last modified) timestamp.

Parameters:
dateComparator - the comparator to use to compare file timestamps
Method Detail

compare

public int compare(File file1,
                   File file2)
Description copied from interface: FileComparator
Compares two Files for order. Returns a negative integer, zero, or a positive integer as the first file is less than, equal to, or greater than the second.

The implementor must ensure that sgn(compare(x, y)) == -sgn(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementer must ensure that compare(x, y)==0 implies that sgn(compare(x, z))==sgn(compare(y, z)) for all z.

It is generally the case, but not strictly required that (compare(x, y)==0) == (x.equals(y)). Generally speaking, any comparator that violates this condition should clearly indicate this fact. The recommended language is "Note: this comparator imposes orderings that are inconsistent with equals."

Parameters:
file1 - the first file to be compared
file2 - the second file to be compared
Returns:
a negative integer, zero, or a positive integer as the first file is less than, equal to, or greater than the second

equals

public boolean equals(Object obj)
Specified by:
equals in interface Comparator
Overrides:
equals in class Object