svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.utils / src / test / java / org / gvsig / utils / TestStringComparator.java @ 40561
History | View | Annotate | Download (5.88 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.utils; |
25 |
|
26 |
import java.text.Collator; |
27 |
import java.util.Collections; |
28 |
import java.util.Locale; |
29 |
import java.util.Vector; |
30 |
import java.util.List; |
31 |
|
32 |
import org.gvsig.utils.StringComparator; |
33 |
|
34 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
35 |
*
|
36 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
37 |
*
|
38 |
* This program is free software; you can redistribute it and/or
|
39 |
* modify it under the terms of the GNU General Public License
|
40 |
* as published by the Free Software Foundation; either version 2
|
41 |
* of the License, or (at your option) any later version.
|
42 |
*
|
43 |
* This program is distributed in the hope that it will be useful,
|
44 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
45 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
46 |
* GNU General Public License for more details.
|
47 |
*
|
48 |
* You should have received a copy of the GNU General Public License
|
49 |
* along with this program; if not, write to the Free Software
|
50 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
51 |
*
|
52 |
* For more information, contact:
|
53 |
*
|
54 |
* Generalitat Valenciana
|
55 |
* Conselleria d'Infraestructures i Transport
|
56 |
* Av. Blasco Ib??ez, 50
|
57 |
* 46010 VALENCIA
|
58 |
* SPAIN
|
59 |
*
|
60 |
* +34 963862235
|
61 |
* gvsig@gva.es
|
62 |
* www.gvsig.gva.es
|
63 |
*
|
64 |
* or
|
65 |
*
|
66 |
* IVER T.I. S.A
|
67 |
* Salamanca 50
|
68 |
* 46005 Valencia
|
69 |
* Spain
|
70 |
*
|
71 |
* +34 963163400
|
72 |
* dac@iver.es
|
73 |
*/
|
74 |
|
75 |
/**
|
76 |
* Tests the methods of the class <i>StringComparator</i>
|
77 |
*
|
78 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
|
79 |
*/
|
80 |
public class TestStringComparator { |
81 |
/**
|
82 |
* Test method for the TestMathExtension class
|
83 |
*
|
84 |
* @param args
|
85 |
*/
|
86 |
public static void main(String[] args) |
87 |
{ |
88 |
StringComparator stringComparator = new StringComparator();
|
89 |
|
90 |
// Initialize the vector of Strings (for test methods with the parameter Comparator)
|
91 |
Vector v = new Vector(); |
92 |
v.add("extWMS");
|
93 |
v.add("libUI");
|
94 |
v.add("extWMS");
|
95 |
v.add("libRemoteServices");
|
96 |
v.add("extWFS2");
|
97 |
v.add("libNomenclatorIGN");
|
98 |
v.add("libNomenclatorIGN_GUI");
|
99 |
v.add("libIverUtiles");
|
100 |
v.add("extWFS2");
|
101 |
v.add("EXTWFS2");
|
102 |
v.add("extWFS2");
|
103 |
v.add("libGDBMS");
|
104 |
v.add("libInternationalization");
|
105 |
v.add("libFMap");
|
106 |
v.add("6");
|
107 |
v.add("4");
|
108 |
v.add("3");
|
109 |
v.add("5");
|
110 |
v.add("2");
|
111 |
v.add("1");
|
112 |
v.add("extWFS2");
|
113 |
v.add("libExceptions");
|
114 |
v.add("libDriverManager");
|
115 |
v.add("libCq CMS for java");
|
116 |
v.add("libCorePlugin");
|
117 |
v.add("extWFS2");
|
118 |
v.add("extAddIDEELayers");
|
119 |
v.add("extAlertCClient");
|
120 |
v.add("extCAD");
|
121 |
v.add("extWFS2");
|
122 |
v.add("?and?");
|
123 |
v.add("?and?");
|
124 |
v.add("extJDBC");
|
125 |
v.add("extMyPlugin");
|
126 |
v.add("extRasterTools");
|
127 |
v.add("extScripting");
|
128 |
v.add("extWCS");
|
129 |
v.add("extWFS2");
|
130 |
v.add("extwfs2"); // If both are null -> true |
131 |
v.add("extWMS");
|
132 |
v.add("extWMS");
|
133 |
v.add("extWCS");
|
134 |
v.add("7");
|
135 |
v.add("9");
|
136 |
v.add("8");
|
137 |
v.add("0");
|
138 |
v.add("EXTWCS");
|
139 |
v.add("?and?");
|
140 |
v.add("extensi?n");
|
141 |
v.add("?AND?");
|
142 |
v.add("_fwAndami");
|
143 |
v.add("abcdefghijklmn?opqrstuvwxyz");
|
144 |
v.add("?");
|
145 |
v.add("appgvSIG");
|
146 |
v.add("la casa");
|
147 |
v.add("la monta?a");
|
148 |
v.add("la colina");
|
149 |
v.add("las abejas");
|
150 |
v.add("las nutrias");
|
151 |
v.add("las ballenas");
|
152 |
v.add("lasa?a");
|
153 |
v.add("Vector");
|
154 |
v.add("avi?n");
|
155 |
v.add("cami?n");
|
156 |
v.add("autob?s");
|
157 |
|
158 |
// Show the original vector
|
159 |
System.out.println("Vector original: " + v.toString() + "\n"); |
160 |
|
161 |
// First kind of sort
|
162 |
stringComparator.setCaseSensitive(true);
|
163 |
List list = v.subList(0, v.size()); |
164 |
Collections.sort(list, stringComparator);
|
165 |
System.out.println("Ordenaci?n normal con case-sensitive:" + list.toString() + "\n"); |
166 |
|
167 |
// Second kind of sort
|
168 |
stringComparator.setCaseSensitive(false);
|
169 |
list = v.subList(0, v.size());
|
170 |
Collections.sort(list, stringComparator);
|
171 |
System.out.println("Ordenaci?n normal sin case-sensitive:" + list.toString() + "\n"); |
172 |
|
173 |
|
174 |
Collator collator = Collator.getInstance(new Locale("es_ES")); |
175 |
stringComparator.setLocaleRules(stringComparator.new LocaleRules(true, collator));
|
176 |
|
177 |
// Third kind of sort
|
178 |
stringComparator.setCaseSensitive(true);
|
179 |
list = v.subList(0, v.size());
|
180 |
Collections.sort(list, stringComparator);
|
181 |
System.out.println("Ordenaci?n con reglas locales y con case-sensitive:" + list.toString() + "\n"); |
182 |
|
183 |
// Fourth kind of sort
|
184 |
stringComparator.setCaseSensitive(false);
|
185 |
list = v.subList(0, v.size());
|
186 |
Collections.sort(list, stringComparator);
|
187 |
System.out.println("Ordenaci?n con reglas locales y sin case-sensitive:" + list.toString() + "\n"); |
188 |
|
189 |
|
190 |
stringComparator.getLocaleRules().setUseLocaleRules(false);
|
191 |
|
192 |
// Fifth kind of sort
|
193 |
stringComparator.setCaseSensitive(true);
|
194 |
list = v.subList(0, v.size());
|
195 |
Collections.sort(list, stringComparator);
|
196 |
System.out.println("Ordenaci?n normal con case-sensitive:" + list.toString() + "\n"); |
197 |
|
198 |
// Sixth kind of sort
|
199 |
stringComparator.setCaseSensitive(false);
|
200 |
list = v.subList(0, v.size());
|
201 |
Collections.sort(list, stringComparator);
|
202 |
System.out.println("Ordenaci?n normal sin case-sensitive:" + list.toString() + "\n"); |
203 |
} |
204 |
} |