Revision 33813
tags/v2_0_0_Build_2020/applications/appgvSIG/package.info | ||
---|---|---|
1 |
# |
|
2 |
#Tue Oct 26 12:06:08 CEST 2010 |
|
3 |
state=devel |
|
4 |
name=appgvSIG |
|
5 |
official=true |
|
6 |
code=org.gvsig.app |
|
7 |
operating-system=all |
|
8 |
architecture=all |
|
9 |
java-version=j1_5 |
|
10 |
gvSIG-version=2.0.0 |
|
11 |
version=2.0-SNAPSHOT |
|
12 |
type=plugin |
|
13 |
build=2020 |
|
14 |
description=This is the plugin that contains the \n\tgvSIG application main extensions |
tags/v2_0_0_Build_2020/applications/appgvSIG/scripts/zopeConnection.xml | ||
---|---|---|
1 |
<project basedir="../.." default="default" name="connectionData"> |
|
2 |
|
|
3 |
<property name="basedir" location=".."/> |
|
4 |
<property name="passw" value="dokdeploy"/> |
|
5 |
<property name="server" value="192.168.0.1"/> |
|
6 |
<property name="port" value="10022"/> |
|
7 |
<property name="user" value="dokdeploy"/> |
|
8 |
<property name="remoteDir1" value="/docdev/v1_0/apireference"/> |
|
9 |
<property name="remoteDir2" value="/plone/docdev/es/v1_0/apireference"/> |
|
10 |
<property name="ftp-passive" value="yes"/> |
|
11 |
<property name="verbose" value="no"/> |
|
12 |
|
|
13 |
<target name="default"> |
|
14 |
<ant antfile="appgvSIG/scripts/buildApi.xml" target="deployAPIReference" inheritAll="true"/> |
|
15 |
</target> |
|
16 |
|
|
17 |
</project> |
|
0 | 18 |
tags/v2_0_0_Build_2020/applications/appgvSIG/scripts/buildApi.xml | ||
---|---|---|
1 |
<project basedir=".." name="build" default="buildAPIReference"> |
|
2 |
<!-- |
|
3 |
Note: the replacement in html links uses lots of memory, this script should |
|
4 |
be launched using the -Xmx512M parameter for the JVM. |
|
5 |
--> |
|
6 |
<property name="tmpSourceDir" value="/tmp/tmp-sources"/> |
|
7 |
<property name="apiReferenceDir" value="/tmp/docs/dist/html/APIReference"/> |
|
8 |
|
|
9 |
<property name="passw" value="my_password"/> |
|
10 |
<property name="server" value="my_server"/> |
|
11 |
<property name="port" value="6666"/> |
|
12 |
<property name="user" value="my_user"/> |
|
13 |
<property name="remoteDir1" value="/remoteDir1"/> |
|
14 |
<property name="remoteDir2" value="/remoteDir2"/> |
|
15 |
<property name="encoding" value="ISO-8859-1"/> |
|
16 |
<property name="ftp-passive" value="yes"/> |
|
17 |
<property name="verbose" value="yes"/> |
|
18 |
|
|
19 |
<!--=======================================================================--> |
|
20 |
|
|
21 |
<!-- Deploy del API --> |
|
22 |
<target name="deployAPIReference" depends="buildAPIReference"> |
|
23 |
<!-- zope no acepta directorios llamados 'values' --> |
|
24 |
<antcall target="renameFiles"> |
|
25 |
<param name="targetDir" value="${apiReferenceDir}" /> |
|
26 |
<param name="oldValue" value="/values"/> |
|
27 |
<param name="newValue" value="/values_" /> |
|
28 |
</antcall> |
|
29 |
<antcall target="replaceInLinks"> |
|
30 |
<param name="targetDir" value="${apiReferenceDir}" /> |
|
31 |
<param name="oldValue" value="/values"/> |
|
32 |
<param name="newValue" value="/values_" /> |
|
33 |
</antcall> |
|
34 |
<!-- Deploy del API en el directorio no Plone--> |
|
35 |
<antcall target="deleteRemoteFiles"> |
|
36 |
<param name="remoteDir" value="${remoteDir1}"/> |
|
37 |
<param name="excludeFiles" value=""/> |
|
38 |
</antcall> |
|
39 |
<antcall target="deleteRemoteDirs"> |
|
40 |
<param name="remoteDir" value="${remoteDir1}"/> |
|
41 |
<param name="excludeDirs" value=""/> |
|
42 |
</antcall> |
|
43 |
<echo>apiReferenceDir ${apiReferenceDir} |
|
44 |
remoteDir1: ${remoteDir1}" |
|
45 |
</echo> |
|
46 |
<antcall target="copyFilesToRemote"> |
|
47 |
<param name="sourceDir" value="${apiReferenceDir}"/> |
|
48 |
<param name="remoteDir" value="${remoteDir1}"/> |
|
49 |
</antcall> |
|
50 |
<!-- |
|
51 |
No queremos crear el .zip con la API |
|
52 |
<antcall target="makeZipFile" |
|
53 |
description="Crea un fichero .zip con la documentacion del api"> |
|
54 |
<param name="dstDir" value="${basedir}/docs/dist/zip/apiref.zip"/> |
|
55 |
<param name="srcDir" value="${apiReferenceDir}"/> |
|
56 |
</antcall> |
|
57 |
<antcall target="copyFilesToRemote" |
|
58 |
description="Copia el fichero apiref.zip al directorio remoto"> |
|
59 |
<param name="sourceDir" value="${basedir}/docs/dist/zip"/> |
|
60 |
<param name="remoteDir" value="${remoteDir}/portal2"/> |
|
61 |
</antcall> --> |
|
62 |
|
|
63 |
<!-- Deploy del API en el directorio Plone--> |
|
64 |
<!-- Plone no acepta directorios llamados 'search' --> |
|
65 |
<antcall target="renameFiles"> |
|
66 |
<param name="targetDir" value="${apiReferenceDir}" /> |
|
67 |
<param name="oldValue" value="/search"/> |
|
68 |
<param name="newValue" value="/search_" /> |
|
69 |
</antcall> |
|
70 |
<antcall target="replaceInLinks"> |
|
71 |
<param name="targetDir" value="${apiReferenceDir}" /> |
|
72 |
<param name="oldValue" value="/search"/> |
|
73 |
<param name="newValue" value="/search_" /> |
|
74 |
</antcall> |
|
75 |
<antcall target="renameFiles"> |
|
76 |
<param name="targetDir" value="${apiReferenceDir}" /> |
|
77 |
<param name="oldValue" value="/layout"/> |
|
78 |
<param name="newValue" value="/layout_" /> |
|
79 |
</antcall> |
|
80 |
<antcall target="replaceInLinks"> |
|
81 |
<param name="targetDir" value="${apiReferenceDir}" /> |
|
82 |
<param name="oldValue" value="/layout"/> |
|
83 |
<param name="newValue" value="/layout_" /> |
|
84 |
</antcall> |
|
85 |
<antcall target="renameFiles"> |
|
86 |
<param name="targetDir" value="${apiReferenceDir}" /> |
|
87 |
<param name="oldValue" value="/actions"/> |
|
88 |
<param name="newValue" value="/actions_" /> |
|
89 |
</antcall> |
|
90 |
<antcall target="replaceInLinks"> |
|
91 |
<param name="targetDir" value="${apiReferenceDir}" /> |
|
92 |
<param name="oldValue" value="/actions"/> |
|
93 |
<param name="newValue" value="/actions_" /> |
|
94 |
</antcall> |
|
95 |
<antcall target="renameFiles"> |
|
96 |
<param name="targetDir" value="${apiReferenceDir}" /> |
|
97 |
<param name="oldValue" value="/view"/> |
|
98 |
<param name="newValue" value="/view_" /> |
|
99 |
</antcall> |
|
100 |
<antcall target="replaceInLinks"> |
|
101 |
<param name="targetDir" value="${apiReferenceDir}" /> |
|
102 |
<param name="oldValue" value="/view"/> |
|
103 |
<param name="newValue" value="/view_" /> |
|
104 |
</antcall> |
|
105 |
<antcall target="renameFiles"> |
|
106 |
<param name="targetDir" value="${apiReferenceDir}" /> |
|
107 |
<param name="oldValue" value="/properties"/> |
|
108 |
<param name="newValue" value="/properties_" /> |
|
109 |
</antcall> |
|
110 |
<antcall target="replaceInLinks"> |
|
111 |
<param name="targetDir" value="${apiReferenceDir}" /> |
|
112 |
<param name="oldValue" value="/properties"/> |
|
113 |
<param name="newValue" value="/properties_" /> |
|
114 |
</antcall> |
|
115 |
<antcall target="deleteRemoteFiles"> |
|
116 |
<param name="remoteDir" value="${remoteDir2}"/> |
|
117 |
<param name="excludeFiles" value="${remoteDir2}/indice.html"/> |
|
118 |
</antcall> |
|
119 |
<antcall target="deleteRemoteDirs"> |
|
120 |
<param name="remoteDir" value="${remoteDir2}"/> |
|
121 |
<param name="excludeDirs" value=""/> |
|
122 |
</antcall> |
|
123 |
<echo>apiReferenceDir ${apiReferenceDir} |
|
124 |
remoteDir1: ${remoteDir1}" |
|
125 |
</echo> |
|
126 |
<antcall target="copyFilesToRemote"> |
|
127 |
<param name="sourceDir" value="${apiReferenceDir}"/> |
|
128 |
<param name="remoteDir" value="${remoteDir2}"/> |
|
129 |
</antcall> |
|
130 |
</target> |
|
131 |
|
|
132 |
<target name="buildAPIReference" |
|
133 |
description="Crea el documento Javadoc del componente"> |
|
134 |
<delete dir="${apiReferenceDir}" /> |
|
135 |
<mkdir dir="${apiReferenceDir}"/> |
|
136 |
<echo>Basedir: ${basedir}</echo> |
|
137 |
<echo>Output dir: ${apiReferenceDir}</echo> |
|
138 |
<!-- |
|
139 |
Copy the packaes from all the projects to a temporary directory. |
|
140 |
We need only one directory to properly generate the Javadocs. |
|
141 |
--> |
|
142 |
<delete dir="${tmpSourceDir}" failonerror="false"/> |
|
143 |
<mkdir dir="${tmpSourceDir}"/> |
|
144 |
<copy todir="${tmpSourceDir}"> |
|
145 |
<fileset dir="${basedir}/_fwAndami/src"> |
|
146 |
<include name="**/*.java"/> |
|
147 |
</fileset> |
|
148 |
<fileset dir="${basedir}/appgvSIG/src"> |
|
149 |
<include name="**/*.java"/> |
|
150 |
</fileset> |
|
151 |
<fileset dir="${basedir}/extAddEventTheme/src"> |
|
152 |
<include name="**/*.java"/> |
|
153 |
</fileset> |
|
154 |
<fileset dir="${basedir}/extCAD/src"> |
|
155 |
<include name="**/*.java"/> |
|
156 |
</fileset> |
|
157 |
<fileset dir="${basedir}/extCatalogYNomenclator/src"> |
|
158 |
<include name="**/*.java"/> |
|
159 |
</fileset> |
|
160 |
<fileset dir="${basedir}/extDataLocator/src"> |
|
161 |
<include name="**/*.java"/> |
|
162 |
</fileset> |
|
163 |
<fileset dir="${basedir}/extDwg/src"> |
|
164 |
<include name="**/*.java"/> |
|
165 |
</fileset> |
|
166 |
<fileset dir="${basedir}/extGeoProcessing/src"> |
|
167 |
<include name="**/*.java"/> |
|
168 |
</fileset> |
|
169 |
<fileset dir="${basedir}/extJDBC/src"> |
|
170 |
<include name="**/*.java"/> |
|
171 |
</fileset> |
|
172 |
<fileset dir="${basedir}/extRasterTools/src"> |
|
173 |
<include name="**/*.java"/> |
|
174 |
</fileset> |
|
175 |
<fileset dir="${basedir}/extWCS/src"> |
|
176 |
<include name="**/*.java"/> |
|
177 |
</fileset> |
|
178 |
<fileset dir="${basedir}/extWFS2/src"> |
|
179 |
<include name="**/*.java"/> |
|
180 |
</fileset> |
|
181 |
<fileset dir="${basedir}/extWMS/src"> |
|
182 |
<include name="**/*.java"/> |
|
183 |
</fileset> |
|
184 |
<fileset dir="${basedir}/libCorePlugin/src"> |
|
185 |
<include name="**/*.java"/> |
|
186 |
</fileset> |
|
187 |
<!-- <fileset dir="${basedir}/libCq CMS for java/src"> |
|
188 |
<include name="**/*.java"/> |
|
189 |
</fileset> --> |
|
190 |
<fileset dir="${basedir}/libDriverManager/src"> |
|
191 |
<include name="**/*.java"/> |
|
192 |
</fileset> |
|
193 |
<fileset dir="${basedir}/libDwg/src"> |
|
194 |
<include name="**/*.java"/> |
|
195 |
</fileset> |
|
196 |
<fileset dir="${basedir}/libFMap/src"> |
|
197 |
<include name="**/*.java"/> |
|
198 |
</fileset> |
|
199 |
<fileset dir="${basedir}/libInternationalization/src"> |
|
200 |
<include name="**/*.java"/> |
|
201 |
</fileset> |
|
202 |
<fileset dir="${basedir}/libIverUtiles/src"> |
|
203 |
<include name="**/*.java"/> |
|
204 |
</fileset> |
|
205 |
<fileset dir="${basedir}/libRemoteServices/src"> |
|
206 |
<include name="**/*.java"/> |
|
207 |
</fileset> |
|
208 |
<fileset dir="${basedir}/libGDBMS/src/main/java/"> |
|
209 |
<include name="**/*.java"/> |
|
210 |
</fileset> |
|
211 |
</copy> |
|
212 |
<javadoc |
|
213 |
author="true" |
|
214 |
version="true" |
|
215 |
destdir="${apiReferenceDir}" |
|
216 |
maxmemory="512m" |
|
217 |
source="1.4" |
|
218 |
doctitle="API DOCUMENTATION" |
|
219 |
bottom="API Documentation" |
|
220 |
windowtitle="API Documentation" |
|
221 |
verbose="${verbose}" |
|
222 |
encoding="${encoding}"> |
|
223 |
<sourcepath> |
|
224 |
<pathelement path="${tmpSourceDir}"/> |
|
225 |
</sourcepath> |
|
226 |
<packageset dir="/${tmpSourceDir}"> |
|
227 |
<include name="**/**"/> |
|
228 |
</packageset> |
|
229 |
</javadoc> |
|
230 |
</target> |
|
231 |
|
|
232 |
<!-- ============================= Scripts ================================= --> |
|
233 |
<target name="makeRemoteDirs" |
|
234 |
description="Crea un directorio por ftp"> |
|
235 |
<ftp |
|
236 |
action="mkdir" |
|
237 |
server="${server}" |
|
238 |
password="${passw}" |
|
239 |
userid="${user}" |
|
240 |
remotedir="${remoteDir}" |
|
241 |
port="${port}" |
|
242 |
passive="${ftp-passive}" |
|
243 |
/> |
|
244 |
</target> |
|
245 |
<target name="deleteRemoteFiles" |
|
246 |
description="Borra los archivos de los directorios remotos"> |
|
247 |
<ftp |
|
248 |
action="del" |
|
249 |
server="${server}" |
|
250 |
password="${passw}" |
|
251 |
userid="${user}" |
|
252 |
remotedir="${remoteDir}" |
|
253 |
port="${port}" |
|
254 |
passive="${ftp-passive}" |
|
255 |
verbose="${verbose}"> |
|
256 |
<fileset dir="${remoteDir}"> |
|
257 |
<include name="**"/> |
|
258 |
<exclude name="${excludeFiles}"/> |
|
259 |
</fileset> |
|
260 |
</ftp> |
|
261 |
</target> |
|
262 |
<target name="deleteRemoteDirs" |
|
263 |
description="Borra los directorios remotos"> |
|
264 |
<ftp |
|
265 |
action="rmdir" |
|
266 |
server="${server}" |
|
267 |
password="${passw}" |
|
268 |
userid="${user}" |
|
269 |
remotedir="${remoteDir}" |
|
270 |
port="${port}" |
|
271 |
passive="${ftp-passive}" |
|
272 |
verbose="${verbose}"> |
|
273 |
<fileset> |
|
274 |
<include name="**"/> |
|
275 |
<exclude name="${excludeDirs}"/> |
|
276 |
</fileset> |
|
277 |
</ftp> |
|
278 |
</target> |
|
279 |
<target name="copyFilesToRemote" |
|
280 |
description="Copia archivos por ftp"> |
|
281 |
<echo>Copying files to ftp://${server}/${remoteDir}</echo> |
|
282 |
<ftp server="${server}" |
|
283 |
password="${passw}" |
|
284 |
userid="${user}" |
|
285 |
remotedir="${remoteDir}" |
|
286 |
port="${port}" |
|
287 |
passive="${ftp-passive}" |
|
288 |
verbose="${verbose}" |
|
289 |
binary="true"> |
|
290 |
|
|
291 |
<fileset dir="${sourceDir}"> |
|
292 |
<include name="**/*"/> |
|
293 |
</fileset> |
|
294 |
</ftp> |
|
295 |
</target> |
|
296 |
<target name="moveDir" |
|
297 |
description="Mueve un directorio a otro"> |
|
298 |
<move todir="${dstDir}"> |
|
299 |
<fileset dir="${srcDir}"/> |
|
300 |
</move> |
|
301 |
</target> |
|
302 |
<target name="copyDir" |
|
303 |
description="Copia un árbol de directorios en otro directorio"> |
|
304 |
<copy todir="${dstDir}"> |
|
305 |
<fileset dir="${srcDir}"/> |
|
306 |
</copy> |
|
307 |
</target> |
|
308 |
<target name="makeZipFile" |
|
309 |
description="Crea un archivo zip"> |
|
310 |
<zip destfile="${dstDir}" |
|
311 |
basedir="${srcDir}" |
|
312 |
includes="**/*.html"> |
|
313 |
</zip> |
|
314 |
|
|
315 |
</target> |
|
316 |
|
|
317 |
<target name="replaceInLinks" |
|
318 |
description="For each html file in ${targetDir}, replaces ${oldValue} by ${newValue} in each href link"> |
|
319 |
<replaceregexp flags="g"> |
|
320 |
<regexp pattern='(A HREF="[^"]*)(${oldValue})([^"]*")'/> |
|
321 |
<substitution expression='\1${newValue}\3'/> |
|
322 |
<fileset dir="${apiReferenceDir}"> |
|
323 |
<include name="**/*.html"/> |
|
324 |
<include name="**/*.HTML"/> |
|
325 |
<include name="**/*.htm"/> |
|
326 |
<include name="**/*.HTM"/> |
|
327 |
</fileset> |
|
328 |
</replaceregexp> |
|
329 |
</target> |
|
330 |
|
|
331 |
<!-- this target does not work perfectly: |
|
332 |
- it will fail if two nested directories have to be replaced |
|
333 |
- it will fail to replaces directory in the root directory |
|
334 |
but anyway, we don't have these situations, so it will make the trick |
|
335 |
--> |
|
336 |
<target name="renameFiles" |
|
337 |
description="Rename directories from ${oldValue} to ${newValue} "> |
|
338 |
<move todir="${targetDir}" verbose="yes"> |
|
339 |
<fileset |
|
340 |
dir="${targetDir}" |
|
341 |
includes="**/*"/> |
|
342 |
<regexpmapper from="(.*)(${oldValue})(.*)" to="\1${newValue}\3" handledirsep="true"/> |
|
343 |
</move> |
|
344 |
</target> |
|
345 |
</project> |
|
0 | 346 |
tags/v2_0_0_Build_2020/applications/appgvSIG/scripts/voidTarget/build.xml | ||
---|---|---|
1 |
<project name="VoidTarget" basedir="."> |
|
2 |
<description> |
|
3 |
Void build file, to use it when a project is not present |
|
4 |
</description> |
|
5 |
<property name="projectName" value="projectName" /> |
|
6 |
|
|
7 |
<target name="batch-build"> |
|
8 |
<echo>Warning: Project ${projectName} was skipped</echo> |
|
9 |
</target> |
|
10 |
<target name="clean"> |
|
11 |
<echo>Warning: Project ${projectName} was skipped</echo> |
|
12 |
</target> |
|
13 |
<target name="import-build-number"> |
|
14 |
</target> |
|
15 |
</project> |
|
0 | 16 |
tags/v2_0_0_Build_2020/applications/appgvSIG/src/log4j.properties | ||
---|---|---|
1 |
log4j.rootLogger=info, stdout |
|
2 |
|
|
3 |
log4j.appender.stdout=org.apache.log4j.ConsoleAppender |
|
4 |
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout |
|
5 |
|
|
6 |
# Pattern to output the caller's file name and line number. |
|
7 |
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n |
|
8 |
|
|
9 |
log4j.appender.R=org.apache.log4j.RollingFileAppender |
|
10 |
log4j.appender.R.File=application.log |
|
11 |
|
|
12 |
log4j.appender.R.MaxFileSize=100KB |
|
13 |
# Keep one backup file |
|
14 |
log4j.appender.R.MaxBackupIndex=1 |
|
15 |
|
|
16 |
log4j.appender.R.layout=org.apache.log4j.PatternLayout |
|
17 |
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n |
|
18 |
|
|
0 | 19 |
tags/v2_0_0_Build_2020/applications/appgvSIG/src/com/vividsolutions/jump/util/Fmt.java | ||
---|---|---|
1 |
|
|
2 |
/* |
|
3 |
* The Unified Mapping Platform (JUMP) is an extensible, interactive GUI |
|
4 |
* for visualizing and manipulating spatial features with geometry and attributes. |
|
5 |
* |
|
6 |
* Copyright (C) 2003 Vivid Solutions |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Vivid Solutions |
|
25 |
* Suite #1A |
|
26 |
* 2328 Government Street |
|
27 |
* Victoria BC V8T 5G5 |
|
28 |
* Canada |
|
29 |
* |
|
30 |
* (250)385-6040 |
|
31 |
* www.vividsolutions.com |
|
32 |
*/ |
|
33 |
|
|
34 |
package com.vividsolutions.jump.util; |
|
35 |
|
|
36 |
|
|
37 |
// Fmt - some simple single-arg sprintf-like routines |
|
38 |
// |
|
39 |
// Copyright (C) 1996 by Jef Poskanzer <jef@acme.com>. All rights reserved. |
|
40 |
// |
|
41 |
// Redistribution and use in source and binary forms, with or without |
|
42 |
// modification, are permitted provided that the following conditions |
|
43 |
// are met: |
|
44 |
// 1. Redistributions of source code must retain the above copyright |
|
45 |
// notice, this list of conditions and the following disclaimer. |
|
46 |
// 2. Redistributions in binary form must reproduce the above copyright |
|
47 |
// notice, this list of conditions and the following disclaimer in the |
|
48 |
// documentation and/or other materials provided with the distribution. |
|
49 |
// |
|
50 |
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
|
51 |
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
52 |
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
53 |
// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
|
54 |
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
55 |
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
56 |
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
57 |
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
58 |
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
59 |
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
60 |
// SUCH DAMAGE. |
|
61 |
// |
|
62 |
// Visit the ACME Labs Java page for up-to-date versions of this and other |
|
63 |
// fine Java utilities: http://www.acme.com/java/ |
|
64 |
/// Some simple single-arg sprintf-like routines. |
|
65 |
// <P> |
|
66 |
// It is apparently impossible to declare a Java method that accepts |
|
67 |
// variable numbers of any type of argument. You can declare it to take |
|
68 |
// Objects, but numeric variables and constants are not in fact Objects. |
|
69 |
// <P> |
|
70 |
// However, using the built-in string concatenation, it's almost as |
|
71 |
// convenient to make a series of single-argument formatting routines. |
|
72 |
// <P> |
|
73 |
// Fmt can format the following types: |
|
74 |
// <BLOCKQUOTE><CODE> |
|
75 |
// byte short int long float double char String Object |
|
76 |
// </CODE></BLOCKQUOTE> |
|
77 |
// For each type there is a set of overloaded methods, each returning |
|
78 |
// a formatted String. There's the plain formatting version: |
|
79 |
// <BLOCKQUOTE><PRE> |
|
80 |
// Fmt.fmt( x ) |
|
81 |
// </PRE></BLOCKQUOTE> |
|
82 |
// There's a version specifying a minimum field width: |
|
83 |
// <BLOCKQUOTE><PRE> |
|
84 |
// Fmt.fmt( x, minWidth ) |
|
85 |
// </PRE></BLOCKQUOTE> |
|
86 |
// And there's a version that takes flags: |
|
87 |
// <BLOCKQUOTE><PRE> |
|
88 |
// Fmt.fmt( x, minWidth, flags ) |
|
89 |
// </PRE></BLOCKQUOTE> |
|
90 |
// Currently available flags are: |
|
91 |
// <BLOCKQUOTE><PRE> |
|
92 |
// Fmt.ZF - zero-fill |
|
93 |
// Fmt.LJ - left justify |
|
94 |
// Fmt.HX - hexadecimal |
|
95 |
// Fmt.OC - octal |
|
96 |
// </PRE></BLOCKQUOTE> |
|
97 |
// The HX and OC flags imply unsigned output. |
|
98 |
// <P> |
|
99 |
// For doubles and floats, there's a significant-figures parameter before |
|
100 |
// the flags: |
|
101 |
// <BLOCKQUOTE><PRE> |
|
102 |
// Fmt.fmt( d ) |
|
103 |
// Fmt.fmt( d, minWidth ) |
|
104 |
// Fmt.fmt( d, minWidth, sigFigs ) |
|
105 |
// Fmt.fmt( d, minWidth, sigFigs, flags ) |
|
106 |
// </PRE></BLOCKQUOTE> |
|
107 |
// <P> |
|
108 |
// <A HREF="/resources/classes/Acme/Fmt.java">Fetch the software.</A><BR> |
|
109 |
// <A HREF="/resources/classes/Acme.tar.gz">Fetch the entire Acme package.</A> |
|
110 |
// <HR> |
|
111 |
// Similar classes: |
|
112 |
// <UL> |
|
113 |
// <LI> Andrew Scherpbier's <A HREF="http://www.sdsu.edu/doc/java-SDSU/sdsu.FormatString.html">FormatString</A> |
|
114 |
// Tries to allow variable numbers of arguments by |
|
115 |
// supplying overloaded routines with different combinations of parameters, |
|
116 |
// but doesn't actually supply that many. The floating point conversion |
|
117 |
// is described as "very incomplete". |
|
118 |
// <LI> Core Java's <A HREF="http://www.apl.jhu.edu/~hall/java/CoreJava-Format.html">Format</A>. |
|
119 |
// The design seems a little weird. They want you to create an instance, |
|
120 |
// passing the format string to the constructor, and then call an instance |
|
121 |
// method with your data to do the actual formatting. The extra steps are |
|
122 |
// pointless; better to just use static methods. |
|
123 |
// </UL> |
|
124 |
public class Fmt { |
|
125 |
// Flags. |
|
126 |
/// Zero-fill. |
|
127 |
public static final int ZF = 1; |
|
128 |
|
|
129 |
/// Left justify. |
|
130 |
public static final int LJ = 2; |
|
131 |
|
|
132 |
/// Hexadecimal. |
|
133 |
public static final int HX = 4; |
|
134 |
|
|
135 |
/// Octal. |
|
136 |
public static final int OC = 8; |
|
137 |
|
|
138 |
// Was a number - internal use. |
|
139 |
private static final int WN = 16; |
|
140 |
|
|
141 |
// byte |
|
142 |
public static String fmt(byte b) { |
|
143 |
return fmt(b, 0, 0); |
|
144 |
} |
|
145 |
|
|
146 |
public static String fmt(byte b, int minWidth) { |
|
147 |
return fmt(b, minWidth, 0); |
|
148 |
} |
|
149 |
|
|
150 |
public static String fmt(byte b, int minWidth, int flags) { |
|
151 |
boolean hexadecimal = ((flags & HX) != 0); |
|
152 |
boolean octal = ((flags & OC) != 0); |
|
153 |
|
|
154 |
if (hexadecimal) { |
|
155 |
return fmt(Integer.toString(b & 0xff, 16), minWidth, flags | WN); |
|
156 |
} else if (octal) { |
|
157 |
return fmt(Integer.toString(b & 0xff, 8), minWidth, flags | WN); |
|
158 |
} else { |
|
159 |
return fmt(Integer.toString(b & 0xff), minWidth, flags | WN); |
|
160 |
} |
|
161 |
} |
|
162 |
|
|
163 |
// short |
|
164 |
public static String fmt(short s) { |
|
165 |
return fmt(s, 0, 0); |
|
166 |
} |
|
167 |
|
|
168 |
public static String fmt(short s, int minWidth) { |
|
169 |
return fmt(s, minWidth, 0); |
|
170 |
} |
|
171 |
|
|
172 |
public static String fmt(short s, int minWidth, int flags) { |
|
173 |
boolean hexadecimal = ((flags & HX) != 0); |
|
174 |
boolean octal = ((flags & OC) != 0); |
|
175 |
|
|
176 |
if (hexadecimal) { |
|
177 |
return fmt(Integer.toString(s & 0xffff, 16), minWidth, flags | WN); |
|
178 |
} else if (octal) { |
|
179 |
return fmt(Integer.toString(s & 0xffff, 8), minWidth, flags | WN); |
|
180 |
} else { |
|
181 |
return fmt(Integer.toString(s), minWidth, flags | WN); |
|
182 |
} |
|
183 |
} |
|
184 |
|
|
185 |
// int |
|
186 |
public static String fmt(int i) { |
|
187 |
return fmt(i, 0, 0); |
|
188 |
} |
|
189 |
|
|
190 |
public static String fmt(int i, int minWidth) { |
|
191 |
return fmt(i, minWidth, 0); |
|
192 |
} |
|
193 |
|
|
194 |
public static String fmt(int i, int minWidth, int flags) { |
|
195 |
boolean hexadecimal = ((flags & HX) != 0); |
|
196 |
boolean octal = ((flags & OC) != 0); |
|
197 |
|
|
198 |
if (hexadecimal) { |
|
199 |
return fmt(Long.toString(i & 0xffffffffL, 16), minWidth, flags | |
|
200 |
WN); |
|
201 |
} else if (octal) { |
|
202 |
return fmt(Long.toString(i & 0xffffffffL, 8), minWidth, flags | WN); |
|
203 |
} else { |
|
204 |
return fmt(Integer.toString(i), minWidth, flags | WN); |
|
205 |
} |
|
206 |
} |
|
207 |
|
|
208 |
// long |
|
209 |
public static String fmt(long l) { |
|
210 |
return fmt(l, 0, 0); |
|
211 |
} |
|
212 |
|
|
213 |
public static String fmt(long l, int minWidth) { |
|
214 |
return fmt(l, minWidth, 0); |
|
215 |
} |
|
216 |
|
|
217 |
public static String fmt(long l, int minWidth, int flags) { |
|
218 |
boolean hexadecimal = ((flags & HX) != 0); |
|
219 |
boolean octal = ((flags & OC) != 0); |
|
220 |
|
|
221 |
if (hexadecimal) { |
|
222 |
if ((l & 0xf000000000000000L) != 0) { |
|
223 |
return fmt(Long.toString(l >>> 60, 16) + |
|
224 |
fmt(l & 0x0fffffffffffffffL, 15, HX | ZF), minWidth, |
|
225 |
flags | WN); |
|
226 |
} else { |
|
227 |
return fmt(Long.toString(l, 16), minWidth, flags | WN); |
|
228 |
} |
|
229 |
} else if (octal) { |
|
230 |
if ((l & 0x8000000000000000L) != 0) { |
|
231 |
return fmt(Long.toString(l >>> 63, 8) + |
|
232 |
fmt(l & 0x7fffffffffffffffL, 21, OC | ZF), minWidth, |
|
233 |
flags | WN); |
|
234 |
} else { |
|
235 |
return fmt(Long.toString(l, 8), minWidth, flags | WN); |
|
236 |
} |
|
237 |
} else { |
|
238 |
return fmt(Long.toString(l), minWidth, flags | WN); |
|
239 |
} |
|
240 |
} |
|
241 |
|
|
242 |
// float |
|
243 |
public static String fmt(float f) { |
|
244 |
return fmt(f, 0, 0, 0); |
|
245 |
} |
|
246 |
|
|
247 |
public static String fmt(float f, int minWidth) { |
|
248 |
return fmt(f, minWidth, 0, 0); |
|
249 |
} |
|
250 |
|
|
251 |
public static String fmt(float f, int minWidth, int sigFigs) { |
|
252 |
return fmt(f, minWidth, sigFigs, 0); |
|
253 |
} |
|
254 |
|
|
255 |
public static String fmt(float f, int minWidth, int sigFigs, int flags) { |
|
256 |
if (sigFigs != 0) { |
|
257 |
return fmt(sigFigFix(Float.toString(f), sigFigs), minWidth, |
|
258 |
flags | WN); |
|
259 |
} else { |
|
260 |
return fmt(Float.toString(f), minWidth, flags | WN); |
|
261 |
} |
|
262 |
} |
|
263 |
|
|
264 |
// double |
|
265 |
public static String fmt(double d) { |
|
266 |
return fmt(d, 0, 0, 0); |
|
267 |
} |
|
268 |
|
|
269 |
public static String fmt(double d, int minWidth) { |
|
270 |
return fmt(d, minWidth, 0, 0); |
|
271 |
} |
|
272 |
|
|
273 |
public static String fmt(double d, int minWidth, int sigFigs) { |
|
274 |
return fmt(d, minWidth, sigFigs, 0); |
|
275 |
} |
|
276 |
|
|
277 |
public static String fmt(double d, int minWidth, int sigFigs, int flags) { |
|
278 |
if (sigFigs != 0) { |
|
279 |
return fmt(sigFigFix(doubleToString(d), sigFigs), minWidth, |
|
280 |
flags | WN); |
|
281 |
} else { |
|
282 |
return fmt(doubleToString(d), minWidth, flags | WN); |
|
283 |
} |
|
284 |
} |
|
285 |
|
|
286 |
// char |
|
287 |
public static String fmt(char c) { |
|
288 |
return fmt(c, 0, 0); |
|
289 |
} |
|
290 |
|
|
291 |
public static String fmt(char c, int minWidth) { |
|
292 |
return fmt(c, minWidth, 0); |
|
293 |
} |
|
294 |
|
|
295 |
public static String fmt(char c, int minWidth, int flags) { |
|
296 |
// return fmt( Character.toString( c ), minWidth, flags ); |
|
297 |
// Character currently lacks a static toString method. Workaround |
|
298 |
// is to make a temporary instance and use the instance toString. |
|
299 |
return fmt(new Character(c).toString(), minWidth, flags); |
|
300 |
} |
|
301 |
|
|
302 |
// Object |
|
303 |
public static String fmt(Object o) { |
|
304 |
return fmt(o, 0, 0); |
|
305 |
} |
|
306 |
|
|
307 |
public static String fmt(Object o, int minWidth) { |
|
308 |
return fmt(o, minWidth, 0); |
|
309 |
} |
|
310 |
|
|
311 |
public static String fmt(Object o, int minWidth, int flags) { |
|
312 |
return fmt(o.toString(), minWidth, flags); |
|
313 |
} |
|
314 |
|
|
315 |
// String |
|
316 |
public static String fmt(String s) { |
|
317 |
return fmt(s, 0, 0); |
|
318 |
} |
|
319 |
|
|
320 |
public static String fmt(String s, int minWidth) { |
|
321 |
return fmt(s, minWidth, 0); |
|
322 |
} |
|
323 |
|
|
324 |
public static String fmt(String s, int minWidth, int flags) { |
|
325 |
int len = s.length(); |
|
326 |
boolean zeroFill = ((flags & ZF) != 0); |
|
327 |
boolean leftJustify = ((flags & LJ) != 0); |
|
328 |
boolean hexadecimal = ((flags & HX) != 0); |
|
329 |
boolean octal = ((flags & OC) != 0); |
|
330 |
boolean wasNumber = ((flags & WN) != 0); |
|
331 |
|
|
332 |
if ((hexadecimal || octal || zeroFill) && !wasNumber) { |
|
333 |
throw new InternalError("Acme.Fmt: number flag on a non-number"); |
|
334 |
} |
|
335 |
|
|
336 |
if (zeroFill && leftJustify) { |
|
337 |
throw new InternalError("Acme.Fmt: zero-fill left-justify is silly"); |
|
338 |
} |
|
339 |
|
|
340 |
if (hexadecimal && octal) { |
|
341 |
throw new InternalError("Acme.Fmt: can't do both hex and octal"); |
|
342 |
} |
|
343 |
|
|
344 |
if (len >= minWidth) { |
|
345 |
return s; |
|
346 |
} |
|
347 |
|
|
348 |
int fillWidth = minWidth - len; |
|
349 |
StringBuffer fill = new StringBuffer(fillWidth); |
|
350 |
|
|
351 |
for (int i = 0; i < fillWidth; ++i) |
|
352 |
if (zeroFill) { |
|
353 |
fill.append('0'); |
|
354 |
} else { |
|
355 |
fill.append(' '); |
|
356 |
} |
|
357 |
|
|
358 |
if (leftJustify) { |
|
359 |
return s + fill; |
|
360 |
} else if (zeroFill && s.startsWith("-")) { |
|
361 |
return "-" + fill + s.substring(1); |
|
362 |
} else { |
|
363 |
return fill + s; |
|
364 |
} |
|
365 |
} |
|
366 |
|
|
367 |
// Internal routines. |
|
368 |
private static String sigFigFix(String s, int sigFigs) { |
|
369 |
// First dissect the floating-point number string into sign, |
|
370 |
// integer part, fraction part, and exponent. |
|
371 |
String sign; |
|
372 |
String unsigned; |
|
373 |
|
|
374 |
if (s.startsWith("-") || s.startsWith("+")) { |
|
375 |
sign = s.substring(0, 1); |
|
376 |
unsigned = s.substring(1); |
|
377 |
} else { |
|
378 |
sign = ""; |
|
379 |
unsigned = s; |
|
380 |
} |
|
381 |
|
|
382 |
String mantissa; |
|
383 |
String exponent; |
|
384 |
int eInd = unsigned.indexOf('e'); |
|
385 |
|
|
386 |
if (eInd == -1) { // it may be 'e' or 'E' |
|
387 |
eInd = unsigned.indexOf('E'); |
|
388 |
} |
|
389 |
|
|
390 |
if (eInd == -1) { |
|
391 |
mantissa = unsigned; |
|
392 |
exponent = ""; |
|
393 |
} else { |
|
394 |
mantissa = unsigned.substring(0, eInd); |
|
395 |
exponent = unsigned.substring(eInd); |
|
396 |
} |
|
397 |
|
|
398 |
StringBuffer number; |
|
399 |
StringBuffer fraction; |
|
400 |
int dotInd = mantissa.indexOf('.'); |
|
401 |
|
|
402 |
if (dotInd == -1) { |
|
403 |
number = new StringBuffer(mantissa); |
|
404 |
fraction = new StringBuffer(""); |
|
405 |
} else { |
|
406 |
number = new StringBuffer(mantissa.substring(0, dotInd)); |
|
407 |
fraction = new StringBuffer(mantissa.substring(dotInd + 1)); |
|
408 |
} |
|
409 |
|
|
410 |
int numFigs = number.length(); |
|
411 |
int fracFigs = fraction.length(); |
|
412 |
|
|
413 |
if (((numFigs == 0) || number.equals("0")) && (fracFigs > 0)) { |
|
414 |
// Don't count leading zeros in the fraction. |
|
415 |
numFigs = 0; |
|
416 |
|
|
417 |
for (int i = 0; i < fraction.length(); ++i) { |
|
418 |
if (fraction.charAt(i) != '0') { |
|
419 |
break; |
|
420 |
} |
|
421 |
|
|
422 |
--fracFigs; |
|
423 |
} |
|
424 |
} |
|
425 |
|
|
426 |
int mantFigs = numFigs + fracFigs; |
|
427 |
|
|
428 |
if (sigFigs > mantFigs) { |
|
429 |
// We want more figures; just append zeros to the fraction. |
|
430 |
for (int i = mantFigs; i < sigFigs; ++i) |
|
431 |
fraction.append('0'); |
|
432 |
} else if ((sigFigs < mantFigs) && (sigFigs >= numFigs)) { |
|
433 |
// Want fewer figures in the fraction; chop. |
|
434 |
fraction.setLength(fraction.length() - |
|
435 |
(fracFigs - (sigFigs - numFigs))); |
|
436 |
|
|
437 |
// Round? |
|
438 |
} else if (sigFigs < numFigs) { |
|
439 |
// Want fewer figures in the number; turn them to zeros. |
|
440 |
fraction.setLength(0); // should already be zero, but make sure |
|
441 |
|
|
442 |
for (int i = sigFigs; i < numFigs; ++i) |
|
443 |
number.setCharAt(i, '0'); |
|
444 |
|
|
445 |
// Round? |
|
446 |
} |
|
447 |
|
|
448 |
// Else sigFigs == mantFigs, which is fine. |
|
449 |
if (fraction.length() == 0) { |
|
450 |
return sign + number + exponent; |
|
451 |
} else { |
|
452 |
return sign + number + "." + fraction + exponent; |
|
453 |
} |
|
454 |
} |
|
455 |
|
|
456 |
/// Improved version of Double.toString(), returns more decimal places. |
|
457 |
// <P> |
|
458 |
// The JDK 1.0.2 version of Double.toString() returns only six decimal |
|
459 |
// places on some systems. In JDK 1.1 full precision is returned on |
|
460 |
// all platforms. |
|
461 |
// @deprecated |
|
462 |
// @see java.lang.Double#toString |
|
463 |
public static String doubleToString(double d) { |
|
464 |
// Handle special numbers first, to avoid complications. |
|
465 |
if (Double.isNaN(d)) { |
|
466 |
return "NaN"; |
|
467 |
} |
|
468 |
|
|
469 |
if (d == Double.NEGATIVE_INFINITY) { |
|
470 |
return "-Inf"; |
|
471 |
} |
|
472 |
|
|
473 |
if (d == Double.POSITIVE_INFINITY) { |
|
474 |
return "Inf"; |
|
475 |
} |
|
476 |
|
|
477 |
// Grab the sign, and then make the number positive for simplicity. |
|
478 |
boolean negative = false; |
|
479 |
|
|
480 |
if (d < 0.0D) { |
|
481 |
negative = true; |
|
482 |
d = -d; |
|
483 |
} |
|
484 |
|
|
485 |
// Get the native version of the unsigned value, as a template. |
|
486 |
String unsStr = Double.toString(d); |
|
487 |
|
|
488 |
// Dissect out the exponent. |
|
489 |
String mantStr; |
|
490 |
|
|
491 |
// Dissect out the exponent. |
|
492 |
String expStr; |
|
493 |
int exp; |
|
494 |
int eInd = unsStr.indexOf('e'); |
|
495 |
|
|
496 |
if (eInd == -1) { // it may be 'e' or 'E' |
|
497 |
eInd = unsStr.indexOf('E'); |
|
498 |
} |
|
499 |
|
|
500 |
if (eInd == -1) { |
|
501 |
mantStr = unsStr; |
|
502 |
expStr = ""; |
|
503 |
exp = 0; |
|
504 |
} else { |
|
505 |
mantStr = unsStr.substring(0, eInd); |
|
506 |
expStr = unsStr.substring(eInd + 1); |
|
507 |
|
|
508 |
if (expStr.startsWith("+")) { |
|
509 |
exp = Integer.parseInt(expStr.substring(1)); |
|
510 |
} else { |
|
511 |
exp = Integer.parseInt(expStr); |
|
512 |
} |
|
513 |
} |
|
514 |
|
|
515 |
// Dissect out the number part. |
|
516 |
String numStr; |
|
517 |
int dotInd = mantStr.indexOf('.'); |
|
518 |
|
|
519 |
if (dotInd == -1) { |
|
520 |
numStr = mantStr; |
|
521 |
} else { |
|
522 |
numStr = mantStr.substring(0, dotInd); |
|
523 |
} |
|
524 |
|
|
525 |
long num; |
|
526 |
|
|
527 |
if (numStr.length() == 0) { |
|
528 |
num = 0; |
|
529 |
} else { |
|
530 |
num = Integer.parseInt(numStr); |
|
531 |
} |
|
532 |
|
|
533 |
// Build the new mantissa. |
|
534 |
StringBuffer newMantBuf = new StringBuffer(numStr + "."); |
|
535 |
double p = Math.pow(10, exp); |
|
536 |
double frac = d - (num * p); |
|
537 |
String digits = "0123456789"; |
|
538 |
int nDigits = 16 - numStr.length(); // about 16 digits in a double |
|
539 |
|
|
540 |
for (int i = 0; i < nDigits; ++i) { |
|
541 |
p /= 10.0D; |
|
542 |
|
|
543 |
int dig = (int) (frac / p); |
|
544 |
|
|
545 |
if (dig < 0) { |
|
546 |
dig = 0; |
|
547 |
} |
|
548 |
|
|
549 |
if (dig > 9) { |
|
550 |
dig = 9; |
|
551 |
} |
|
552 |
|
|
553 |
newMantBuf.append(digits.charAt(dig)); |
|
554 |
frac -= (dig * p); |
|
555 |
} |
|
556 |
|
|
557 |
if ((int) ((frac / p) + 0.5D) == 1) { |
|
558 |
// Round up. |
|
559 |
boolean roundMore = true; |
|
560 |
|
|
561 |
for (int i = newMantBuf.length() - 1; i >= 0; --i) { |
|
562 |
int dig = digits.indexOf(newMantBuf.charAt(i)); |
|
563 |
|
|
564 |
if (dig == -1) { |
|
565 |
continue; |
|
566 |
} |
|
567 |
|
|
568 |
++dig; |
|
569 |
|
|
570 |
if (dig == 10) { |
|
571 |
newMantBuf.setCharAt(i, '0'); |
|
572 |
|
|
573 |
continue; |
|
574 |
} |
|
575 |
|
|
576 |
newMantBuf.setCharAt(i, digits.charAt(dig)); |
|
577 |
roundMore = false; |
|
578 |
|
|
579 |
break; |
|
580 |
} |
|
581 |
|
|
582 |
if (roundMore) { |
|
583 |
// If this happens, we need to prepend a 1. But I haven't |
|
584 |
// found a test case yet, so I'm leaving it out for now. |
|
585 |
// But if you get this message, please let me know! |
|
586 |
newMantBuf.append("ROUNDMORE"); |
|
587 |
} |
|
588 |
} |
|
589 |
|
|
590 |
// Chop any trailing zeros. |
|
591 |
int len = newMantBuf.length(); |
|
592 |
|
|
593 |
while (newMantBuf.charAt(len - 1) == '0') |
|
594 |
newMantBuf.setLength(--len); |
|
595 |
|
|
596 |
// And chop a trailing dot, if any. |
|
597 |
if (newMantBuf.charAt(len - 1) == '.') { |
|
598 |
newMantBuf.setLength(--len); |
|
599 |
} |
|
600 |
|
|
601 |
// Done. |
|
602 |
return (negative ? "-" : "") + newMantBuf + |
|
603 |
((expStr.length() != 0) ? ("e" + expStr) : ""); |
|
604 |
} |
|
605 |
|
|
606 |
/****************************************************************************** |
|
607 |
/// Test program. |
|
608 |
public static void main( String[] args ) |
|
609 |
{ |
|
610 |
System.out.println( "Starting tests." ); |
|
611 |
show( Fmt.fmt( "Hello there." ) ); |
|
612 |
show( Fmt.fmt( 123 ) ); |
|
613 |
show( Fmt.fmt( 123, 10 ) ); |
|
614 |
show( Fmt.fmt( 123, 10, Fmt.ZF ) ); |
|
615 |
show( Fmt.fmt( 123, 10, Fmt.LJ ) ); |
|
616 |
show( Fmt.fmt( -123 ) ); |
|
617 |
show( Fmt.fmt( -123, 10 ) ); |
|
618 |
show( Fmt.fmt( -123, 10, Fmt.ZF ) ); |
|
619 |
show( Fmt.fmt( -123, 10, Fmt.LJ ) ); |
|
620 |
show( Fmt.fmt( (byte) 0xbe, 22, Fmt.OC ) ); |
|
621 |
show( Fmt.fmt( (short) 0xbabe, 22, Fmt.OC ) ); |
|
622 |
show( Fmt.fmt( 0xcafebabe, 22, Fmt.OC ) ); |
|
623 |
show( Fmt.fmt( 0xdeadbeefcafebabeL, 22, Fmt.OC ) ); |
|
624 |
show( Fmt.fmt( 0x8000000000000000L, 22, Fmt.OC ) ); |
|
625 |
show( Fmt.fmt( (byte) 0xbe, 16, Fmt.HX ) ); |
|
626 |
show( Fmt.fmt( (short) 0xbabe, 16, Fmt.HX ) ); |
|
627 |
show( Fmt.fmt( 0xcafebabe, 16, Fmt.HX ) ); |
|
628 |
show( Fmt.fmt( 0xdeadbeefcafebabeL, 16, Fmt.HX ) ); |
|
629 |
show( Fmt.fmt( 0x8000000000000000L, 16, Fmt.HX ) ); |
|
630 |
show( Fmt.fmt( 'c' ) ); |
|
631 |
show( Fmt.fmt( new java.util.Date() ) ); |
|
632 |
show( Fmt.fmt( 123.456F ) ); |
|
633 |
show( Fmt.fmt( 123456000000000000.0F ) ); |
|
634 |
show( Fmt.fmt( 123.456F, 0, 8 ) ); |
|
635 |
show( Fmt.fmt( 123.456F, 0, 7 ) ); |
|
636 |
show( Fmt.fmt( 123.456F, 0, 6 ) ); |
|
637 |
show( Fmt.fmt( 123.456F, 0, 5 ) ); |
|
638 |
show( Fmt.fmt( 123.456F, 0, 4 ) ); |
|
639 |
show( Fmt.fmt( 123.456F, 0, 3 ) ); |
|
640 |
show( Fmt.fmt( 123.456F, 0, 2 ) ); |
|
641 |
show( Fmt.fmt( 123.456F, 0, 1 ) ); |
|
642 |
show( Fmt.fmt( 123456000000000000.0F, 0, 4 ) ); |
|
643 |
show( Fmt.fmt( -123.456F, 0, 4 ) ); |
|
644 |
show( Fmt.fmt( -123456000000000000.0F, 0, 4 ) ); |
|
645 |
show( Fmt.fmt( 123.0F ) ); |
|
646 |
show( Fmt.fmt( 123.0D ) ); |
|
647 |
show( Fmt.fmt( 1.234567890123456789F ) ); |
|
648 |
show( Fmt.fmt( 1.234567890123456789D ) ); |
|
649 |
show( Fmt.fmt( 1234567890123456789F ) ); |
|
650 |
show( Fmt.fmt( 1234567890123456789D ) ); |
|
651 |
show( Fmt.fmt( 0.000000000000000000001234567890123456789F ) ); |
|
652 |
show( Fmt.fmt( 0.000000000000000000001234567890123456789D ) ); |
|
653 |
show( Fmt.fmt( 12300.0F ) ); |
|
654 |
show( Fmt.fmt( 12300.0D ) ); |
|
655 |
show( Fmt.fmt( 123000.0F ) ); |
|
656 |
show( Fmt.fmt( 123000.0D ) ); |
|
657 |
show( Fmt.fmt( 1230000.0F ) ); |
|
658 |
show( Fmt.fmt( 1230000.0D ) ); |
|
659 |
show( Fmt.fmt( 12300000.0F ) ); |
|
660 |
show( Fmt.fmt( 12300000.0D ) ); |
|
661 |
show( Fmt.fmt( Float.NaN ) ); |
|
662 |
show( Fmt.fmt( Float.POSITIVE_INFINITY ) ); |
|
663 |
show( Fmt.fmt( Float.NEGATIVE_INFINITY ) ); |
|
664 |
show( Fmt.fmt( Double.NaN ) ); |
|
665 |
show( Fmt.fmt( Double.POSITIVE_INFINITY ) ); |
|
666 |
show( Fmt.fmt( Double.NEGATIVE_INFINITY ) ); |
|
667 |
show( Fmt.fmt( 1.0F / 8.0F ) ); |
|
668 |
show( Fmt.fmt( 1.0D / 8.0D ) ); |
|
669 |
System.out.println( "Done with tests." ); |
|
670 |
} |
|
671 |
|
|
672 |
private static void show( String str ) |
|
673 |
{ |
|
674 |
System.out.println( "#" + str + "#" ); |
|
675 |
} |
|
676 |
******************************************************************************/ |
|
677 |
} |
|
0 | 678 |
tags/v2_0_0_Build_2020/applications/appgvSIG/src/com/vividsolutions/jump/util/DebugTimer.java | ||
---|---|---|
1 |
|
|
2 |
/* |
|
3 |
* The Unified Mapping Platform (JUMP) is an extensible, interactive GUI |
|
4 |
* for visualizing and manipulating spatial features with geometry and attributes. |
|
5 |
* |
|
6 |
* Copyright (C) 2003 Vivid Solutions |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Vivid Solutions |
|
25 |
* Suite #1A |
|
26 |
* 2328 Government Street |
|
27 |
* Victoria BC V8T 5G5 |
|
28 |
* Canada |
|
29 |
* |
|
30 |
* (250)385-6040 |
|
31 |
* www.vividsolutions.com |
|
32 |
*/ |
|
33 |
|
|
34 |
package com.vividsolutions.jump.util; |
|
35 |
|
|
36 |
import com.vividsolutions.jts.util.Stopwatch; |
|
37 |
|
|
38 |
|
|
39 |
public class DebugTimer { |
|
40 |
private static final int TIME_LEN = 10; |
|
41 |
private static DebugTimer timer = new DebugTimer(); |
|
42 |
private Stopwatch sw = null; |
|
43 |
private String blankStr; |
|
44 |
|
|
45 |
public DebugTimer() { |
|
46 |
sw = new Stopwatch(); |
|
47 |
sw.start(); |
|
48 |
blankStr = fillString(TIME_LEN, ' '); |
|
49 |
} |
|
50 |
|
|
51 |
public static void startStatic(String msg) { |
|
52 |
timer.start(msg); |
|
53 |
} |
|
54 |
|
|
55 |
public static void logEventStatic(String msg) { |
|
56 |
timer.logEvent(msg); |
|
57 |
} |
|
58 |
|
|
59 |
public void start(String msg) { |
|
60 |
System.out.println("Started " + msg); |
|
61 |
sw.start(); |
|
62 |
} |
|
63 |
|
|
64 |
public void logEvent(String msg) { |
|
65 |
String elapsedStr = formatTime(sw.getTimeString()); |
|
66 |
System.out.println("Elapsed: " + elapsedStr + " " + msg); |
|
67 |
sw.start(); |
|
68 |
} |
|
69 |
|
|
70 |
public String formatTime(String timeStr) { |
|
71 |
if (timeStr.length() < TIME_LEN) { |
|
72 |
String filled = blankStr + timeStr; |
|
73 |
int start = filled.length() - TIME_LEN; |
|
74 |
|
|
75 |
return filled.substring(start); |
|
76 |
} |
|
77 |
|
|
78 |
// don't pad if it's already longer |
|
79 |
return timeStr; |
|
80 |
} |
|
81 |
|
|
82 |
public String fillString(int len, char ch) { |
|
83 |
StringBuffer buf = new StringBuffer(len); |
|
84 |
|
|
85 |
for (int i = 0; i < len; i++) { |
|
86 |
buf.append(ch); |
|
87 |
} |
|
88 |
|
|
89 |
return buf.toString(); |
|
90 |
} |
|
91 |
} |
|
0 | 92 |
tags/v2_0_0_Build_2020/applications/appgvSIG/src/com/vividsolutions/jump/util/MathUtil.java | ||
---|---|---|
1 |
|
|
2 |
/* |
|
3 |
* The Unified Mapping Platform (JUMP) is an extensible, interactive GUI |
|
4 |
* for visualizing and manipulating spatial features with geometry and attributes. |
|
5 |
* |
|
6 |
* Copyright (C) 2003 Vivid Solutions |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Vivid Solutions |
|
25 |
* Suite #1A |
|
26 |
* 2328 Government Street |
|
27 |
* Victoria BC V8T 5G5 |
|
28 |
* Canada |
|
29 |
* |
|
30 |
* (250)385-6040 |
|
31 |
* www.vividsolutions.com |
|
32 |
*/ |
|
33 |
|
|
34 |
package com.vividsolutions.jump.util; |
|
35 |
|
|
36 |
|
|
37 |
/** |
|
38 |
* Additional math utilities. |
|
39 |
* @see Math |
|
40 |
*/ |
|
41 |
public class MathUtil { |
|
42 |
public MathUtil() { |
|
43 |
} |
|
44 |
|
|
45 |
public static double orderOfMagnitude(double x) { |
|
46 |
return base10Log(x); |
|
47 |
} |
|
48 |
|
|
49 |
public static double base10Log(double x) { |
|
50 |
return Math.log(x) / Math.log(10); |
|
51 |
} |
|
52 |
|
|
53 |
public static int mostSignificantDigit(double x) { |
|
54 |
return (int) (x / Math.pow(10, Math.floor(MathUtil.orderOfMagnitude(x)))); |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* Returns the average of two doubles |
|
59 |
* @param a one of the doubles to average |
|
60 |
* @param b the other double to average |
|
61 |
* @return the average of two doubles |
|
62 |
*/ |
|
63 |
public static double avg(double a, double b) { |
|
64 |
return (a + b) / 2d; |
|
65 |
} |
|
66 |
} |
|
0 | 67 |
tags/v2_0_0_Build_2020/applications/appgvSIG/src/com/vividsolutions/jump/util/CollectionMap.java | ||
---|---|---|
1 |
|
|
2 |
/* |
|
3 |
* The Unified Mapping Platform (JUMP) is an extensible, interactive GUI |
|
4 |
* for visualizing and manipulating spatial features with geometry and attributes. |
|
5 |
* |
|
6 |
* Copyright (C) 2003 Vivid Solutions |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Vivid Solutions |
|
25 |
* Suite #1A |
|
26 |
* 2328 Government Street |
|
27 |
* Victoria BC V8T 5G5 |
|
28 |
* Canada |
|
29 |
* |
|
30 |
* (250)385-6040 |
|
31 |
* www.vividsolutions.com |
|
32 |
*/ |
|
33 |
|
|
34 |
package com.vividsolutions.jump.util; |
|
35 |
|
|
36 |
import java.util.ArrayList; |
|
37 |
import java.util.Collection; |
|
38 |
import java.util.Collections; |
|
39 |
import java.util.HashMap; |
|
40 |
import java.util.Iterator; |
|
41 |
import java.util.Map; |
|
42 |
import java.util.Set; |
|
43 |
|
|
44 |
import com.vividsolutions.jts.util.Assert; |
|
45 |
|
|
46 |
|
|
47 |
/** |
|
48 |
* A Map whose values are Collections. |
|
49 |
*/ |
|
50 |
public class CollectionMap implements Map { |
|
51 |
private Map map; |
|
52 |
private Class collectionClass = ArrayList.class; |
|
53 |
|
|
54 |
/** |
|
55 |
* Creates a CollectionMap backed by the given Map class. |
|
56 |
* @param mapClass a Class that implements Map |
|
57 |
*/ |
|
58 |
public CollectionMap(Class mapClass) { |
|
59 |
try { |
|
60 |
map = (Map) mapClass.newInstance(); |
|
61 |
} catch (InstantiationException e) { |
|
62 |
Assert.shouldNeverReachHere(); |
|
63 |
} catch (IllegalAccessException e) { |
|
64 |
Assert.shouldNeverReachHere(); |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
public CollectionMap(Class mapClass, Class collectionClass) { |
|
69 |
this.collectionClass = collectionClass; |
|
70 |
try { |
|
71 |
map = (Map) mapClass.newInstance(); |
|
72 |
} catch (InstantiationException e) { |
|
73 |
Assert.shouldNeverReachHere(); |
|
74 |
} catch (IllegalAccessException e) { |
|
75 |
Assert.shouldNeverReachHere(); |
|
76 |
} |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* Creates a CollectionMap. |
|
81 |
*/ |
|
82 |
public CollectionMap() { |
|
83 |
this(HashMap.class); |
|
84 |
} |
|
85 |
|
|
86 |
private Collection getItemsInternal(Object key) { |
|
87 |
Collection collection = (Collection) map.get(key); |
|
88 |
if (collection == null) { |
|
89 |
try { |
|
90 |
collection = (Collection) collectionClass.newInstance(); |
|
91 |
} catch (InstantiationException e) { |
|
92 |
Assert.shouldNeverReachHere(); |
|
93 |
} catch (IllegalAccessException e) { |
|
94 |
Assert.shouldNeverReachHere(); |
|
95 |
} |
|
96 |
map.put(key, collection); |
|
97 |
} |
|
98 |
return collection; |
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* Adds the item to the Collection at the given key, creating a new Collection if |
|
103 |
* necessary. |
|
104 |
* @param key the key to the Collection to which the item should be added |
|
105 |
* @param item the item to add |
|
106 |
*/ |
|
107 |
public void addItem(Object key, Object item) { |
|
108 |
getItemsInternal(key).add(item); |
|
109 |
} |
|
110 |
|
|
111 |
public void removeItem(Object key, Object item) { |
|
112 |
getItemsInternal(key).remove(item); |
|
113 |
} |
|
114 |
|
|
115 |
public void clear() { |
|
116 |
map.clear(); |
|
117 |
} |
|
118 |
|
|
119 |
/** |
|
120 |
* Adds the items to the Collection at the given key, creating a new Collection if |
|
121 |
* necessary. |
|
122 |
* @param key the key to the Collection to which the items should be added |
|
123 |
* @param items the items to add |
|
124 |
*/ |
|
125 |
public void addItems(Object key, Collection items) { |
|
126 |
for (Iterator i = items.iterator(); i.hasNext();) { |
|
127 |
addItem(key, i.next()); |
|
128 |
} |
|
129 |
} |
|
130 |
|
|
131 |
public void addItems(CollectionMap other) { |
|
132 |
for (Iterator i = other.keySet().iterator(); i.hasNext(); ) { |
|
133 |
Object key = i.next(); |
|
134 |
addItems(key, other.getItems(key)); |
|
135 |
} |
|
136 |
} |
|
137 |
|
|
138 |
/** |
|
139 |
* Returns the values. |
|
140 |
* @return a view of the values, backed by this CollectionMap |
|
141 |
*/ |
|
142 |
public Collection values() { |
|
143 |
return map.values(); |
|
144 |
} |
|
145 |
|
|
146 |
/** |
|
147 |
* Returns the keys. |
|
148 |
* @return a view of the keys, backed by this CollectionMap |
|
149 |
*/ |
|
150 |
public Set keySet() { |
|
151 |
return map.keySet(); |
Also available in: Unified diff