Statistics
| Revision:

root / trunk / libraries / libIverUtiles / src-test / com / iver / utiles / TestStringComparator.java @ 33213

History | View | Annotate | Download (4.9 KB)

1
package com.iver.utiles;
2

    
3
import java.text.Collator;
4
import java.util.Collections;
5
import java.util.List;
6
import java.util.Locale;
7
import java.util.Vector;
8

    
9
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
10
 *
11
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
12
 *
13
 * This program is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU General Public License
15
 * as published by the Free Software Foundation; either version 2
16
 * of the License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
26
 *
27
 * For more information, contact:
28
 *
29
 *  Generalitat Valenciana
30
 *   Conselleria d'Infraestructures i Transport
31
 *   Av. Blasco Ib??ez, 50
32
 *   46010 VALENCIA
33
 *   SPAIN
34
 *
35
 *      +34 963862235
36
 *   gvsig@gva.es
37
 *      www.gvsig.gva.es
38
 *
39
 *    or
40
 *
41
 *   IVER T.I. S.A
42
 *   Salamanca 50
43
 *   46005 Valencia
44
 *   Spain
45
 *
46
 *   +34 963163400
47
 *   dac@iver.es
48
 */
49

    
50
/**
51
 * Tests the methods of the class <i>StringComparator</i>
52
 * 
53
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
54
 */
55
public class TestStringComparator {
56
        /**
57
         * Test method for the TestMathExtension class
58
         * 
59
         * @param args
60
         */
61
        public static void main(String[] args)
62
        {
63
                StringComparator stringComparator = new StringComparator();
64
                
65
                // Initialize the vector of Strings (for test methods with the parameter Comparator)
66
                Vector v = new Vector();
67
                v.add("extWMS");
68
                v.add("libUI");
69
                v.add("extWMS");
70
                v.add("libRemoteServices");
71
                v.add("extWFS2");
72
                v.add("libNomenclatorIGN");
73
                v.add("libNomenclatorIGN_GUI");
74
                v.add("libIverUtiles");
75
                v.add("extWFS2");
76
                v.add("EXTWFS2");
77
                v.add("extWFS2");
78
                v.add("libGDBMS");
79
                v.add("libInternationalization");
80
                v.add("libFMap");
81
                v.add("6");
82
                v.add("4");
83
                v.add("3");
84
                v.add("5");
85
                v.add("2");
86
                v.add("1");
87
                v.add("extWFS2");
88
                v.add("libExceptions");
89
                v.add("libDriverManager");
90
                v.add("libCq CMS for java");
91
                v.add("libCorePlugin");
92
                v.add("extWFS2");
93
                v.add("extAddIDEELayers");
94
                v.add("extAlertCClient");
95
                v.add("extCAD");
96
                v.add("extWFS2");
97
                v.add("?and?");
98
                v.add("?and?");
99
                v.add("extJDBC");
100
                v.add("extMyPlugin");
101
                v.add("extRasterTools");
102
                v.add("extScripting");
103
                v.add("extWCS");
104
                v.add("extWFS2");
105
                v.add("extwfs2");                // If both are null -> true
106
                v.add("extWMS");
107
                v.add("extWMS");
108
                v.add("extWCS");
109
                v.add("7");
110
                v.add("9");
111
                v.add("8");
112
                v.add("0");
113
                v.add("EXTWCS");
114
                v.add("?and?");
115
                v.add("extensi?n");
116
                v.add("?AND?");
117
                v.add("_fwAndami");
118
                v.add("abcdefghijklmn?opqrstuvwxyz");
119
                v.add("?");
120
                v.add("appgvSIG");
121
                v.add("la casa");
122
                v.add("la monta?a");
123
                v.add("la colina");
124
                v.add("las abejas");
125
                v.add("las nutrias");
126
                v.add("las ballenas");
127
                v.add("lasa?a");
128
                v.add("Vector");
129
                v.add("avi?n");
130
                v.add("cami?n");
131
                v.add("autob?s");
132
                
133
                // Show the original vector
134
                System.out.println("Vector original: " + v.toString() + "\n");
135
                
136
                // First kind of sort
137
                stringComparator.setCaseSensitive(true);
138
                List list = v.subList(0, v.size());
139
                Collections.sort(list, stringComparator);
140
                System.out.println("Ordenaci?n normal con case-sensitive:" + list.toString() + "\n");
141
                
142
                // Second kind of sort
143
                stringComparator.setCaseSensitive(false);
144
                list = v.subList(0, v.size());
145
                Collections.sort(list, stringComparator);
146
                System.out.println("Ordenaci?n normal sin case-sensitive:" + list.toString() + "\n");
147
                
148
                
149
                Collator collator = Collator.getInstance(new Locale("es_ES"));
150
                stringComparator.setLocaleRules(stringComparator.new LocaleRules(true, collator));
151
                
152
                // Third kind of sort
153
                stringComparator.setCaseSensitive(true);
154
                list = v.subList(0, v.size());
155
                Collections.sort(list, stringComparator);
156
                System.out.println("Ordenaci?n con reglas locales y con case-sensitive:" + list.toString() + "\n");
157

    
158
                // Fourth kind of sort
159
                stringComparator.setCaseSensitive(false);
160
                list = v.subList(0, v.size());
161
                Collections.sort(list, stringComparator);
162
                System.out.println("Ordenaci?n con reglas locales y sin case-sensitive:" + list.toString() + "\n");
163
                
164
                
165
                stringComparator.getLocaleRules().setUseLocaleRules(false);
166
                
167
                // Fifth kind of sort
168
                stringComparator.setCaseSensitive(true);
169
                list = v.subList(0, v.size());
170
                Collections.sort(list, stringComparator);
171
                System.out.println("Ordenaci?n normal con case-sensitive:" + list.toString() + "\n");
172

    
173
                // Sixth kind of sort
174
                stringComparator.setCaseSensitive(false);
175
                list = v.subList(0, v.size());
176
                Collections.sort(list, stringComparator);
177
                System.out.println("Ordenaci?n normal sin case-sensitive:" + list.toString() + "\n");
178
        }        
179
}