BrightSide Workbench Full Report + Source Code
org.turro.file.FileComparator Class Reference
Inheritance diagram for org.turro.file.FileComparator:
Collaboration diagram for org.turro.file.FileComparator:

Public Member Functions

 FileComparator (Properties props)
 
int compare (Object o1, Object o2)
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 28 of file FileComparator.java.

Constructor & Destructor Documentation

◆ FileComparator()

org.turro.file.FileComparator.FileComparator ( Properties  props)

Creates a new instance of FileComparator

Definition at line 33 of file FileComparator.java.

33  {
34  this.props = props;
35  }

Member Function Documentation

◆ compare()

int org.turro.file.FileComparator.compare ( Object  o1,
Object  o2 
)

Uses file.ordering.[n].name and file.ordering.[n].order pairs to compare FileDocument entries. Possible fields are: directory, fileName, fileDate, fileSize. Ex.:

file.ordering.0.name=directory
file.ordering.0.order=asc
file.ordering.1.name=fileName
file.ordering.1.order=asc
file.ordering.2.name=fileDate
file.ordering.2.order=desc

Definition at line 50 of file FileComparator.java.

50  {
51  File f1 = (File) o1,
52  f2 = (File) o2;
53 
54  String field;
55  boolean desc;
56  int result = 0;
57  for(int i = 0; i < 10 && result == 0; i++) {
58  field = props.getProperty("file.ordering." + i + ".name");
59  desc = "desc".equals(props.getProperty("file.ordering." + i + ".order"));
60  if(result == 0 && "directory".equals(field)) {
61  if(!f1.isDirectory() && f2.isDirectory()) {
62  result = 1;
63  }
64  else if(f1.isDirectory() && !f2.isDirectory()) {
65  result = -1;
66  }
67  else {
68  result = 0;
69  }
70  if(desc) result *= -1;
71  }
72  else if(result == 0 && "fileName".equals(field)) {
73  result = f1.getName().compareTo(f2.getName());
74  if(desc) result *= -1;
75  }
76  else if(result == 0 && "fileDate".equals(field)) {
77  result = Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
78  if(desc) result *= -1;
79  }
80  else if(!f1.isDirectory() && !f2.isDirectory() && result == 0 && "fileSize".equals(field)) {
81  result = Long.valueOf(f1.length()).compareTo(f2.length());
82  if(desc) result *= -1;
83  }
84  }
85  return result;
86  }

The documentation for this class was generated from the following file: