TogaGemは、3D動画制作ツール、MikuMikuDance(MMD)で用いられる各種データファイルを読み書きするためのJavaライブラリです。
旧TogaParserライブラリの資産は、TogaGemライブラリに吸収されました。
Revision | 61e60f5daf0ec483a80f8045cb3eca8039445f7e (tree) |
---|---|
Zeit | 2019-06-04 22:32:31 |
Autor | ![]() |
Commiter | Olyutorskii |
Merge release/v3.120.2
@@ -4,6 +4,9 @@ | ||
4 | 4 | TogaGem 変更履歴 |
5 | 5 | |
6 | 6 | |
7 | +3.120.2 (2019-06-04) | |
8 | + ・replacing JAXB DatatypeConverter. | |
9 | + | |
7 | 10 | 3.101.106 (2019-06-02) |
8 | 11 | ・必須環境をJavaSE8に引き上げ。 |
9 | 12 | ・Mercurial(3.102.4)からGit(3.101.105-SNAPSHOT)へSCMを移行。 |
@@ -31,12 +31,17 @@ | ||
31 | 31 | <suppress files="" checks="ImportControl" /> |
32 | 32 | |
33 | 33 | <!-- Javadoc Comments --> |
34 | + <suppress files="" checks="JavadocParagraph" /> | |
35 | + <suppress files="" checks="JavadocTagContinuationIndentation" /> | |
34 | 36 | <suppress files="" checks="SummaryJavadocCheck" /> |
35 | 37 | |
36 | 38 | <!-- Miscellaneous --> |
37 | 39 | <suppress files="" checks="FinalParameters" /> |
38 | 40 | <suppress files="" checks="TrailingComment" /> |
39 | 41 | |
42 | + <!-- Modifier --> | |
43 | + <suppress files="" checks="InterfaceMemberImpliedModifier" /> | |
44 | + | |
40 | 45 | <!-- Whitespace --> |
41 | 46 | <suppress files="" checks="SingleSpaceSeparator" /> |
42 | 47 |
@@ -6,7 +6,7 @@ | ||
6 | 6 | |
7 | 7 | <!-- |
8 | 8 | Checkstyle modules |
9 | - for Checkstyle 8.20 or later | |
9 | + for Checkstyle 8.21 or later | |
10 | 10 | |
11 | 11 | [ https://checkstyle.org/ ] |
12 | 12 |
@@ -20,11 +20,12 @@ | ||
20 | 20 | <property name="localeCountry" value="JP" /> |
21 | 21 | <property name="localeLanguage" value="en" /> |
22 | 22 | <!--property name="localeLanguage" value="ja" /--> |
23 | - <property name="fileExtensions" value="java, xml, properties" /> | |
23 | + <property name="fileExtensions" value="java, properties, xml, xsd, md, txt" /> | |
24 | 24 | <property name="severity" value="error" /> |
25 | 25 | |
26 | 26 | |
27 | 27 | <!-- Filters --> |
28 | + | |
28 | 29 | <module name="SeverityMatchFilter" /> |
29 | 30 | <!--module name="SuppressionFilter" /--> |
30 | 31 | <module name="SuppressWarningsFilter" /> |
@@ -32,6 +33,7 @@ | ||
32 | 33 | |
33 | 34 | |
34 | 35 | <!-- Headers --> |
36 | + | |
35 | 37 | <module name="Header"> |
36 | 38 | <property name="header" value="<?xml version="1.0" encoding="UTF-8" ?>" /> |
37 | 39 | <property name="fileExtensions" value="xml" /> |
@@ -44,18 +46,21 @@ | ||
44 | 46 | |
45 | 47 | |
46 | 48 | <!-- Javadoc Comments --> |
49 | + | |
47 | 50 | <module name="JavadocPackage" /> |
48 | 51 | |
49 | 52 | |
50 | 53 | <!-- Miscellaneous --> |
54 | + | |
51 | 55 | <module name="NewlineAtEndOfFile"> |
52 | - <property name="fileExtensions" value="java" /> | |
56 | + <property name="fileExtensions" value="java, properties, xml, xsd, md, txt" /> | |
53 | 57 | </module> |
54 | 58 | <module name="Translation" /> |
55 | 59 | <module name="UniqueProperties" /> |
56 | 60 | |
57 | 61 | |
58 | 62 | <!-- Regexp --> |
63 | + | |
59 | 64 | <module name="RegexpMultiline"> |
60 | 65 | <property name="format" value="[\u000b\f\u001a]" /> |
61 | 66 | </module> |
@@ -70,10 +75,12 @@ | ||
70 | 75 | |
71 | 76 | |
72 | 77 | <!-- Size Violations --> |
78 | + | |
73 | 79 | <module name="FileLength" /> |
74 | 80 | |
75 | 81 | |
76 | 82 | <!-- Whitespace --> |
83 | + | |
77 | 84 | <module name="FileTabCharacter" /> |
78 | 85 | |
79 | 86 |
@@ -188,7 +195,9 @@ | ||
188 | 195 | <module name="SuperClone" /> |
189 | 196 | <module name="SuperFinalize" /> |
190 | 197 | <module name="UnnecessaryParentheses" /> |
191 | - <module name="VariableDeclarationUsageDistance" /> | |
198 | + <module name="VariableDeclarationUsageDistance"> | |
199 | + <property name="allowedDistance" value="5"/> | |
200 | + </module> | |
192 | 201 | |
193 | 202 | |
194 | 203 | <!-- Imports --> |
@@ -220,6 +229,8 @@ | ||
220 | 229 | <module name="JavadocVariable"> |
221 | 230 | <property name="scope" value="protected" /> |
222 | 231 | </module> |
232 | + <module name="MissingJavadocMethod" /> | |
233 | + <module name="MissingJavadocType" /> | |
223 | 234 | <module name="NonEmptyAtclauseDescription" /> |
224 | 235 | <module name="SingleLineJavadoc" /> |
225 | 236 | <module name="SummaryJavadocCheck" /> |
@@ -344,8 +355,17 @@ | ||
344 | 355 | <module name="NoWhitespaceAfter" /> |
345 | 356 | <module name="NoWhitespaceBefore" /> |
346 | 357 | <module name="OperatorWrap" /> |
347 | - <module name="ParenPad" /> | |
348 | - <module name="SeparatorWrap" /> | |
358 | + <module name="ParenPad"> | |
359 | + <property name="option" value="nospace" /> | |
360 | + <property | |
361 | + name="tokens" | |
362 | + value="CTOR_CALL, METHOD_CALL, SUPER_CTOR_CALL" | |
363 | + /> | |
364 | + </module> | |
365 | + <module name="SeparatorWrap"> | |
366 | + <property name="tokens" value="DOT"/> | |
367 | + <property name="option" value="nl"/> | |
368 | + </module> | |
349 | 369 | <module name="SingleSpaceSeparator" /> |
350 | 370 | <module name="TypecastParenPad" /> |
351 | 371 | <module name="WhitespaceAfter" > |
@@ -16,7 +16,7 @@ | ||
16 | 16 | <groupId>jp.sourceforge.mikutoga</groupId> |
17 | 17 | <artifactId>togagem</artifactId> |
18 | 18 | |
19 | - <version>3.101.106</version> | |
19 | + <version>3.120.2</version> | |
20 | 20 | |
21 | 21 | <packaging>jar</packaging> |
22 | 22 | <name>TogaGem</name> |
@@ -96,16 +96,15 @@ | ||
96 | 96 | <detectJavaApiLink>false</detectJavaApiLink> |
97 | 97 | |
98 | 98 | <surefire-plugin.version>3.0.0-M3</surefire-plugin.version> |
99 | - <jacoco-plugin.version>0.8.3</jacoco-plugin.version> | |
99 | + <jacoco-plugin.version>0.8.4</jacoco-plugin.version> | |
100 | 100 | |
101 | - <checkstyle-plugin.version>3.0.0</checkstyle-plugin.version> | |
102 | - <checkstyleruntime.version>8.20</checkstyleruntime.version> | |
101 | + <checkstyle-plugin.version>3.1.0</checkstyle-plugin.version> | |
102 | + <checkstyleruntime.version>8.21</checkstyleruntime.version> | |
103 | 103 | <checkstyle.config.location>${project.basedir}/config/checkstyle/checkstyle.xml</checkstyle.config.location> |
104 | 104 | <checkstyle.suppressions.location>${project.basedir}/config/checkstyle/checkstyle-suppressions.xml</checkstyle.suppressions.location> |
105 | 105 | <checkstyle.enable.rss>false</checkstyle.enable.rss> |
106 | 106 | |
107 | 107 | <pmd-plugin.version>3.12.0</pmd-plugin.version> |
108 | - <pmd.analysisCache>true</pmd.analysisCache> | |
109 | 108 | |
110 | 109 | <spotbugs-plugin.version>3.1.11</spotbugs-plugin.version> |
111 | 110 | <spotbugs.effort>Max</spotbugs.effort> |
@@ -202,8 +201,7 @@ | ||
202 | 201 | <version>[3.3.9,)</version> |
203 | 202 | </requireMavenVersion> |
204 | 203 | <requireJavaVersion> |
205 | - <!-- JAXB --> | |
206 | - <version>1.8</version> | |
204 | + <version>[1.8,)</version> | |
207 | 205 | </requireJavaVersion> |
208 | 206 | </rules> |
209 | 207 | </configuration> |
@@ -220,7 +218,7 @@ | ||
220 | 218 | <plugin> |
221 | 219 | <groupId>org.apache.maven.plugins</groupId> |
222 | 220 | <artifactId>maven-compiler-plugin</artifactId> |
223 | - <version>3.8.0</version> | |
221 | + <version>3.8.1</version> | |
224 | 222 | <configuration> |
225 | 223 | <source>1.8</source> <!-- for NetBeans IDE --> |
226 | 224 | <target>1.8</target> |
@@ -285,7 +283,7 @@ | ||
285 | 283 | <plugin> |
286 | 284 | <groupId>org.apache.maven.plugins</groupId> |
287 | 285 | <artifactId>maven-jar-plugin</artifactId> |
288 | - <version>3.1.1</version> | |
286 | + <version>3.1.2</version> | |
289 | 287 | <configuration> |
290 | 288 | <archive> |
291 | 289 | <manifest> |
@@ -303,7 +301,7 @@ | ||
303 | 301 | <plugin> |
304 | 302 | <groupId>org.apache.maven.plugins</groupId> |
305 | 303 | <artifactId>maven-source-plugin</artifactId> |
306 | - <version>3.0.1</version> | |
304 | + <version>3.1.0</version> | |
307 | 305 | <configuration> |
308 | 306 | <includePom>true</includePom> |
309 | 307 | <archive> |
@@ -8,9 +8,6 @@ | ||
8 | 8 | package jp.sfjp.mikutoga.xml; |
9 | 9 | |
10 | 10 | import java.io.IOException; |
11 | -import java.util.regex.Matcher; | |
12 | -import java.util.regex.Pattern; | |
13 | -import javax.xml.bind.DatatypeConverter; | |
14 | 11 | |
15 | 12 | /** |
16 | 13 | * Appendable実装に依存したXMLエクスポータの半実装。 |
@@ -35,9 +32,6 @@ abstract class AbstractXmlExporter implements XmlExporter{ | ||
35 | 32 | private static final String COMM_START = "<!--"; |
36 | 33 | private static final String COMM_END = "-->"; |
37 | 34 | |
38 | - private static final Pattern NUM_FUZZY = | |
39 | - Pattern.compile("([^.]*\\.[0-9][0-9]*?)0+"); | |
40 | - | |
41 | 35 | private static final String REF_HEX = "&#x"; |
42 | 36 | private static final int HEX_EXP = 4; // 2 ** 4 == 16 |
43 | 37 | private static final int MASK_1HEX = (1 << HEX_EXP) - 1; // 0b00001111 |
@@ -84,28 +78,6 @@ abstract class AbstractXmlExporter implements XmlExporter{ | ||
84 | 78 | return false; |
85 | 79 | } |
86 | 80 | |
87 | - /** | |
88 | - * 冗長な実数出力を抑止する。 | |
89 | - * <p>DatatypeConverterにおけるJDK1.6系と1.7系の仕様変更を吸収する。 | |
90 | - * <p>0.001fは"0.0010"ではなく"0.001"と出力される。 | |
91 | - * <p>指数表記での冗長桁は無視する。 | |
92 | - * @param numTxt 実数表記 | |
93 | - * @return 冗長桁が抑止された実数表記 | |
94 | - * @see javax.xml.bind.DatatypeConverter | |
95 | - */ | |
96 | - protected static String chopFuzzyZero(String numTxt){ | |
97 | - String result; | |
98 | - | |
99 | - Matcher matcher = NUM_FUZZY.matcher(numTxt); | |
100 | - if(matcher.matches()){ | |
101 | - result = matcher.group(1); | |
102 | - }else{ | |
103 | - result = numTxt; | |
104 | - } | |
105 | - | |
106 | - return result; | |
107 | - } | |
108 | - | |
109 | 81 | |
110 | 82 | /** |
111 | 83 | * {@inheritDoc} |
@@ -617,7 +589,7 @@ abstract class AbstractXmlExporter implements XmlExporter{ | ||
617 | 589 | */ |
618 | 590 | @Override |
619 | 591 | public XmlExporter putXsdInt(int iVal) throws IOException{ |
620 | - String value = DatatypeConverter.printInt(iVal); | |
592 | + String value = DatatypeIo.printInt(iVal); | |
621 | 593 | putRawText(value); |
622 | 594 | return this; |
623 | 595 | } |
@@ -630,8 +602,7 @@ abstract class AbstractXmlExporter implements XmlExporter{ | ||
630 | 602 | */ |
631 | 603 | @Override |
632 | 604 | public XmlExporter putXsdFloat(float fVal) throws IOException{ |
633 | - String value = DatatypeConverter.printFloat(fVal); | |
634 | - value = chopFuzzyZero(value); | |
605 | + String value = DatatypeIo.printFloat(fVal); | |
635 | 606 | putRawText(value); |
636 | 607 | return this; |
637 | 608 | } |
@@ -0,0 +1,225 @@ | ||
1 | +/* | |
2 | + * XML Schema datatypes input/output | |
3 | + * | |
4 | + * License : The MIT License | |
5 | + * Copyright(c) 2019 MikuToga Partners | |
6 | + */ | |
7 | + | |
8 | +package jp.sfjp.mikutoga.xml; | |
9 | + | |
10 | +/** | |
11 | + * XSD datatypes I/O utilities. | |
12 | + * | |
13 | + * <p>This class replaces javax.xml.bind.DatatypeConverter(JAXB) subset. | |
14 | + * JAXB is not part of JDK9 or later. | |
15 | + * | |
16 | + * @see <a href="https://www.w3.org/TR/xmlschema-2/"> | |
17 | + * XML Schema Part 2: Datatypes Second Edition | |
18 | + * </a> | |
19 | + * @see <a href="https://docs.oracle.com/javase/8/docs/api/javax/xml/bind/DatatypeConverter.html"> | |
20 | + * JavaSE8:DatatypeConverter | |
21 | + * </a> | |
22 | + */ | |
23 | +final class DatatypeIo { | |
24 | + | |
25 | + /** | |
26 | + * Hidden constructor. | |
27 | + */ | |
28 | + private DatatypeIo(){ | |
29 | + assert false; | |
30 | + } | |
31 | + | |
32 | + /** | |
33 | + * Converts an int value into a string as xsd:int. | |
34 | + * | |
35 | + * @param iVal int value | |
36 | + * @return xsd:int type text | |
37 | + */ | |
38 | + public static String printInt(int iVal){ | |
39 | + String result; | |
40 | + result = String.valueOf(iVal); | |
41 | + return result; | |
42 | + } | |
43 | + | |
44 | + /** | |
45 | + * Converts an float value into a string as xsd:float. | |
46 | + * | |
47 | + * <p>Infinite value will be "INF". | |
48 | + * | |
49 | + * @param fVal float value | |
50 | + * @return xsd:float type text | |
51 | + */ | |
52 | + public static String printFloat(float fVal){ | |
53 | + String result; | |
54 | + | |
55 | + if(fVal == Float.POSITIVE_INFINITY){ | |
56 | + result = "INF"; | |
57 | + }else if(fVal == Float.NEGATIVE_INFINITY){ | |
58 | + result = "-INF"; | |
59 | + }else{ | |
60 | + result = String.valueOf(fVal); | |
61 | + } | |
62 | + | |
63 | + return result; | |
64 | + } | |
65 | + | |
66 | + /** | |
67 | + * trimming whitespace around XSD datatypes value. | |
68 | + * | |
69 | + * @param txt XSD value | |
70 | + * @return trimmed text | |
71 | + */ | |
72 | + public static CharSequence xsdTrim(CharSequence txt){ | |
73 | + int length = txt.length(); | |
74 | + int startPos = 0; | |
75 | + int endPos = length; | |
76 | + | |
77 | + for(int pt = 0; pt < length; pt++){ | |
78 | + char ch = txt.charAt(pt); | |
79 | + if(!isXsdWhitespace(ch)){ | |
80 | + startPos = pt; | |
81 | + break; | |
82 | + } | |
83 | + } | |
84 | + | |
85 | + for(int pt = length - 1; pt >= 0; pt--){ | |
86 | + char ch = txt.charAt(pt); | |
87 | + if(!isXsdWhitespace(ch)){ | |
88 | + endPos = pt + 1; | |
89 | + break; | |
90 | + } | |
91 | + } | |
92 | + | |
93 | + CharSequence result = txt.subSequence(startPos, endPos); | |
94 | + | |
95 | + return result; | |
96 | + } | |
97 | + | |
98 | + /** | |
99 | + * checking whitespace character around XSD datattypes. | |
100 | + * | |
101 | + * <p>\n, \r, \t, and \0020 are whitespace. | |
102 | + * | |
103 | + * @param ch character | |
104 | + * @return true if whitespace | |
105 | + */ | |
106 | + public static boolean isXsdWhitespace(char ch){ | |
107 | + boolean result; | |
108 | + | |
109 | + switch(ch){ | |
110 | + case '\n': | |
111 | + case '\r': | |
112 | + case '\t': | |
113 | + case '\u0020': | |
114 | + result = true; | |
115 | + break; | |
116 | + default: | |
117 | + result = false; | |
118 | + break; | |
119 | + } | |
120 | + | |
121 | + return result; | |
122 | + } | |
123 | + | |
124 | + /** | |
125 | + * Converts the xsd:boolean string argument into a boolean value. | |
126 | + * | |
127 | + * <p>{"true", "1"} is true. {"false", "0"} is false. | |
128 | + * | |
129 | + * @param xsdVal xsd:boolean string | |
130 | + * @return true if true | |
131 | + * @throws IllegalArgumentException illegal xsd:boolean string | |
132 | + */ | |
133 | + public static boolean parseBoolean(CharSequence xsdVal) | |
134 | + throws IllegalArgumentException{ | |
135 | + boolean result; | |
136 | + | |
137 | + CharSequence trimmed = xsdTrim(xsdVal); | |
138 | + | |
139 | + if("true".contentEquals(trimmed)){ | |
140 | + result = true; | |
141 | + }else if("false".contentEquals(trimmed)){ | |
142 | + result = false; | |
143 | + }else if("0".contentEquals(trimmed)){ | |
144 | + result = false; | |
145 | + }else if("1".contentEquals(trimmed)){ | |
146 | + result = true; | |
147 | + }else{ | |
148 | + throw new IllegalArgumentException(trimmed.toString()); | |
149 | + } | |
150 | + | |
151 | + return result; | |
152 | + } | |
153 | + | |
154 | + /** | |
155 | + * Converts the xsd:byte string argument into a byte value. | |
156 | + * | |
157 | + * @param xsdVal xsd:byte string | |
158 | + * @return byte value | |
159 | + * @throws NumberFormatException illegal xsd:byte | |
160 | + */ | |
161 | + public static byte parseByte(CharSequence xsdVal) | |
162 | + throws NumberFormatException{ | |
163 | + CharSequence trimmed = xsdTrim(xsdVal); | |
164 | + | |
165 | + int iVal; | |
166 | + iVal = Integer.parseInt(trimmed.toString()); | |
167 | + | |
168 | + if(iVal < -128 || 127 < iVal){ | |
169 | + throw new NumberFormatException(xsdVal.toString()); | |
170 | + } | |
171 | + | |
172 | + byte result; | |
173 | + result = (byte)iVal; | |
174 | + | |
175 | + return result; | |
176 | + } | |
177 | + | |
178 | + /** | |
179 | + * Converts the xsd:int string argument into a int value. | |
180 | + * | |
181 | + * @param xsdVal xsd:int string | |
182 | + * @return int value | |
183 | + * @throws NumberFormatException illegal xsd:int | |
184 | + */ | |
185 | + public static int parseInt(CharSequence xsdVal) | |
186 | + throws NumberFormatException{ | |
187 | + CharSequence trimmed = xsdTrim(xsdVal); | |
188 | + int result; | |
189 | + result = Integer.parseInt(trimmed.toString()); | |
190 | + return result; | |
191 | + } | |
192 | + | |
193 | + /** | |
194 | + * Converts the xsd:float string argument into a float value. | |
195 | + * | |
196 | + * @param xsdVal xsd:float string | |
197 | + * @return float value | |
198 | + * @throws NumberFormatException illegal xsd:float | |
199 | + */ | |
200 | + public static float parseFloat(CharSequence xsdVal) | |
201 | + throws NumberFormatException{ | |
202 | + String trimmed = xsdTrim(xsdVal).toString(); | |
203 | + | |
204 | + float result; | |
205 | + if("INF".equals(trimmed)){ | |
206 | + result = Float.POSITIVE_INFINITY; | |
207 | + }else if("-INF".equals(trimmed)){ | |
208 | + result = Float.NEGATIVE_INFINITY; | |
209 | + }else if(trimmed.endsWith("Infinity")){ | |
210 | + throw new NumberFormatException(trimmed); | |
211 | + }else if(trimmed.contains("x") || trimmed.contains("X")){ | |
212 | + // HexFloatingPointLiteral | |
213 | + throw new NumberFormatException(trimmed); | |
214 | + }else{ | |
215 | + // zero will happen when underflow. | |
216 | + // infinite will happen when overflow. | |
217 | + // NaN is NaN. | |
218 | + // -0 is minus zero. | |
219 | + result = Float.parseFloat(trimmed); | |
220 | + } | |
221 | + | |
222 | + return result; | |
223 | + } | |
224 | + | |
225 | +} |
@@ -9,7 +9,6 @@ package jp.sfjp.mikutoga.xml; | ||
9 | 9 | |
10 | 10 | import java.text.MessageFormat; |
11 | 11 | import java.util.Iterator; |
12 | -import javax.xml.bind.DatatypeConverter; | |
13 | 12 | import org.w3c.dom.DOMException; |
14 | 13 | import org.w3c.dom.Element; |
15 | 14 | import org.w3c.dom.Node; |
@@ -223,7 +222,7 @@ public final class DomNsUtils { | ||
223 | 222 | |
224 | 223 | boolean result; |
225 | 224 | try{ |
226 | - result = DatatypeConverter.parseBoolean(value); | |
225 | + result = DatatypeIo.parseBoolean(value); | |
227 | 226 | }catch(IllegalArgumentException e){ |
228 | 227 | String message = MessageFormat.format(ERRMSG_INVATTR, |
229 | 228 | localName, |
@@ -250,7 +249,7 @@ public final class DomNsUtils { | ||
250 | 249 | |
251 | 250 | int result; |
252 | 251 | try{ |
253 | - result = DatatypeConverter.parseInt(value); | |
252 | + result = DatatypeIo.parseInt(value); | |
254 | 253 | }catch(NumberFormatException e){ |
255 | 254 | String message = MessageFormat.format(ERRMSG_INVATTR, |
256 | 255 | localName, |
@@ -277,7 +276,7 @@ public final class DomNsUtils { | ||
277 | 276 | |
278 | 277 | float result; |
279 | 278 | try{ |
280 | - result = DatatypeConverter.parseFloat(value); | |
279 | + result = DatatypeIo.parseFloat(value); | |
281 | 280 | }catch(NumberFormatException e){ |
282 | 281 | String message = MessageFormat.format(ERRMSG_INVATTR, |
283 | 282 | localName, |
@@ -11,7 +11,6 @@ import java.util.Iterator; | ||
11 | 11 | import java.util.LinkedList; |
12 | 12 | import java.util.List; |
13 | 13 | import java.util.NoSuchElementException; |
14 | -import javax.xml.bind.DatatypeConverter; | |
15 | 14 | import org.w3c.dom.Element; |
16 | 15 | import org.w3c.dom.Node; |
17 | 16 |
@@ -72,7 +71,7 @@ public final class DomUtils { | ||
72 | 71 | |
73 | 72 | boolean result; |
74 | 73 | try{ |
75 | - result = DatatypeConverter.parseBoolean(value); | |
74 | + result = DatatypeIo.parseBoolean(value); | |
76 | 75 | }catch(IllegalArgumentException e){ |
77 | 76 | String message = |
78 | 77 | "Invalid boolean attribute form " |
@@ -96,7 +95,7 @@ public final class DomUtils { | ||
96 | 95 | |
97 | 96 | int result; |
98 | 97 | try{ |
99 | - result = DatatypeConverter.parseInt(value); | |
98 | + result = DatatypeIo.parseInt(value); | |
100 | 99 | }catch(IllegalArgumentException e){ |
101 | 100 | String message = |
102 | 101 | "Invalid integer attribute form " |
@@ -120,7 +119,7 @@ public final class DomUtils { | ||
120 | 119 | |
121 | 120 | float result; |
122 | 121 | try{ |
123 | - result = DatatypeConverter.parseFloat(value); | |
122 | + result = DatatypeIo.parseFloat(value); | |
124 | 123 | }catch(IllegalArgumentException e){ |
125 | 124 | String message = |
126 | 125 | "Invalid float attribute form " |
@@ -7,7 +7,6 @@ | ||
7 | 7 | |
8 | 8 | package jp.sfjp.mikutoga.xml; |
9 | 9 | |
10 | -import javax.xml.bind.DatatypeConverter; | |
11 | 10 | import org.xml.sax.Attributes; |
12 | 11 | |
13 | 12 | /** |
@@ -57,7 +56,7 @@ public final class SaxAttr { | ||
57 | 56 | throws IllegalArgumentException{ |
58 | 57 | String attrVal = attr.getValue(name); |
59 | 58 | boolean bVal; |
60 | - bVal = DatatypeConverter.parseBoolean(attrVal); | |
59 | + bVal = DatatypeIo.parseBoolean(attrVal); | |
61 | 60 | return bVal; |
62 | 61 | } |
63 | 62 |
@@ -77,7 +76,7 @@ public final class SaxAttr { | ||
77 | 76 | if(attrVal == null) return def; |
78 | 77 | |
79 | 78 | boolean bVal; |
80 | - bVal = DatatypeConverter.parseBoolean(attrVal); | |
79 | + bVal = DatatypeIo.parseBoolean(attrVal); | |
81 | 80 | |
82 | 81 | return bVal; |
83 | 82 | } |
@@ -93,7 +92,7 @@ public final class SaxAttr { | ||
93 | 92 | throws NumberFormatException{ |
94 | 93 | String attrVal = attr.getValue(name); |
95 | 94 | byte bVal; |
96 | - bVal = DatatypeConverter.parseByte(attrVal); | |
95 | + bVal = DatatypeIo.parseByte(attrVal); | |
97 | 96 | return bVal; |
98 | 97 | } |
99 | 98 |
@@ -108,7 +107,7 @@ public final class SaxAttr { | ||
108 | 107 | throws NumberFormatException { |
109 | 108 | String attrVal = attr.getValue(name); |
110 | 109 | float fVal; |
111 | - fVal = DatatypeConverter.parseFloat(attrVal); | |
110 | + fVal = DatatypeIo.parseFloat(attrVal); | |
112 | 111 | return fVal; |
113 | 112 | } |
114 | 113 |
@@ -123,7 +122,7 @@ public final class SaxAttr { | ||
123 | 122 | throws NumberFormatException { |
124 | 123 | String attrVal = attr.getValue(name); |
125 | 124 | int iVal; |
126 | - iVal = DatatypeConverter.parseInt(attrVal); | |
125 | + iVal = DatatypeIo.parseInt(attrVal); | |
127 | 126 | return iVal; |
128 | 127 | } |
129 | 128 |
@@ -41,12 +41,22 @@ public strictfp class MkQuatTest { | ||
41 | 41 | public void tearDown() { |
42 | 42 | } |
43 | 43 | |
44 | - private void assert0UlpEquals(double expected, double result){ | |
44 | + /** | |
45 | + * StrictMath.toRadians(6) results are not same between JDK8 & JDK9. | |
46 | + */ | |
47 | + private static double toRadians(double deg){ | |
48 | + double result = deg * 0.01745329251994329576924; | |
49 | +// assert StrictMath.toRadians(6) == 0.10471975511965977; //JDK8 | |
50 | +// assert StrictMath.toRadians(6) == 0.10471975511965978; //JDK9 | |
51 | + return result; | |
52 | + } | |
53 | + | |
54 | + private static void assert0UlpEquals(double expected, double result){ | |
45 | 55 | assertUlpEquals(expected, result, 0); |
46 | 56 | return; |
47 | 57 | } |
48 | 58 | |
49 | - private void assertUlpEquals(double expected, double result, int ulpNum){ | |
59 | + private static void assertUlpEquals(double expected, double result, int ulpNum){ | |
50 | 60 | double ulpExpected = StrictMath.ulp(expected); |
51 | 61 | double ulpResult = StrictMath.ulp(result); |
52 | 62 | double ulp = StrictMath.max(ulpExpected, ulpResult); |
@@ -434,14 +444,14 @@ public strictfp class MkQuatTest { | ||
434 | 444 | double yRad; |
435 | 445 | double zRad; |
436 | 446 | |
437 | - xRad = StrictMath.toRadians(95); | |
438 | - yRad = StrictMath.toRadians(0); | |
439 | - zRad = StrictMath.toRadians(0); | |
447 | + xRad = toRadians(95); | |
448 | + yRad = toRadians(0); | |
449 | + zRad = toRadians(0); | |
440 | 450 | qq.setEulerYXZ(xRad, yRad, zRad); |
441 | 451 | qq.toEulerYXZ(eu, yRad); |
442 | - assertUlpEquals(StrictMath.toRadians(85), eu.getXRot(), 1); | |
443 | - assertUlpEquals(StrictMath.toRadians(180), eu.getYRot(), 0); | |
444 | - assertUlpEquals(StrictMath.toRadians(180), eu.getZRot(), 0); | |
452 | + assertUlpEquals(toRadians(85), eu.getXRot(), 1); | |
453 | + assertUlpEquals(toRadians(180), eu.getYRot(), 0); | |
454 | + assertUlpEquals(toRadians(180), eu.getZRot(), 0); | |
445 | 455 | |
446 | 456 | return; |
447 | 457 | } |
@@ -462,9 +472,9 @@ public strictfp class MkQuatTest { | ||
462 | 472 | qq = new MkQuat(); |
463 | 473 | eu = new EulerYXZ(); |
464 | 474 | |
465 | - xRad = StrictMath.toRadians(89); | |
466 | - yRad = StrictMath.toRadians(80); | |
467 | - zRad = StrictMath.toRadians(41); | |
475 | + xRad = toRadians(89); | |
476 | + yRad = toRadians(80); | |
477 | + zRad = toRadians(41); | |
468 | 478 | qq.setEulerYXZ(xRad, yRad, zRad); |
469 | 479 | qq.toEulerYXZ(eu, 0.0); |
470 | 480 | assertUlpEquals(xRad, eu.getXRot(), 164); |
@@ -472,23 +482,23 @@ public strictfp class MkQuatTest { | ||
472 | 482 | assertUlpEquals(zRad, eu.getZRot(), 211); |
473 | 483 | |
474 | 484 | // ジンバルロック判定境界ケース |
475 | - xRad = StrictMath.toRadians(90); | |
476 | - yRad = StrictMath.toRadians(6); | |
477 | - zRad = StrictMath.toRadians(7); | |
485 | + xRad = toRadians(90); | |
486 | + yRad = toRadians(6); | |
487 | + zRad = toRadians(7); | |
478 | 488 | qq.setEulerYXZ(xRad, yRad, zRad); |
479 | 489 | qq.toEulerYXZ(eu, yRad); |
480 | 490 | assert0UlpEquals(xRad, eu.getXRot()); |
481 | 491 | assert0UlpEquals(yRad, eu.getYRot()); |
482 | - assert0UlpEquals(zRad, eu.getZRot()); | |
492 | + assertUlpEquals(zRad, eu.getZRot(), 1); | |
483 | 493 | |
484 | - xRad = StrictMath.toRadians(89.999); | |
485 | - yRad = StrictMath.toRadians(89.999); | |
486 | - zRad = StrictMath.toRadians(89.999); | |
494 | + xRad = toRadians(89.999); | |
495 | + yRad = toRadians(89.999); | |
496 | + zRad = toRadians(89.999); | |
487 | 497 | qq.setEulerYXZ(xRad, yRad, zRad); |
488 | 498 | qq.toEulerYXZ(eu, yRad); |
489 | 499 | assertUlpEquals(xRad, eu.getXRot(), 83029); |
490 | - assertUlpEquals(yRad, eu.getYRot(), 80108); | |
491 | - assertUlpEquals(zRad, eu.getZRot(), 80108); | |
500 | + assertUlpEquals(yRad, eu.getYRot(), 91782); | |
501 | + assertUlpEquals(zRad, eu.getZRot(), 91782); | |
492 | 502 | |
493 | 503 | return; |
494 | 504 | } |
@@ -668,9 +678,9 @@ public strictfp class MkQuatTest { | ||
668 | 678 | qq = new MkQuat(); |
669 | 679 | result = new EulerYXZ(); |
670 | 680 | |
671 | - double xRad = StrictMath.toRadians(ix); | |
672 | - double yRad = StrictMath.toRadians(iy); | |
673 | - double zRad = StrictMath.toRadians(iz); | |
681 | + double xRad = toRadians(ix); | |
682 | + double yRad = toRadians(iy); | |
683 | + double zRad = toRadians(iz); | |
674 | 684 | |
675 | 685 | qq.setEulerYXZ(xRad, yRad, zRad); |
676 | 686 | qq.toEulerYXZ(result, yRad); |
@@ -0,0 +1,172 @@ | ||
1 | +/* | |
2 | + */ | |
3 | + | |
4 | +package jp.sfjp.mikutoga.xml; | |
5 | + | |
6 | +import java.io.IOException; | |
7 | +import org.junit.After; | |
8 | +import org.junit.AfterClass; | |
9 | +import org.junit.Before; | |
10 | +import org.junit.BeforeClass; | |
11 | +import org.junit.Test; | |
12 | +import static org.junit.Assert.*; | |
13 | + | |
14 | +/** | |
15 | + * | |
16 | + */ | |
17 | +public class BasicXmlExporterTest { | |
18 | + | |
19 | + public BasicXmlExporterTest() { | |
20 | + } | |
21 | + | |
22 | + @BeforeClass | |
23 | + public static void setUpClass() { | |
24 | + } | |
25 | + | |
26 | + @AfterClass | |
27 | + public static void tearDownClass() { | |
28 | + } | |
29 | + | |
30 | + @Before | |
31 | + public void setUp() { | |
32 | + } | |
33 | + | |
34 | + @After | |
35 | + public void tearDown() { | |
36 | + } | |
37 | + | |
38 | + /** | |
39 | + * Test of append method, of class BasicXmlExporter. | |
40 | + */ | |
41 | + @Test | |
42 | + public void testAppend() { | |
43 | + System.out.println("setAppendable"); | |
44 | + | |
45 | + BasicXmlExporter instance; | |
46 | + Appendable app; | |
47 | + StringBuffer buf; | |
48 | + | |
49 | + instance = new BasicXmlExporter(); | |
50 | + | |
51 | + try{ | |
52 | + instance.append(null); | |
53 | + fail(); | |
54 | + }catch(NullPointerException e){ | |
55 | + assert true; | |
56 | + }catch(IOException e){ | |
57 | + fail(); | |
58 | + } | |
59 | + | |
60 | + buf = new StringBuffer(); | |
61 | + app = buf; | |
62 | + | |
63 | + instance.setAppendable(app); | |
64 | + | |
65 | + try{ | |
66 | + instance.append("abc"); | |
67 | + instance.append('d'); | |
68 | + instance.append("abcdef", 4, 5); | |
69 | + }catch(IOException e){ | |
70 | + fail(); | |
71 | + } | |
72 | + | |
73 | + assertEquals("abcde", buf.toString()); | |
74 | + | |
75 | + try{ | |
76 | + instance.flush(); | |
77 | + instance.close(); | |
78 | + }catch(IOException e){ | |
79 | + fail(); | |
80 | + } | |
81 | + | |
82 | + return; | |
83 | + } | |
84 | + | |
85 | + @Test | |
86 | + public void testPutXsdInt() throws IOException{ | |
87 | + System.out.println("putXsdInt"); | |
88 | + | |
89 | + BasicXmlExporter instance; | |
90 | + StringBuffer buf; | |
91 | + | |
92 | + instance = new BasicXmlExporter(); | |
93 | + | |
94 | + buf = new StringBuffer(); | |
95 | + instance.setAppendable(buf); | |
96 | + instance.putXsdInt(-1).putCh(',').putXsdInt(0).putCh(',').putXsdInt(1); | |
97 | + assertEquals("-1,0,1", buf.toString()); | |
98 | + | |
99 | + buf = new StringBuffer(); | |
100 | + instance.setAppendable(buf); | |
101 | + instance.putXsdInt(-999).putCh(',').putXsdInt(9999); | |
102 | + assertEquals("-999,9999", buf.toString()); | |
103 | + | |
104 | + buf = new StringBuffer(); | |
105 | + instance.setAppendable(buf); | |
106 | + instance.putXsdInt(Integer.MIN_VALUE).putCh(',').putXsdInt(Integer.MAX_VALUE); | |
107 | + assertEquals("-2147483648,2147483647", buf.toString()); | |
108 | + | |
109 | + return; | |
110 | + } | |
111 | + | |
112 | + @Test | |
113 | + public void testPutXsdFloat() throws IOException{ | |
114 | + System.out.println("putXsdFloat"); | |
115 | + | |
116 | + BasicXmlExporter instance; | |
117 | + StringBuffer buf; | |
118 | + | |
119 | + instance = new BasicXmlExporter(); | |
120 | + | |
121 | + buf = new StringBuffer(); | |
122 | + instance.setAppendable(buf); | |
123 | + instance.putXsdFloat(-1.0f).putCh(',') | |
124 | + .putXsdFloat(-0.0f).putCh(',') | |
125 | + .putXsdFloat(0.0f).putCh(',') | |
126 | + .putXsdFloat(1.0f); | |
127 | + assertEquals("-1.0,-0.0,0.0,1.0", buf.toString()); | |
128 | + | |
129 | + buf = new StringBuffer(); | |
130 | + instance.setAppendable(buf); | |
131 | + instance.putXsdFloat(Float.NEGATIVE_INFINITY).putCh(',') | |
132 | + .putXsdFloat(Float.POSITIVE_INFINITY).putCh(',') | |
133 | + .putXsdFloat(Float.NaN); | |
134 | + assertEquals("-INF,INF,NaN", buf.toString()); | |
135 | + | |
136 | + buf = new StringBuffer(); | |
137 | + instance.setAppendable(buf); | |
138 | + instance.putXsdFloat(Float.MIN_VALUE).putCh(',') | |
139 | + .putXsdFloat(Float.MIN_NORMAL).putCh(',') | |
140 | + .putXsdFloat(Float.MAX_VALUE); | |
141 | + assertEquals("1.4E-45,1.17549435E-38,3.4028235E38", buf.toString()); | |
142 | + | |
143 | + buf = new StringBuffer(); | |
144 | + instance.setAppendable(buf); | |
145 | + instance.putXsdFloat(0.001f); | |
146 | + assertEquals("0.001", buf.toString()); // fuzzy "0.0010" on JDK1.6 | |
147 | + | |
148 | + buf = new StringBuffer(); | |
149 | + instance.setAppendable(buf); | |
150 | + instance.putXsdFloat(StrictMath.nextDown(0.001f)); | |
151 | + assertEquals("9.999999E-4", buf.toString()); | |
152 | + | |
153 | + buf = new StringBuffer(); | |
154 | + instance.setAppendable(buf); | |
155 | + instance.putXsdFloat(10000000.0f); | |
156 | + assertEquals("1.0E7", buf.toString()); | |
157 | + | |
158 | + buf = new StringBuffer(); | |
159 | + instance.setAppendable(buf); | |
160 | + instance.putXsdFloat(StrictMath.nextDown(10000000.0f)); | |
161 | + assertEquals("9999999.0", buf.toString()); | |
162 | + | |
163 | + buf = new StringBuffer(); | |
164 | + instance.setAppendable(buf); | |
165 | + instance.putXsdFloat((float)StrictMath.E).putCh(',') | |
166 | + .putXsdFloat((float)StrictMath.PI); | |
167 | + assertEquals("2.7182817,3.1415927", buf.toString()); | |
168 | + | |
169 | + return; | |
170 | + } | |
171 | + | |
172 | +} |
@@ -0,0 +1,388 @@ | ||
1 | +/* | |
2 | + */ | |
3 | +package jp.sfjp.mikutoga.xml; | |
4 | + | |
5 | +import org.junit.After; | |
6 | +import org.junit.AfterClass; | |
7 | +import org.junit.Before; | |
8 | +import org.junit.BeforeClass; | |
9 | +import org.junit.Test; | |
10 | +import static org.junit.Assert.*; | |
11 | + | |
12 | +/** | |
13 | + * | |
14 | + */ | |
15 | +public class DatatypeIoTest { | |
16 | + | |
17 | + public DatatypeIoTest() { | |
18 | + } | |
19 | + | |
20 | + @BeforeClass | |
21 | + public static void setUpClass() { | |
22 | + } | |
23 | + | |
24 | + @AfterClass | |
25 | + public static void tearDownClass() { | |
26 | + } | |
27 | + | |
28 | + @Before | |
29 | + public void setUp() { | |
30 | + } | |
31 | + | |
32 | + @After | |
33 | + public void tearDown() { | |
34 | + } | |
35 | + | |
36 | + /** | |
37 | + * Test of printInt method, of class DatatypeIo. | |
38 | + */ | |
39 | + @Test | |
40 | + public void testPrintInt() { | |
41 | + System.out.println("printInt"); | |
42 | + | |
43 | + CharSequence result; | |
44 | + | |
45 | + result = DatatypeIo.printInt(0); | |
46 | + assertEquals("0", result.toString()); | |
47 | + | |
48 | + result = DatatypeIo.printInt(1); | |
49 | + assertEquals("1", result.toString()); | |
50 | + | |
51 | + result = DatatypeIo.printInt(-1); | |
52 | + assertEquals("-1", result.toString()); | |
53 | + | |
54 | + result = DatatypeIo.printInt(999); | |
55 | + assertEquals("999", result.toString()); | |
56 | + | |
57 | + result = DatatypeIo.printInt(-9999); | |
58 | + assertEquals("-9999", result.toString()); | |
59 | + | |
60 | + result = DatatypeIo.printInt(Integer.MIN_VALUE); | |
61 | + assertEquals("-2147483648", result.toString()); | |
62 | + | |
63 | + result = DatatypeIo.printInt(Integer.MAX_VALUE); | |
64 | + assertEquals("2147483647", result.toString()); | |
65 | + | |
66 | + return; | |
67 | + } | |
68 | + | |
69 | + /** | |
70 | + * Test of printFloat method, of class DatatypeIo. | |
71 | + */ | |
72 | + @Test | |
73 | + public void testPrintFloat() { | |
74 | + System.out.println("printFloat"); | |
75 | + | |
76 | + CharSequence result; | |
77 | + | |
78 | + result = DatatypeIo.printFloat(0.0f); | |
79 | + assertEquals("0.0", result.toString()); | |
80 | + | |
81 | + result = DatatypeIo.printFloat(-0.0f); | |
82 | + assertEquals("-0.0", result.toString()); | |
83 | + | |
84 | + result = DatatypeIo.printFloat(1.0f); | |
85 | + assertEquals("1.0", result.toString()); | |
86 | + | |
87 | + result = DatatypeIo.printFloat(-1.0f); | |
88 | + assertEquals("-1.0", result.toString()); | |
89 | + | |
90 | + result = DatatypeIo.printFloat((float)StrictMath.E); | |
91 | + assertEquals("2.7182817", result.toString()); | |
92 | + | |
93 | + result = DatatypeIo.printFloat((float)StrictMath.PI); | |
94 | + assertEquals("3.1415927", result.toString()); | |
95 | + | |
96 | + result = DatatypeIo.printFloat(0.001f); | |
97 | + assertEquals("0.001", result.toString()); | |
98 | + | |
99 | + result = DatatypeIo.printFloat(StrictMath.nextDown(0.001f)); | |
100 | + assertEquals("9.999999E-4", result.toString()); | |
101 | + | |
102 | + result = DatatypeIo.printFloat(10_000_000.0f); | |
103 | + assertEquals("1.0E7", result.toString()); | |
104 | + | |
105 | + result = DatatypeIo.printFloat(StrictMath.nextDown(10_000_000.0f)); | |
106 | + assertEquals("9999999.0", result.toString()); | |
107 | + | |
108 | + result = DatatypeIo.printFloat(Float.POSITIVE_INFINITY); | |
109 | + assertEquals("INF", result.toString()); | |
110 | + | |
111 | + result = DatatypeIo.printFloat(Float.NEGATIVE_INFINITY); | |
112 | + assertEquals("-INF", result.toString()); | |
113 | + | |
114 | + result = DatatypeIo.printFloat(Float.NaN); | |
115 | + assertEquals("NaN", result.toString()); | |
116 | + | |
117 | + result = DatatypeIo.printFloat(Float.MIN_VALUE); | |
118 | + assertEquals("1.4E-45", result.toString()); | |
119 | + | |
120 | + result = DatatypeIo.printFloat(Float.MIN_NORMAL); | |
121 | + assertEquals("1.17549435E-38", result.toString()); | |
122 | + | |
123 | + result = DatatypeIo.printFloat(Float.MAX_VALUE); | |
124 | + assertEquals("3.4028235E38", result.toString()); | |
125 | + | |
126 | + return; | |
127 | + } | |
128 | + | |
129 | + /** | |
130 | + * Test of parseBoolean method, of class DatatypeIo. | |
131 | + */ | |
132 | + @Test | |
133 | + public void testParseBoolean() { | |
134 | + System.out.println("parseBoolean"); | |
135 | + | |
136 | + assertFalse(DatatypeIo.parseBoolean("0")); | |
137 | + assertFalse(DatatypeIo.parseBoolean("false")); | |
138 | + assertTrue(DatatypeIo.parseBoolean("1")); | |
139 | + assertTrue(DatatypeIo.parseBoolean("true")); | |
140 | + | |
141 | + assertTrue(DatatypeIo.parseBoolean("\n\rtrue\u0020\t")); | |
142 | + | |
143 | + try{ | |
144 | + DatatypeIo.parseBoolean("yes"); | |
145 | + fail(); | |
146 | + }catch(IllegalArgumentException e){ | |
147 | + assert true; | |
148 | + } | |
149 | + | |
150 | + try{ | |
151 | + DatatypeIo.parseBoolean(""); | |
152 | + fail(); | |
153 | + }catch(IllegalArgumentException e){ | |
154 | + assert true; | |
155 | + } | |
156 | + | |
157 | + return; | |
158 | + } | |
159 | + | |
160 | + /** | |
161 | + * Test of parseInt method, of class DatatypeIo. | |
162 | + */ | |
163 | + @Test | |
164 | + public void testParseInt() { | |
165 | + System.out.println("parseInt"); | |
166 | + | |
167 | + int result; | |
168 | + | |
169 | + result = DatatypeIo.parseInt("0"); | |
170 | + assertEquals(0, result); | |
171 | + | |
172 | + result = DatatypeIo.parseInt("+0"); | |
173 | + assertEquals(0, result); | |
174 | + | |
175 | + result = DatatypeIo.parseInt("-0"); | |
176 | + assertEquals(0, result); | |
177 | + | |
178 | + result = DatatypeIo.parseInt("1"); | |
179 | + assertEquals(1, result); | |
180 | + | |
181 | + result = DatatypeIo.parseInt("+1"); | |
182 | + assertEquals(1, result); | |
183 | + | |
184 | + result = DatatypeIo.parseInt("-1"); | |
185 | + assertEquals(-1, result); | |
186 | + | |
187 | + result = DatatypeIo.parseInt("999"); | |
188 | + assertEquals(999, result); | |
189 | + | |
190 | + result = DatatypeIo.parseInt("-9999"); | |
191 | + assertEquals(-9999, result); | |
192 | + | |
193 | + result = DatatypeIo.parseInt("-2147483648"); | |
194 | + assertEquals(Integer.MIN_VALUE, result); | |
195 | + | |
196 | + result = DatatypeIo.parseInt("2147483647"); | |
197 | + assertEquals(Integer.MAX_VALUE, result); | |
198 | + | |
199 | + result = DatatypeIo.parseInt("\n\r999\u0020\t"); | |
200 | + assertEquals(999, result); | |
201 | + | |
202 | + try{ | |
203 | + DatatypeIo.parseInt("?"); | |
204 | + fail(); | |
205 | + }catch(NumberFormatException e){ | |
206 | + assert true; | |
207 | + } | |
208 | + | |
209 | + try{ | |
210 | + DatatypeIo.parseInt("-2147483649"); | |
211 | + fail(); | |
212 | + }catch(NumberFormatException e){ | |
213 | + assert true; | |
214 | + } | |
215 | + | |
216 | + try{ | |
217 | + DatatypeIo.parseInt("2147483648"); | |
218 | + fail(); | |
219 | + }catch(NumberFormatException e){ | |
220 | + assert true; | |
221 | + } | |
222 | + | |
223 | + try{ | |
224 | + DatatypeIo.parseInt("3.14"); | |
225 | + fail(); | |
226 | + }catch(NumberFormatException e){ | |
227 | + assert true; | |
228 | + } | |
229 | + | |
230 | + return; | |
231 | + } | |
232 | + | |
233 | + /** | |
234 | + * Test of parseFloat method, of class DatatypeIo. | |
235 | + */ | |
236 | + @Test | |
237 | + public void testParseFloat() { | |
238 | + System.out.println("parseFloat"); | |
239 | + | |
240 | + float result; | |
241 | + | |
242 | + result = DatatypeIo.parseFloat("0.0"); | |
243 | + assertEquals(0.0f, result, 0.0f); | |
244 | + | |
245 | + result = DatatypeIo.parseFloat("+0.0"); | |
246 | + assertEquals(0.0f, result, 0.0f); | |
247 | + | |
248 | + result = DatatypeIo.parseFloat("-0.0"); | |
249 | + assertEquals(-0.0f, result, 0.0f); | |
250 | + | |
251 | + result = DatatypeIo.parseFloat("-123.45"); | |
252 | + assertEquals(-123.45f, result, 0.0f); | |
253 | + | |
254 | + result = DatatypeIo.parseFloat("654.32"); | |
255 | + assertEquals(654.32f, result, 0.0f); | |
256 | + | |
257 | + result = DatatypeIo.parseFloat("2.718281828459045"); | |
258 | + assertEquals((float)StrictMath.E, result, 0.0f); | |
259 | + | |
260 | + result = DatatypeIo.parseFloat("3.141592653589793"); | |
261 | + assertEquals((float)StrictMath.PI, result, 0.0f); | |
262 | + | |
263 | + result = DatatypeIo.parseFloat("1.401298464324817E-45"); | |
264 | + assertEquals(Float.MIN_VALUE, result, 0.0f); | |
265 | + | |
266 | + result = DatatypeIo.parseFloat("1.1754943508222875E-38"); | |
267 | + assertEquals(Float.MIN_NORMAL, result, 0.0f); | |
268 | + | |
269 | + result = DatatypeIo.parseFloat("3.4028234663852886E38"); | |
270 | + assertEquals(Float.MAX_VALUE, result, 0.0f); | |
271 | + | |
272 | + result = DatatypeIo.parseFloat("2E3"); | |
273 | + assertEquals(2000.0f, result, 0.0f); | |
274 | + | |
275 | + result = DatatypeIo.parseFloat("2.3E4"); | |
276 | + assertEquals(23000.0f, result, 0.0f); | |
277 | + | |
278 | + result = DatatypeIo.parseFloat("2.3e4"); | |
279 | + assertEquals(23000.0f, result, 0.0f); | |
280 | + | |
281 | + result = DatatypeIo.parseFloat("2.3E+4"); | |
282 | + assertEquals(23000.0f, result, 0.0f); | |
283 | + | |
284 | + result = DatatypeIo.parseFloat("2.3E-4"); | |
285 | + assertEquals(0.00023f, result, 0.0f); | |
286 | + | |
287 | + result = DatatypeIo.parseFloat("INF"); | |
288 | + assertEquals(Float.POSITIVE_INFINITY, result, 0.0f); | |
289 | + | |
290 | + result = DatatypeIo.parseFloat("-INF"); | |
291 | + assertEquals(Float.NEGATIVE_INFINITY, result, 0.0f); | |
292 | + | |
293 | + try{ | |
294 | + DatatypeIo.parseFloat("+INF"); | |
295 | + fail(); | |
296 | + }catch(NumberFormatException e){ | |
297 | + assert true; | |
298 | + } | |
299 | + | |
300 | + try{ | |
301 | + DatatypeIo.parseFloat("Infinity"); | |
302 | + fail(); | |
303 | + }catch(NumberFormatException e){ | |
304 | + assert true; | |
305 | + } | |
306 | + | |
307 | + result = DatatypeIo.parseFloat("NaN"); | |
308 | + assertTrue(Float.isNaN(result)); | |
309 | + | |
310 | + result = DatatypeIo.parseFloat("\n\r1.2\u0020\t"); | |
311 | + assertEquals(1.2f, result, 0.0f); | |
312 | + | |
313 | + try{ | |
314 | + DatatypeIo.parseFloat("?"); | |
315 | + fail(); | |
316 | + }catch(NumberFormatException e){ | |
317 | + assert true; | |
318 | + } | |
319 | + | |
320 | + try{ | |
321 | + DatatypeIo.parseFloat("0x1.0p0"); | |
322 | + fail(); | |
323 | + }catch(NumberFormatException e){ | |
324 | + assert true; | |
325 | + } | |
326 | + | |
327 | + return; | |
328 | + } | |
329 | + | |
330 | + /** | |
331 | + * Test of trim method, of class DatatypeIo. | |
332 | + */ | |
333 | + @Test | |
334 | + public void testTrim() { | |
335 | + System.out.println("trim"); | |
336 | + | |
337 | + CharSequence txt; | |
338 | + CharSequence result; | |
339 | + | |
340 | + txt = "abc"; | |
341 | + result = DatatypeIo.xsdTrim(txt); | |
342 | + assertEquals("abc", result.toString()); | |
343 | + | |
344 | + txt = ""; | |
345 | + result = DatatypeIo.xsdTrim(txt); | |
346 | + assertEquals("", result.toString()); | |
347 | + | |
348 | + txt = " abc "; | |
349 | + result = DatatypeIo.xsdTrim(txt); | |
350 | + assertEquals("abc", result.toString()); | |
351 | + | |
352 | + txt = " abc"; | |
353 | + result = DatatypeIo.xsdTrim(txt); | |
354 | + assertEquals("abc", result.toString()); | |
355 | + | |
356 | + txt = "abc "; | |
357 | + result = DatatypeIo.xsdTrim(txt); | |
358 | + assertEquals("abc", result.toString()); | |
359 | + | |
360 | + txt = " a b c "; | |
361 | + result = DatatypeIo.xsdTrim(txt); | |
362 | + assertEquals("a b c", result.toString()); | |
363 | + | |
364 | + txt = "\n\rabc\u0020\t"; | |
365 | + result = DatatypeIo.xsdTrim(txt); | |
366 | + assertEquals("abc", result.toString()); | |
367 | + | |
368 | + return; | |
369 | + } | |
370 | + | |
371 | + /** | |
372 | + * Test of isWhitespace method, of class DatatypeIo. | |
373 | + */ | |
374 | + @Test | |
375 | + public void testIsWhitespace() { | |
376 | + System.out.println("isWhitespace"); | |
377 | + | |
378 | + assertTrue(DatatypeIo.isXsdWhitespace('\u0020')); | |
379 | + assertTrue(DatatypeIo.isXsdWhitespace('\n')); | |
380 | + assertTrue(DatatypeIo.isXsdWhitespace('\r')); | |
381 | + assertTrue(DatatypeIo.isXsdWhitespace('\t')); | |
382 | + assertFalse(DatatypeIo.isXsdWhitespace('X')); | |
383 | + assertFalse(DatatypeIo.isXsdWhitespace('\u0001')); | |
384 | + | |
385 | + return; | |
386 | + } | |
387 | + | |
388 | +} |
@@ -0,0 +1,213 @@ | ||
1 | +/* | |
2 | +@see https://www.w3.org/TR/xmlschema-2/ | |
3 | + */ | |
4 | + | |
5 | +package jp.sfjp.mikutoga.xml; | |
6 | + | |
7 | +import javax.xml.parsers.DocumentBuilder; | |
8 | +import javax.xml.parsers.DocumentBuilderFactory; | |
9 | +import javax.xml.parsers.ParserConfigurationException; | |
10 | +import org.junit.After; | |
11 | +import org.junit.AfterClass; | |
12 | +import org.junit.Before; | |
13 | +import org.junit.BeforeClass; | |
14 | +import org.junit.Test; | |
15 | +import static org.junit.Assert.*; | |
16 | +import org.w3c.dom.Document; | |
17 | +import org.w3c.dom.Element; | |
18 | + | |
19 | +/** | |
20 | + * | |
21 | + */ | |
22 | +public class DomUtilsTest { | |
23 | + | |
24 | + private static final DocumentBuilderFactory FACTORY = | |
25 | + DocumentBuilderFactory.newInstance(); | |
26 | + private static final DocumentBuilder BUILDER; | |
27 | + | |
28 | + private static final String TESTELEM = "testelem"; | |
29 | + private static final String TESTATTR = "testattr"; | |
30 | + | |
31 | + private static Element getTestAttredElem(String attrVal){ | |
32 | + Document doc = BUILDER.newDocument(); | |
33 | + Element elem = doc.createElement(TESTELEM); | |
34 | + elem.setAttribute(TESTATTR, attrVal); | |
35 | + return elem; | |
36 | + } | |
37 | + | |
38 | + static{ | |
39 | + try{ | |
40 | + BUILDER = FACTORY.newDocumentBuilder(); | |
41 | + }catch(ParserConfigurationException e){ | |
42 | + throw new ExceptionInInitializerError(e); | |
43 | + } | |
44 | + } | |
45 | + | |
46 | + public DomUtilsTest() { | |
47 | + } | |
48 | + | |
49 | + @BeforeClass | |
50 | + public static void setUpClass() throws ParserConfigurationException{ | |
51 | + } | |
52 | + | |
53 | + @AfterClass | |
54 | + public static void tearDownClass() { | |
55 | + } | |
56 | + | |
57 | + @Before | |
58 | + public void setUp() { | |
59 | + } | |
60 | + | |
61 | + @After | |
62 | + public void tearDown() { | |
63 | + } | |
64 | + | |
65 | + /** | |
66 | + * Test of getBooleanAttr method, of class DomUtils. | |
67 | + */ | |
68 | + @Test | |
69 | + public void testGetBooleanAttr() throws Exception { | |
70 | + System.out.println("getBooleanAttr"); | |
71 | + | |
72 | + boolean result; | |
73 | + Element elem; | |
74 | + | |
75 | + elem = getTestAttredElem("true"); | |
76 | + result = DomUtils.getBooleanAttr(elem, TESTATTR); | |
77 | + assertTrue(result); | |
78 | + | |
79 | + elem = getTestAttredElem("false"); | |
80 | + result = DomUtils.getBooleanAttr(elem, TESTATTR); | |
81 | + assertFalse(result); | |
82 | + | |
83 | + elem = getTestAttredElem("0"); | |
84 | + result = DomUtils.getBooleanAttr(elem, TESTATTR); | |
85 | + assertFalse(result); | |
86 | + | |
87 | + elem = getTestAttredElem("1"); | |
88 | + result = DomUtils.getBooleanAttr(elem, TESTATTR); | |
89 | + assertTrue(result); | |
90 | + | |
91 | + elem = getTestAttredElem("\n\rtrue\u0020\t"); | |
92 | + result = DomUtils.getBooleanAttr(elem, TESTATTR); | |
93 | + assertTrue(result); | |
94 | + | |
95 | + elem = getTestAttredElem("?"); | |
96 | + try{ | |
97 | + DomUtils.getBooleanAttr(elem, TESTATTR); | |
98 | + fail(); | |
99 | + }catch(TogaXmlException e){ | |
100 | + assert true; | |
101 | + } | |
102 | + | |
103 | + return; | |
104 | + } | |
105 | + | |
106 | + /** | |
107 | + * Test of getIntegerAttr method, of class DomUtils. | |
108 | + */ | |
109 | + @Test | |
110 | + public void testGetIntegerAttr() throws TogaXmlException { | |
111 | + System.out.println("getIntegerAttr"); | |
112 | + | |
113 | + int result; | |
114 | + Element elem; | |
115 | + | |
116 | + elem = getTestAttredElem("0"); | |
117 | + result = DomUtils.getIntegerAttr(elem, TESTATTR); | |
118 | + assertEquals(0, result); | |
119 | + | |
120 | + elem = getTestAttredElem("1"); | |
121 | + result = DomUtils.getIntegerAttr(elem, TESTATTR); | |
122 | + assertEquals(1, result); | |
123 | + | |
124 | + elem = getTestAttredElem("-1"); | |
125 | + result = DomUtils.getIntegerAttr(elem, TESTATTR); | |
126 | + assertEquals(-1, result); | |
127 | + | |
128 | + elem = getTestAttredElem("999"); | |
129 | + result = DomUtils.getIntegerAttr(elem, TESTATTR); | |
130 | + assertEquals(999, result); | |
131 | + | |
132 | + elem = getTestAttredElem("-9999"); | |
133 | + result = DomUtils.getIntegerAttr(elem, TESTATTR); | |
134 | + assertEquals(-9999, result); | |
135 | + | |
136 | + elem = getTestAttredElem("\n\r999\u0020\t"); | |
137 | + result = DomUtils.getIntegerAttr(elem, TESTATTR); | |
138 | + assertEquals(999, result); | |
139 | + | |
140 | + elem = getTestAttredElem("?"); | |
141 | + try{ | |
142 | + result = DomUtils.getIntegerAttr(elem, TESTATTR); | |
143 | + fail(); | |
144 | + }catch(TogaXmlException e){ | |
145 | + assert true; | |
146 | + } | |
147 | + | |
148 | + return; | |
149 | + } | |
150 | + | |
151 | + /** | |
152 | + * Test of getFloatAttr method, of class DomUtils. | |
153 | + */ | |
154 | + @Test | |
155 | + public void testGetFloatAttr() throws TogaXmlException { | |
156 | + System.out.println("getFloatAttr"); | |
157 | + | |
158 | + float result; | |
159 | + Element elem; | |
160 | + | |
161 | + elem = getTestAttredElem("0.0"); | |
162 | + result = DomUtils.getFloatAttr(elem, TESTATTR); | |
163 | + assertEquals(0.0f, result, 0.0f); | |
164 | + | |
165 | + elem = getTestAttredElem("-0.0"); | |
166 | + result = DomUtils.getFloatAttr(elem, TESTATTR); | |
167 | + assertEquals(0.0f, result, 0.0f); | |
168 | + assertEquals("-0.0", Float.toString(result)); | |
169 | + | |
170 | + elem = getTestAttredElem("-123.456"); | |
171 | + result = DomUtils.getFloatAttr(elem, TESTATTR); | |
172 | + assertEquals(-123.456f, result, 0.0f); | |
173 | + | |
174 | + elem = getTestAttredElem("654.321"); | |
175 | + result = DomUtils.getFloatAttr(elem, TESTATTR); | |
176 | + assertEquals(654.321f, result, 0.0f); | |
177 | + | |
178 | + elem = getTestAttredElem("2.3E4"); | |
179 | + result = DomUtils.getFloatAttr(elem, TESTATTR); | |
180 | + assertEquals(23000.0f, result, 0.0f); | |
181 | + | |
182 | + elem = getTestAttredElem("INF"); | |
183 | + result = DomUtils.getFloatAttr(elem, TESTATTR); | |
184 | + assertEquals(Float.POSITIVE_INFINITY, result, 0.0f); | |
185 | + | |
186 | + elem = getTestAttredElem("+INF"); | |
187 | + try{ | |
188 | + DomUtils.getFloatAttr(elem, TESTATTR); | |
189 | + fail(); | |
190 | + }catch(TogaXmlException e){ | |
191 | + assert true; | |
192 | + } | |
193 | + | |
194 | + elem = getTestAttredElem("NaN"); | |
195 | + result = DomUtils.getFloatAttr(elem, TESTATTR); | |
196 | + assertTrue(Float.isNaN(result)); | |
197 | + | |
198 | + elem = getTestAttredElem("\n\r123.456\u0020\t"); | |
199 | + result = DomUtils.getFloatAttr(elem, TESTATTR); | |
200 | + assertEquals(123.456f, result, 0.0f); | |
201 | + | |
202 | + elem = getTestAttredElem("?"); | |
203 | + try{ | |
204 | + DomUtils.getFloatAttr(elem, TESTATTR); | |
205 | + fail(); | |
206 | + }catch(TogaXmlException e){ | |
207 | + assert true; | |
208 | + } | |
209 | + | |
210 | + return; | |
211 | + } | |
212 | + | |
213 | +} |