8000 Add Comparator toString() implementations · apache/commons-io@b03cc28 · GitHub
Skip to content

Commit b03cc28

Browse files
author
Niall Pemberton
committed
Add Comparator toString() implementations
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@721740 13f79535-47bb-0310-9956-ffa450edef68
1 parent e2d0dce commit b03cc28

6 files changed

Lines changed: 55 additions & 0 deletions

File tree

src/java/org/apache/commons/io/comparator/AbstractFileComparator.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,14 @@ public List<File> sort(List<File> files) {
6161
}
6262
return files;
6363
}
64+
65+
/**
66+
* String representation of this file comparator.
67+
*
68+
* @return String representation of this file comparator
69+
*/
70+
public String toString() {
71+
String className = getClass().getName();
72+
return className.substring(className.lastIndexOf('.') + 1);
73+
}
6474
}

src/java/org/apache/commons/io/comparator/ExtensionFileComparator.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,13 @@ public int compare(File file1, File file2) {
107107
String suffix2 = FilenameUtils.getExtension(file2.getName());
108108
return caseSensitivity.checkCompareTo(suffix1, suffix2);
109109
}
110+
111+
/**
112+
* String representation of this file comparator.
113+
*
114+
* @return String representation of this file comparator
115+
*/
116+
public String toString() {
117+
return super.toString() + "[caseSensitivity=" + caseSensitivity + "]";
118+
}
110119
}

src/java/org/apache/commons/io/comparator/NameFileComparator.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,13 @@ public NameFileComparator(IOCase caseSensitivity) {
101101
public int compare(File file1, File file2) {
102102
return caseSensitivity.checkCompareTo(file1.getName(), file2.getName());
103103
}
104+
105+
/**
106+
* String representation of this file comparator.
107+
*
108+
* @return String representation of this file comparator
109+
*/
110+
public String toString() {
111+
return super.toString() + "[caseSensitivity=" + caseSensitivity + "]";
112+
}
104113
}

src/java/org/apache/commons/io/comparator/PathFileComparator.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,13 @@ public PathFileComparator(IOCase caseSensitivity) {
102102
public int compare(File file1, File file2) {
103103
return caseSensitivity.checkCompareTo(file1.getPath(), file2.getPath());
104104
}
105+
106+
/**
107+
* String representation of this file comparator.
108+
*
109+
* @return String representation of this file comparator
110+
*/
111+
public String toString() {
112+
return super.toString() + "[caseSensitivity=" + caseSensitivity + "]";
113+
}
105114
}

src/java/org/apache/commons/io/comparator/ReverseComparator.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,13 @@ public int compare(File file1, File file2) {
5555
return delegate.compare(file2, file1); // parameters switched round
5656
}
5757

58+
/**
59+
* String representation of this file comparator.
60+
*
61+
* @return String representation of this file comparator
62+
*/
63+
public String toString() {
64+
return super.toString() + "[" + delegate.toString() + "]";
65+
}
66+
5867
}

src/java/org/apache/commons/io/comparator/SizeFileComparator.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,13 @@ public int compare(File file1, File file2) {
127127
return 0;
128128
}
129129
}
130+
131+
/**
132+
* String representation of this file comparator.
133+
*
134+
* @return String representation of this file comparator
135+
*/
136+
public String toString() {
137+
return super.toString() + "[sumDirectoryContents=" + sumDirectoryContents + "]";
138+
}
130139
}

0 commit comments

Comments
 (0)