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

Public Member Functions

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

Detailed Description

Constructor & Destructor Documentation

◆ FileComparator()

org.turro.elephant.documents.FileComparator.FileComparator ( )

Creates a new instance of FileComparator

Definition at line 29 of file Elephant/elephant/src/main/java/org/turro/elephant/documents/FileComparator.java.

29  {
30  }

Member Function Documentation

◆ compare()

int org.turro.elephant.documents.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 45 of file Elephant/elephant/src/main/java/org/turro/elephant/documents/FileComparator.java.

45  {
46  FileDocument fd1 = (FileDocument) o1,
47  fd2 = (FileDocument) o2;
48 
49  String field;
50  boolean desc;
51  int result = 0;
52  for(int i = 0; i < 10 && result == 0; i++) {
53  field = fd1.getDocumentsRoot().readRootConfig("file.ordering." + i + ".name");
54  desc = "desc".equals(fd1.getDocumentsRoot().readRootConfig("file.ordering." + i + ".order"));
55  if(result == 0 && "directory".equals(field)) {
56  if(!fd1.isDirectory() && fd2.isDirectory()) {
57  result = 1;
58  }
59  else if(fd1.isDirectory() && !fd2.isDirectory()) {
60  result = -1;
61  }
62  else {
63  result = 0;
64  }
65  if(desc) result *= -1;
66  }
67  else if(result == 0 && "fileName".equals(field)) {
68  result = fd1.getName().compareTo(fd2.getName());
69  if(desc) result *= -1;
70  }
71  else if(result == 0 && "fileDate".equals(field)) {
72  result = new Long(fd1.lastModified()).compareTo(fd2.lastModified());
73  if(desc) result *= -1;
74  }
75  else if(!fd1.isDirectory() && !fd2.isDirectory() && result == 0 && "fileSize".equals(field)) {
76  result = new Long(fd1.length()).compareTo(fd2.length());
77  if(desc) result *= -1;
78  }
79  }
80  return result;
81  }
Here is the call graph for this function:

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