This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 139753
Collapse All | Expand All

(-)openide.loaders/apichanges.xml (+25 lines)
Lines 109-114 Link Here
109
<!-- ACTUAL CHANGES BEGIN HERE: -->
109
<!-- ACTUAL CHANGES BEGIN HERE: -->
110
110
111
  <changes>
111
  <changes>
112
      <change id="org.netbeans.modules.masterfs.case">
113
          <api name="loaders"/>
114
          <summary>Introduces a system property to override case-sensitive ordering of DataFolder's children.</summary>
115
          <version major="7" minor="67"/>
116
          <date day="31" month="8" year="2016"/>
117
          <author login="markiewb"/>
118
          <compatibility addition="yes" binary="compatible" source="compatible"
119
                         semantic="compatible" deprecation="no" deletion="no"
120
                         modification="no"/>
121
          <description>
122
              The case-sensitivity behaviour for ordering children (folders and files) of a Datafolder can be overriden by a system property named <code>org.netbeans.modules.masterfs.case</code>.
123
              <p>
124
                  It can be set to
125
                  <code>sensitive</code>
126
                  or
127
                  <code>insensitive</code>
128
                  value in order to override the system default.
129
              </p>
130
              This property has been already introduced into "masterfs" to address problems when mixing various types of network file systems (as described in bug
131
              <a href="http://netbeans.org/bugzilla/show_bug.cgi?id=198946">198946</a>
132
              )  
133
          </description>
134
          <class package="org.openide.loaders" name="DataFolder"/>
135
          <issue number="139753"/>
136
      </change>
112
      <change id="org.openide.loaders.DataFolder.SortMode.NATURAL">
137
      <change id="org.openide.loaders.DataFolder.SortMode.NATURAL">
113
          <api name="loaders"/>
138
          <api name="loaders"/>
114
          <summary>Introduces SortMode for natural sorting.</summary>
139
          <summary>Introduces SortMode for natural sorting.</summary>
(-)openide.loaders/arch.xml (+14 lines)
Lines 533-538 Link Here
533
        between successive refreshes of contents of a folder. Can be used to tweak
533
        between successive refreshes of contents of a folder. Can be used to tweak
534
        performance of folder refresh. Defaults to 10.
534
        performance of folder refresh. Defaults to 10.
535
    </api>
535
    </api>
536
537
    <api name="org.netbeans.modules.masterfs.case" category="private" group="systemproperty" type="export">
538
        The case-sensitivity behaviour for ordering children (folders and files) of a Datafolder can be overriden by a system property named <code>org.netbeans.modules.masterfs.case</code>.
539
        <p>
540
            It can be set to
541
            <code>sensitive</code>
542
            or
543
            <code>insensitive</code>
544
            value in order to override the system default.
545
        </p>
546
        This property has been already introduced into "masterfs" to address problems when mixing various types of network file systems (as described in bug
547
        <a href="http://netbeans.org/bugzilla/show_bug.cgi?id=198946">198946</a>
548
        ) 
549
    </api>
536
    
550
    
537
    <api group="systemproperty" category="friend" name="netbeans.dataobject.insecure.operation" type="export" >
551
    <api group="systemproperty" category="friend" name="netbeans.dataobject.insecure.operation" type="export" >
538
        If set to <b>true</b>, the <code>DataObject.copy, move, createFromTemplate</code> 
552
        If set to <b>true</b>, the <code>DataObject.copy, move, createFromTemplate</code> 
(-)openide.loaders/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.loaders
2
OpenIDE-Module: org.openide.loaders
3
OpenIDE-Module-Specification-Version: 7.66
3
OpenIDE-Module-Specification-Version: 7.67
4
OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties
5
OpenIDE-Module-Provides: org.netbeans.modules.templates.v1_0
5
OpenIDE-Module-Provides: org.netbeans.modules.templates.v1_0
6
OpenIDE-Module-Layer: org/netbeans/modules/openide/loaders/layer.xml
6
OpenIDE-Module-Layer: org/netbeans/modules/openide/loaders/layer.xml
(-)openide.loaders/src/org/openide/loaders/FolderComparator.java (-8 / +67 lines)
Lines 49-54 Link Here
49
import java.util.Enumeration;
49
import java.util.Enumeration;
50
import org.openide.filesystems.FileObject;
50
import org.openide.filesystems.FileObject;
51
import org.openide.nodes.Node;
51
import org.openide.nodes.Node;
52
import org.openide.util.BaseUtilities;
52
53
53
/**
54
/**
54
 * Compares objects in a folder.
55
 * Compares objects in a folder.
Lines 148-156 Link Here
148
        return obj;
149
        return obj;
149
    }
150
    }
150
151
152
    /**
153
     * Compares two strings (f.e. filenames, filename extentsion or path elements) lexiographically.
154
     * <p>
155
     * The compare is done case-sensitive by default.
156
     * </p>
157
     * <p>
158
     * The case-sensitivity can be altered by the system property "<code>org.netbeans.modules.masterfs.case</code>", which was introduced in #198946.
159
     * <ul>
160
     * <li>
161
     * If the property value is "<code>sensitive</code>", then the compare is case-sensitive.
162
     * </li>
163
     * <li>
164
     * If the property value is "<code>insensitive</code>", then the compare is case-insensitive.
165
     * </li>
166
     * <li>
167
     * If the property isn't set (=<code>null</code>), then the compare is case-sensitive (for backward-compatibility reasons).
168
     * </li>
169
     * </ul>
170
     * </p>
171
     * @since 7.67
172
     */
173
    private static int compare(String o1, String o2) {
174
        /*
175
         * backwards compatibility
176
         */
177
        if (SENSITIVE == null) {
178
            return o1.compareTo(o2);
179
        }
180
        if (Boolean.TRUE.equals(SENSITIVE)) {
181
            return o1.compareTo(o2);
182
        } else {
183
            return o1.compareToIgnoreCase(o2);
184
        }
185
    }
186
    
151
    /** for sorting data objects by names */
187
    /** for sorting data objects by names */
152
    private int compareNames(Object o1, Object o2) {     
188
    private int compareNames(Object o1, Object o2) {     
153
        return findFileObject(o1).getNameExt().compareTo(findFileObject(o2).getNameExt());
189
        return compare(findFileObject(o1).getNameExt(), findFileObject(o2).getNameExt());
154
    }
190
    }
155
191
156
    /** for sorting folders first and then by names */
192
    /** for sorting folders first and then by names */
Lines 177-190 Link Here
177
        if (folder1 != folder2) {
213
        if (folder1 != folder2) {
178
            return folder1 ? -1 : 1; // folders first
214
            return folder1 ? -1 : 1; // folders first
179
        } else if (folder1) { // && folder2
215
        } else if (folder1) { // && folder2
180
            return obj1.getNameExt().compareTo(obj2.getNameExt()); // by nameExt
216
            return compare(obj1.getNameExt(), obj2.getNameExt()); // by nameExt
181
        } else {
217
        } else {
182
            String ext1 = obj1.getExt();
218
            String ext1 = obj1.getExt();
183
            String ext2 = obj2.getExt();
219
            String ext2 = obj2.getExt();
184
            if (ext1.equals(ext2)) { // same extensions
220
            if (ext1.equals(ext2)) { // same extensions
185
                return obj1.getName().compareTo(obj2.getName()); // by name
221
                return compare(obj1.getName(), obj2.getName()); // by name
186
            } else { // different extensions
222
            } else { // different extensions
187
                return ext1.compareTo(ext2); // by extension
223
                return compare(ext1, ext2); // by extension
188
            }
224
            }
189
        }
225
        }
190
    }
226
    }
Lines 245-251 Link Here
245
        } else if (d2.after(d1)) {
281
        } else if (d2.after(d1)) {
246
            return 1;
282
            return 1;
247
        } else {
283
        } else {
248
            return fo1.getNameExt().compareTo(fo2.getNameExt());
284
            return compare(fo1.getNameExt(), fo2.getNameExt());
249
        }
285
        }
250
    }
286
    }
251
287
Lines 269-275 Link Here
269
        } else if (s2 > s1) {
305
        } else if (s2 > s1) {
270
            return 1;
306
            return 1;
271
        } else {
307
        } else {
272
            return fo1.getNameExt().compareTo(fo2.getNameExt());
308
            return compare(fo1.getNameExt(), fo2.getNameExt());
273
        }
309
        }
274
    }
310
    }
275
311
Lines 323-336 Link Here
323
        boolean unfinished1 = p1 < n1.length();
359
        boolean unfinished1 = p1 < n1.length();
324
        boolean unfinished2 = p2 < n2.length();
360
        boolean unfinished2 = p2 < n2.length();
325
        if (!unfinished1 && !unfinished2) {
361
        if (!unfinished1 && !unfinished2) {
326
            return name1.compareTo(name2);
362
            return compare(name1, name2);
327
        } else if (unfinished1) {
363
        } else if (unfinished1) {
328
            return 1; // first string is longer (prefix of second string)
364
            return 1; // first string is longer (prefix of second string)
329
        } else if (unfinished2) {
365
        } else if (unfinished2) {
330
            return -1; // second string is longer (prefix of first string)
366
            return -1; // second string is longer (prefix of first string)
331
        } else {
367
        } else {
332
            assert false : "Invalid state in natural comparator";       //NOI18N
368
            assert false : "Invalid state in natural comparator";       //NOI18N
333
            return n1.compareTo(n2);
369
            return compare(n1, n2);
334
        }
370
        }
335
    }
371
    }
336
372
Lines 392-395 Link Here
392
            return endPos;
428
            return endPos;
393
        }
429
        }
394
    }
430
    }
431
432
    /**
433
     * #139753 Copied from org.netbeans.modules.masterfs.filebasedfs.utils.Utils to prevent dependency to masterfs.
434
     */
435
    private static final Boolean SENSITIVE = findCase();
436
    
437
    /**
438
     * #139753 Copied from org.netbeans.modules.masterfs.filebasedfs.utils.Utils to prevent dependency to masterfs.
439
     */
440
    private static Boolean findCase() {
441
        String userDef = System.getProperty("org.netbeans.modules.masterfs.case"); // NOI18N
442
        if ("insensitive".equals(userDef)) { // NOI18N
443
            return false;
444
        } 
445
        if ("sensitive".equals(userDef)) { // NOI18N
446
            return true;
447
        }
448
        assert userDef == null : "Wrong value " + userDef;
449
        if (BaseUtilities.isMac()) {
450
            return false;
451
        }
452
        return null;
453
    }
395
}
454
}
(-)openide.loaders/test/unit/src/org/openide/loaders/FolderComparatorCaseInsensitiveTest.java (+208 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2015 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2015 Sun Microsystems, Inc.
41
 */
42
package org.openide.loaders;
43
44
import java.awt.EventQueue;
45
import java.io.IOException;
46
import java.lang.reflect.InvocationTargetException;
47
import java.util.ArrayList;
48
import java.util.Collections;
49
import java.util.List;
50
import static junit.framework.TestCase.assertEquals;
51
import static junit.framework.TestCase.assertNotNull;
52
import org.junit.After;
53
import org.junit.Before;
54
import org.junit.Test;
55
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileSystem;
57
import org.openide.filesystems.FileUtil;
58
59
/**
60
 *
61
 * @author jhavlin
62
 */
63
public class FolderComparatorCaseInsensitiveTest {
64
65
    private String backup;
66
67
    public FolderComparatorCaseInsensitiveTest() {
68
    }
69
70
    @Before
71
    public void _before() {
72
        backup = System.getProperty("org.netbeans.modules.masterfs.case");
73
        System.setProperty("org.netbeans.modules.masterfs.case", "insensitive");
74
    }
75
76
    @After
77
    public void _after() {
78
        if (null != backup) {
79
            System.setProperty("org.netbeans.modules.masterfs.case", backup);
80
        }
81
    }
82
    
83
84
    @Test
85
    public void testNaturalComparatorBasic() throws IOException {
86
        testNaturalComparator(new String[]{
87
            "b 10.txt",
88
            "b 9.txt",
89
            "a2.txt",
90
            "a 4 9.txt",
91
            "a10.txt",
92
            "b0070.txt",
93
            "a 3.txt",
94
            "b08.txt"
95
        }, new String[]{
96
            "a2.txt",
97
            "a 3.txt",
98
            "a 4 9.txt",
99
            "a10.txt",
100
            "b08.txt",
101
            "b 9.txt",
102
            "b 10.txt",
103
            "b0070.txt"
104
        });
105
    }
106
107
    @Test
108
    public void testNaturalComparatorWithSuffixes() throws IOException {
109
        testNaturalComparator(new String[]{
110
            "a01b",
111
            "a2x",
112
            "a02",
113
            "a1"
114
        }, new String[]{
115
            "a1",
116
            "a01b",
117
            "a02",
118
            "a2x"
119
        });
120
    }
121
122
    @Test
123
    public void testUseCustomComparator() throws IOException,
124
            InterruptedException, InvocationTargetException {
125
126
        FileSystem fs = FileUtil.createMemoryFileSystem();
127
128
        fs.getRoot().createData("aaaa.txt");
129
        fs.getRoot().createData("bbb.txt");
130
        fs.getRoot().createData("cc.txt");
131
        fs.getRoot().createData("d.txt");
132
        fs.getRoot().refresh();
133
134
        DataFolder.SortMode custom = new DataFolder.SortMode() {
135
            @Override
136
            public int compare(DataObject o1, DataObject o2) {
137
                return o1.getName().length() - o2.getName().length();
138
            }
139
        };
140
141
        DataFolder df = DataFolder.findFolder(fs.getRoot());
142
        df.setSortMode(custom);
143
        EventQueue.invokeAndWait(new Runnable() {
144
            @Override
145
            public void run() {
146
            }
147
        });
148
        DataObject[] children = df.getChildren();
149
        assertEquals("d.txt", children[0].getName());
150
        assertEquals("cc.txt", children[1].getName());
151
        assertEquals("bbb.txt", children[2].getName());
152
        assertEquals("aaaa.txt", children[3].getName());
153
    }
154
155
    @Test
156
    public void testNaturalComparatorFallback() throws IOException {
157
        testNaturalComparator(new String[]{
158
            "a01.txt",
159
            "a001.txt",
160
            "A1.txt"
161
        }, new String[]{
162
            "a001.txt",
163
            "a01.txt",
164
            "A1.txt",
165
        });
166
    }
167
168
    /**
169
     * #139753 - test if "org.netbeans.modules.masterfs.case=insensitive" is used.
170
     *
171
     * @throws IOException
172
     */
173
    @Test
174
    public void testCaseSensitivity() throws IOException {
175
        testComparator(new String[]{
176
            "CustomerInvoice.txt",
177
            "Customerappro.txt",
178
            "CustomerABC.txt",
179
            "Customerinterview.txt"
180
        }, new String[]{
181
            "CustomerABC.txt",
182
            "Customerappro.txt",
183
            "Customerinterview.txt",
184
            "CustomerInvoice.txt",}, FolderComparator.FOLDER_NAMES);
185
    }
186
187
    private void testComparator(String[] fileNames, String[] expectedOrder, int mode) throws IOException {
188
        FolderComparator c = new FolderComparator(mode);
189
        FileSystem fs = FileUtil.createMemoryFileSystem();
190
        FileObject root = fs.getRoot();
191
        List<DataObject> list = new ArrayList<DataObject>();
192
        for (String n : fileNames) {
193
            FileObject fo = root.createData(n);
194
            assertNotNull(fo);
195
            list.add(DataObject.find(fo));
196
        }
197
198
        Collections.sort(list, c);
199
        for (int i = 0; i < expectedOrder.length; i++) {
200
            assertEquals(expectedOrder[i], list.get(i).getName());
201
        }
202
    }
203
    
204
    private void testNaturalComparator(String[] fileNames,
205
            String[] expectedOrder) throws IOException {
206
        testComparator(fileNames, expectedOrder, FolderComparator.NATURAL);
207
    }
208
}
(-)openide.loaders/test/unit/src/org/openide/loaders/FolderComparatorCaseSensitiveTest.java (+208 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2015 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2015 Sun Microsystems, Inc.
41
 */
42
package org.openide.loaders;
43
44
import java.awt.EventQueue;
45
import java.io.IOException;
46
import java.lang.reflect.InvocationTargetException;
47
import java.util.ArrayList;
48
import java.util.Collections;
49
import java.util.List;
50
import static junit.framework.TestCase.assertEquals;
51
import static junit.framework.TestCase.assertNotNull;
52
import org.junit.After;
53
import org.junit.Before;
54
import org.junit.Test;
55
import org.openide.filesystems.FileObject;
56
import org.openide.filesystems.FileSystem;
57
import org.openide.filesystems.FileUtil;
58
59
/**
60
 *
61
 * @author jhavlin
62
 */
63
public class FolderComparatorCaseSensitiveTest {
64
65
    private String backup;
66
67
    public FolderComparatorCaseSensitiveTest() {
68
    }
69
70
    @Before
71
    public void _before() {
72
        backup = System.getProperty("org.netbeans.modules.masterfs.case");
73
        System.setProperty("org.netbeans.modules.masterfs.case", "sensitive");
74
    }
75
76
    @After
77
    public void _after() {
78
        if (null != backup) {
79
            System.setProperty("org.netbeans.modules.masterfs.case", backup);
80
        }
81
    }
82
    
83
84
    @Test
85
    public void testNaturalComparatorBasic() throws IOException {
86
        testNaturalComparator(new String[]{
87
            "b 10.txt",
88
            "b 9.txt",
89
            "a2.txt",
90
            "a 4 9.txt",
91
            "a10.txt",
92
            "b0070.txt",
93
            "a 3.txt",
94
            "b08.txt"
95
        }, new String[]{
96
            "a2.txt",
97
            "a 3.txt",
98
            "a 4 9.txt",
99
            "a10.txt",
100
            "b08.txt",
101
            "b 9.txt",
102
            "b 10.txt",
103
            "b0070.txt"
104
        });
105
    }
106
107
    @Test
108
    public void testNaturalComparatorWithSuffixes() throws IOException {
109
        testNaturalComparator(new String[]{
110
            "a01b",
111
            "a2x",
112
            "a02",
113
            "a1"
114
        }, new String[]{
115
            "a1",
116
            "a01b",
117
            "a02",
118
            "a2x"
119
        });
120
    }
121
122
    @Test
123
    public void testUseCustomComparator() throws IOException,
124
            InterruptedException, InvocationTargetException {
125
126
        FileSystem fs = FileUtil.createMemoryFileSystem();
127
128
        fs.getRoot().createData("aaaa.txt");
129
        fs.getRoot().createData("bbb.txt");
130
        fs.getRoot().createData("cc.txt");
131
        fs.getRoot().createData("d.txt");
132
        fs.getRoot().refresh();
133
134
        DataFolder.SortMode custom = new DataFolder.SortMode() {
135
            @Override
136
            public int compare(DataObject o1, DataObject o2) {
137
                return o1.getName().length() - o2.getName().length();
138
            }
139
        };
140
141
        DataFolder df = DataFolder.findFolder(fs.getRoot());
142
        df.setSortMode(custom);
143
        EventQueue.invokeAndWait(new Runnable() {
144
            @Override
145
            public void run() {
146
            }
147
        });
148
        DataObject[] children = df.getChildren();
149
        assertEquals("d.txt", children[0].getName());
150
        assertEquals("cc.txt", children[1].getName());
151
        assertEquals("bbb.txt", children[2].getName());
152
        assertEquals("aaaa.txt", children[3].getName());
153
    }
154
155
    @Test
156
    public void testNaturalComparatorFallback() throws IOException {
157
        testNaturalComparator(new String[]{
158
            "a01.txt",
159
            "a001.txt",
160
            "A1.txt"
161
        }, new String[]{
162
            "A1.txt",
163
            "a001.txt",
164
            "a01.txt"
165
        });
166
    }
167
168
    /**
169
     * #139753 - test if "org.netbeans.modules.masterfs.case=sensitive" is used.
170
     *
171
     * @throws IOException
172
     */
173
    @Test
174
    public void testCaseSensitivity() throws IOException {
175
        testComparator(new String[]{
176
            "CustomerInvoice.txt",
177
            "Customerappro.txt",
178
            "CustomerABC.txt",
179
            "Customerinterview.txt"
180
        }, new String[]{
181
            "CustomerABC.txt",
182
            "CustomerInvoice.txt",
183
            "Customerappro.txt",
184
            "Customerinterview.txt",}, FolderComparator.FOLDER_NAMES);
185
    }
186
187
    private void testComparator(String[] fileNames, String[] expectedOrder, int mode) throws IOException {
188
        FolderComparator c = new FolderComparator(mode);
189
        FileSystem fs = FileUtil.createMemoryFileSystem();
190
        FileObject root = fs.getRoot();
191
        List<DataObject> list = new ArrayList<DataObject>();
192
        for (String n : fileNames) {
193
            FileObject fo = root.createData(n);
194
            assertNotNull(fo);
195
            list.add(DataObject.find(fo));
196
        }
197
198
        Collections.sort(list, c);
199
        for (int i = 0; i < expectedOrder.length; i++) {
200
            assertEquals(expectedOrder[i], list.get(i).getName());
201
        }
202
    }
203
    
204
    private void testNaturalComparator(String[] fileNames,
205
            String[] expectedOrder) throws IOException {
206
        testComparator(fileNames, expectedOrder, FolderComparator.NATURAL);
207
    }
208
}

Return to bug 139753