001package Torello.Java.JSON; 002 003import javax.json.*; 004import java.lang.reflect.*; 005import java.math.*; 006 007import java.util.function.Function; 008 009import static javax.json.JsonValue.ValueType.*; 010import static Torello.Java.JSON.JFlag.*; 011import static Torello.Java.JSON.RJInternal.*; 012 013/** 014 * Builds on the J2EE Standard Release JSON Parsing Tools by providing additional 015 * help with converting JSON Data into <B STYLE='color: red'>Java Boxed-Primitive Types</B> 016 * 017 * <EMBED CLASS='external-html' DATA-FILE-ID=GLASS_FISH_NOTE> 018 * <EMBED CLASS='external-html' DATA-CH='java.lang.Character' DATA-FILE-ID=JAVA_LANG_CHAR> 019 * 020 * @see Json 021 * @see JsonObject 022 * @see JsonArray 023 */ 024@Torello.JavaDoc.StaticFunctional 025@Torello.JavaDoc.JDHeaderBackgroundImg(EmbedTagFileID="JSON_JDHBI") 026public class ReadBoxedJSON 027{ 028 // This is a static class. Has no program state. 029 private ReadBoxedJSON() { } 030 031 032 // ******************************************************************************************** 033 // ******************************************************************************************** 034 // Integer from JsonArray 035 // ******************************************************************************************** 036 // ******************************************************************************************** 037 038 039 /** 040 * Retrieve a {@link JsonArray} element, and transform it to a {@code java.lang.Integer}. 041 * 042 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_NULLNOTE> 043 * <EMBED CLASS=defs DATA-JTYPE=JsonNumber DATA-TYPE='java.lang.Integer' DATA-M=intValueExact> 044 * 045 * @param ja Any instance of {@link JsonArray} 046 * @param index <EMBED CLASS='external-html' DATA-FILE-ID=JR_INDEX_JA> 047 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JR_RET_JA> 048 * 049 * @throws IndexOutOfBoundsException If {@code 'index'} is out of the bounds of {@code 'ja'} 050 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JTAEX> 051 * @throws JsonArithmeticArrException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JAEX> 052 * 053 * @see RJInternal#GET(JsonArray, int, Function, Class) 054 * @see JsonNumber#intValueExact() 055 */ 056 public static Integer getInteger(JsonArray ja, int index) 057 { return GET(ja, index, JsonNumber::intValueExact, Integer.class); } 058 059 /** 060 * Retrieve a {@link JsonArray} element, and transform it to a {@code java.lang.Integer}. 061 * 062 * <EMBED CLASS=defs DATA-TYPE='java.lang.Integer' DATA-PTYPE=int DATA-THIS=getInteger 063 * DATA-JTYPE=JsonNumber> 064 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC> 065 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_JA> 066 * 067 * @param ja Any instance of {@link JsonArray} 068 * @param index The array index containing the element to retrieve. 069 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 070 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 071 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_RET_JA> 072 * 073 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 074 * @throws JsonArithmeticArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 075 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNAEX> 076 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTAEX> 077 * 078 * @see RJInternal#GET(JsonArray, int, int, Number, Class, Function, Function) 079 * @see JsonNumber#intValueExact() 080 * @see JsonNumber#intValue() 081 */ 082 public static Integer getInteger(JsonArray ja, int index, int FLAGS, int defaultValue) 083 { 084 return GET( 085 ja, index, FLAGS, defaultValue, 086 Integer.class, JsonNumber::intValueExact, JsonNumber::intValue 087 ); 088 } 089 090 /** 091 * Retrieve a {@link JsonArray} element containing a {@link JsonString}, and transform it to a 092 * {@code java.lang.Integer}, with either a user-provided parser, or the standard java integer 093 * parser 094 * 095 * <EMBED CLASS=defs DATA-TYPE='java.lang.Integer' DATA-PTYPE=int DATA-THIS=parseInteger 096 * DATA-JTYPE=JsonString DATA-PARSER='Integer.parseInt'> 097 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC_STR> 098 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_STR_JA> 099 * 100 * @param ja Any instance of {@link JsonArray} 101 * @param index The array index containing the {@link JsonString} element to retrieve. 102 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 103 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 104 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSER> 105 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSERET_JA> 106 * 107 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 108 * @throws JsonArithmeticArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 109 * @throws JsonStrParseArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JSPAEX> 110 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNAEX> 111 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTAEX> 112 * 113 * @see RJInternal#PARSE(JsonObject, String, int, Number, Class, Function, Function, Function) 114 */ 115 public static Integer parseInteger( 116 JsonArray ja, int index, int FLAGS, int defaultValue, 117 Function<String, Integer> optionalParser 118 ) 119 { 120 return PARSE( 121 ja, index, FLAGS, defaultValue, Integer.class, optionalParser, 122 BigDecimal::intValueExact, BigDecimal::intValue 123 ); 124 } 125 126 127 // ******************************************************************************************** 128 // ******************************************************************************************** 129 // Integer from JsonObject 130 // ******************************************************************************************** 131 // ******************************************************************************************** 132 133 134 /** 135 * Extract a {@link JsonObject} property, and transform it to a {@code java.lang.Integer}. 136 * 137 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_NULLNOTE> 138 * <EMBED CLASS=defs DATA-TYPE='java.lang.Integer' DATA-JTYPE=JsonNumber DATA-M=intValueExact> 139 * 140 * @param jo Any instance of {@link JsonObject}. 141 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 142 * @param isOptional <EMBED CLASS='external-html' DATA-FILE-ID=JR_ISOPT_JO> 143 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JR_RET_JO> 144 * 145 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JPMEX> 146 * @throws JsonArithmeticObjException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JAEX> 147 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JTOEX> 148 * 149 * @see RJInternal#GET(JsonObject, String, boolean, Function, Class) 150 * @see JsonNumber#intValueExact() 151 */ 152 public static Integer getInteger(JsonObject jo, String propertyName, boolean isOptional) 153 { return GET(jo, propertyName, isOptional, JsonNumber::intValueExact, Integer.class); } 154 155 /** 156 * Retrieve a {@link JsonObject} property, and transform it to a {@code java.lang.Integer}. 157 * 158 * <EMBED CLASS=defs DATA-TYPE='java.lang.Integer' DATA-PTYPE=int DATA-THIS=getInteger 159 * DATA-JTYPE=JsonNumber> 160 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC> 161 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_JO> 162 * 163 * @param jo Any instance of {@link JsonObject} 164 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 165 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 166 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 167 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_RET_JO> 168 * 169 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 170 * @throws JsonArithmeticObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 171 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNOEX> 172 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTOEX> 173 * 174 * @see RJInternal#GET(JsonObject, String, int, Number, Class, Function, Function) 175 * @see JsonNumber#intValueExact() 176 * @see JsonNumber#intValue() 177 */ 178 public static Integer getInteger 179 (JsonObject jo, String propertyName, int FLAGS, int defaultValue) 180 { 181 return GET( 182 jo, propertyName, FLAGS, defaultValue, 183 Integer.class, JsonNumber::intValueExact, JsonNumber::intValue 184 ); 185 } 186 187 /** 188 * Retrieve a {@link JsonObject} property containing a {@link JsonString}, and transform it to 189 * a {@code java.lang.Integer}, with either a user-provided parser, or the standard java 190 * integer parser 191 * 192 * <EMBED CLASS=defs DATA-TYPE='java.lang.Integer' DATA-PTYPE=int DATA-THIS=parseInteger 193 * DATA-JTYPE=JsonString DATA-PARSER='Integer.parseInt'> 194 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC_STR> 195 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_STR_JO> 196 * 197 * @param jo Any instance of {@link JsonObject} 198 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 199 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 200 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 201 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSER> 202 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSERET_JO> 203 * 204 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 205 * @throws JsonArithmeticObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 206 * @throws JsonStrParseObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JSPOEX> 207 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNOEX> 208 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTOEX> 209 * 210 * @see RJInternal#PARSE(JsonObject, String, int, Number, Class, Function, Function, Function) 211 */ 212 public static Integer parseInteger( 213 JsonObject jo, String propertyName, int FLAGS, int defaultValue, 214 Function<String, Integer> optionalParser 215 ) 216 { 217 return PARSE( 218 jo, propertyName, FLAGS, defaultValue, Integer.class, optionalParser, 219 BigDecimal::intValueExact, BigDecimal::intValue 220 ); 221 } 222 223 224 // ******************************************************************************************** 225 // ******************************************************************************************** 226 // Long from JsonArray 227 // ******************************************************************************************** 228 // ******************************************************************************************** 229 230 231 /** 232 * Retrieve a {@link JsonArray} element, and transform it to a {@code java.lang.Long}. 233 * 234 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_NULLNOTE> 235 * <EMBED CLASS=defs DATA-JTYPE=JsonNumber DATA-TYPE='java.lang.Long' DATA-M=longValueExact> 236 * 237 * @param ja Any instance of {@link JsonArray} 238 * @param index <EMBED CLASS='external-html' DATA-FILE-ID=JR_INDEX_JA> 239 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JR_RET_JA> 240 * 241 * @throws IndexOutOfBoundsException If {@code 'index'} is out of the bounds of {@code 'ja'} 242 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JTAEX> 243 * @throws JsonArithmeticArrException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JAEX> 244 * 245 * @see RJInternal#GET(JsonArray, int, Function, Class) 246 * @see JsonNumber#longValueExact() 247 */ 248 public static Long getLong(JsonArray ja, int index) 249 { return GET(ja, index, JsonNumber::longValueExact, Long.class); } 250 251 /** 252 * Retrieve a {@link JsonArray} element, and transform it to a {@code java.lang.Long}. 253 * 254 * <EMBED CLASS=defs DATA-TYPE='java.lang.Long' DATA-PTYPE=long DATA-THIS=getLong 255 * DATA-JTYPE=JsonNumber> 256 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC> 257 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_JA> 258 * 259 * @param ja Any instance of {@link JsonArray} 260 * @param index The array index containing the element to retrieve. 261 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 262 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 263 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_RET_JA> 264 * 265 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 266 * @throws JsonArithmeticArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 267 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNAEX> 268 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTAEX> 269 * 270 * @see RJInternal#GET(JsonArray, int, int, Number, Class, Function, Function) 271 * @see JsonNumber#longValueExact() 272 * @see JsonNumber#longValue() 273 */ 274 public static Long getLong(JsonArray ja, int index, int FLAGS, long defaultValue) 275 { 276 return GET( 277 ja, index, FLAGS, defaultValue, 278 Long.class, JsonNumber::longValueExact, JsonNumber::longValue 279 ); 280 } 281 282 /** 283 * Retrieve a {@link JsonArray} element containing a {@link JsonString}, and transform it to a 284 * {@code java.lang.Long}, with either a user-provided parser, or the standard java 285 * long-integer parser 286 * 287 * <EMBED CLASS=defs DATA-TYPE='java.lang.Long' DATA-PTYPE=long DATA-THIS=parseLong 288 * DATA-JTYPE=JsonString DATA-PARSER='Long.parseLong'> 289 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC_STR> 290 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_STR_JA> 291 * 292 * @param ja Any instance of {@link JsonArray} 293 * @param index The array index containing the {@link JsonString} element to retrieve. 294 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 295 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 296 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSER> 297 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSERET_JA> 298 * 299 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 300 * @throws JsonArithmeticArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 301 * @throws JsonStrParseArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JSPAEX> 302 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNAEX> 303 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTAEX> 304 * 305 * @see RJInternal#PARSE(JsonObject, String, int, Number, Class, Function, Function, Function) 306 */ 307 public static Long parseLong( 308 JsonArray ja, int index, int FLAGS, long defaultValue, 309 Function<String, Long> optionalParser 310 ) 311 { 312 return PARSE( 313 ja, index, FLAGS, defaultValue, Long.class, optionalParser, 314 BigDecimal::longValueExact, BigDecimal::longValue 315 ); 316 } 317 318 319 // ******************************************************************************************** 320 // ******************************************************************************************** 321 // Long from JsonObject 322 // ******************************************************************************************** 323 // ******************************************************************************************** 324 325 326 /** 327 * Extract a {@link JsonObject} property, and transform it to a {@code java.lang.Long}. 328 * 329 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_NULLNOTE> 330 * <EMBED CLASS=defs DATA-TYPE='java.lang.Long' DATA-JTYPE=JsonNumber DATA-M=longValueExact> 331 * 332 * @param jo Any instance of {@link JsonObject}. 333 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 334 * @param isOptional <EMBED CLASS='external-html' DATA-FILE-ID=JR_ISOPT_JO> 335 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JR_RET_JO> 336 * 337 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JPMEX> 338 * @throws JsonArithmeticObjException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JAEX> 339 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JTOEX> 340 * 341 * @see RJInternal#GET(JsonObject, String, boolean, Function, Class) 342 * @see JsonNumber#longValueExact() 343 */ 344 public static Long getLong(JsonObject jo, String propertyName, boolean isOptional) 345 { return GET(jo, propertyName, isOptional, JsonNumber::longValueExact, Long.class); } 346 347 /** 348 * Retrieve a {@link JsonObject} property, and transform it to a {@code java.lang.Long}. 349 * 350 * <EMBED CLASS=defs DATA-TYPE='java.lang.Long' DATA-PTYPE=int DATA-THIS=getLong 351 * DATA-JTYPE=JsonNumber> 352 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC> 353 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_JO> 354 * 355 * @param jo Any instance of {@link JsonObject} 356 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 357 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 358 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 359 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_RET_JO> 360 * 361 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 362 * @throws JsonArithmeticObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 363 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNOEX> 364 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTOEX> 365 * 366 * @see RJInternal#GET(JsonObject, String, int, Number, Class, Function, Function) 367 * @see JsonNumber#longValueExact() 368 * @see JsonNumber#longValue() 369 */ 370 public static Long getLong 371 (JsonObject jo, String propertyName, int FLAGS, long defaultValue) 372 { 373 return GET( 374 jo, propertyName, FLAGS, defaultValue, 375 Long.class, JsonNumber::longValueExact, JsonNumber::longValue 376 ); 377 } 378 379 /** 380 * Retrieve a {@link JsonObject} property containing a {@link JsonString}, and transform it to 381 * a {@code java.lang.Long}, with either a user-provided parser, or the standard java 382 * long-integer parser 383 * 384 * <EMBED CLASS=defs DATA-TYPE='java.lang.Long' DATA-PTYPE=long DATA-THIS=parseLong 385 * DATA-JTYPE=JsonString DATA-PARSER='Long.parseLong'> 386 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC_STR> 387 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_STR_JO> 388 * 389 * @param jo Any instance of {@link JsonObject} 390 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 391 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 392 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 393 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSER> 394 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSERET_JO> 395 * 396 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 397 * @throws JsonArithmeticObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 398 * @throws JsonStrParseObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JSPOEX> 399 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNOEX> 400 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTOEX> 401 * 402 * @see RJInternal#PARSE(JsonObject, String, int, Number, Class, Function, Function, Function) 403 */ 404 public static Long parseLong( 405 JsonObject jo, String propertyName, int FLAGS, long defaultValue, 406 Function<String, Long> optionalParser 407 ) 408 { 409 return PARSE( 410 jo, propertyName, FLAGS, defaultValue, Long.class, optionalParser, 411 BigDecimal::longValueExact, BigDecimal::longValue 412 ); 413 } 414 415 416 // ******************************************************************************************** 417 // ******************************************************************************************** 418 // Short from JsonArray 419 // ******************************************************************************************** 420 // ******************************************************************************************** 421 422 423 /** 424 * Retrieve a {@link JsonArray} element, and transform it to a {@code java.lang.Short}. 425 * 426 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_NULLNOTE> 427 * <EMBED CLASS=defs DATA-JTYPE=JsonNumber DATA-TYPE='java.lang.Short' DATA-M=shortValueExact> 428 * 429 * @param ja Any instance of {@link JsonArray} 430 * @param index <EMBED CLASS='external-html' DATA-FILE-ID=JR_INDEX_JA> 431 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JR_RET_JA> 432 * 433 * @throws IndexOutOfBoundsException If {@code 'index'} is out of the bounds of {@code 'ja'} 434 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JTAEX> 435 * @throws JsonArithmeticArrException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JAEX> 436 * 437 * @see RJInternal#GET(JsonArray, int, Function, Class) 438 * @see JsonNumber#bigDecimalValue() 439 */ 440 public static Short getShort(JsonArray ja, int index) 441 { return GET(ja, index, jn -> jn.bigDecimalValue().shortValueExact(), Short.class); } 442 443 /** 444 * Retrieve a {@link JsonArray} element, and transform it to a {@code java.lang.Short}. 445 * 446 * <EMBED CLASS=defs DATA-TYPE='java.lang.Short' DATA-PTYPE=short DATA-THIS=getShort 447 * DATA-JTYPE=JsonNumber> 448 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC> 449 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_JA> 450 * 451 * @param ja Any instance of {@link JsonArray} 452 * @param index The array index containing the element to retrieve. 453 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 454 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 455 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_RET_JA> 456 * 457 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 458 * @throws JsonArithmeticArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 459 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNAEX> 460 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTAEX> 461 * 462 * @see RJInternal#GET(JsonArray, int, int, Number, Class, Function, Function) 463 * @see JsonNumber#bigDecimalValue() 464 */ 465 public static Short getShort(JsonArray ja, int index, int FLAGS, short defaultValue) 466 { 467 return GET( 468 ja, index, FLAGS, defaultValue, Short.class, 469 jn -> jn.bigDecimalValue().shortValueExact(), 470 jn -> jn.bigDecimalValue().shortValue() 471 ); 472 } 473 474 /** 475 * Retrieve a {@link JsonArray} element containing a {@link JsonString}, and transform it to a 476 * {@code java.lang.Short}, with either a user-provided parser, or the standard java 477 * short-integer parser 478 * 479 * <EMBED CLASS=defs DATA-TYPE='java.lang.Short' DATA-PTYPE=short DATA-THIS=parseShort 480 * DATA-JTYPE=JsonString DATA-PARSER='Short.parseShort'> 481 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC_STR> 482 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_STR_JA> 483 * 484 * @param ja Any instance of {@link JsonArray} 485 * @param index The array index containing the {@link JsonString} element to retrieve. 486 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 487 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 488 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSER> 489 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSERET_JA> 490 * 491 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 492 * @throws JsonArithmeticArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 493 * @throws JsonStrParseArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JSPAEX> 494 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNAEX> 495 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTAEX> 496 * 497 * @see RJInternal#PARSE(JsonObject, String, int, Number, Class, Function, Function, Function) 498 */ 499 public static Short parseShort( 500 JsonArray ja, int index, int FLAGS, short defaultValue, 501 Function<String, Short> optionalParser 502 ) 503 { 504 return PARSE( 505 ja, index, FLAGS, defaultValue, Short.class, optionalParser, 506 BigDecimal::shortValueExact, BigDecimal::shortValue 507 ); 508 } 509 510 511 // ******************************************************************************************** 512 // ******************************************************************************************** 513 // Short from JsonObject 514 // ******************************************************************************************** 515 // ******************************************************************************************** 516 517 518 /** 519 * Extract a {@link JsonObject} property, and transform it to a {@code java.lang.Short}. 520 * 521 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_NULLNOTE> 522 * <EMBED CLASS=defs DATA-TYPE='java.lang.Short' DATA-JTYPE=JsonNumber DATA-M=shortValueExact> 523 * 524 * @param jo Any instance of {@link JsonObject}. 525 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 526 * @param isOptional <EMBED CLASS='external-html' DATA-FILE-ID=JR_ISOPT_JO> 527 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JR_RET_JO> 528 * 529 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JPMEX> 530 * @throws JsonArithmeticObjException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JAEX> 531 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JTOEX> 532 * 533 * @see RJInternal#GET(JsonObject, String, boolean, Function, Class) 534 * @see JsonNumber#bigDecimalValue() 535 */ 536 public static Short getShort(JsonObject jo, String propertyName, boolean isOptional) 537 { 538 return GET( 539 jo, propertyName, isOptional, jn -> jn.bigDecimalValue().shortValueExact(), 540 Short.class 541 ); 542 } 543 544 /** 545 * Retrieve a {@link JsonObject} property, and transform it to a {@code java.lang.Short}. 546 * 547 * <EMBED CLASS=defs DATA-TYPE='java.lang.Short' DATA-PTYPE=int DATA-THIS=getShort 548 * DATA-JTYPE=JsonNumber> 549 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC> 550 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_JO> 551 * 552 * @param jo Any instance of {@link JsonObject} 553 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 554 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 555 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 556 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_RET_JO> 557 * 558 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 559 * @throws JsonArithmeticObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 560 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNOEX> 561 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTOEX> 562 * 563 * @see RJInternal#GET(JsonObject, String, int, Number, Class, Function, Function) 564 * @see JsonNumber#bigDecimalValue() 565 */ 566 public static Short getShort 567 (JsonObject jo, String propertyName, int FLAGS, short defaultValue) 568 { 569 return GET( 570 jo, propertyName, FLAGS, defaultValue, Short.class, 571 jn -> jn.bigDecimalValue().shortValueExact(), 572 jn -> jn.bigDecimalValue().shortValue() 573 ); 574 } 575 576 /** 577 * Retrieve a {@link JsonObject} property containing a {@link JsonString}, and transform it to 578 * a {@code java.lang.Short}, with either a user-provided parser, or the standard java 579 * short-integer parser 580 * 581 * <EMBED CLASS=defs DATA-TYPE='java.lang.Short' DATA-PTYPE=short DATA-THIS=parseShort 582 * DATA-JTYPE=JsonString DATA-PARSER='Short.parseShort'> 583 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC_STR> 584 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_STR_JO> 585 * 586 * @param jo Any instance of {@link JsonObject} 587 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 588 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 589 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 590 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSER> 591 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSERET_JO> 592 * 593 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 594 * @throws JsonArithmeticObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 595 * @throws JsonStrParseObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JSPOEX> 596 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNOEX> 597 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTOEX> 598 * 599 * @see RJInternal#PARSE(JsonObject, String, int, Number, Class, Function, Function, Function) 600 */ 601 public static Short parseShort( 602 JsonObject jo, String propertyName, int FLAGS, short defaultValue, 603 Function<String, Short> optionalParser 604 ) 605 { 606 return PARSE( 607 jo, propertyName, FLAGS, defaultValue, Short.class, optionalParser, 608 BigDecimal::shortValueExact, BigDecimal::shortValue 609 ); 610 } 611 612 613 // ******************************************************************************************** 614 // ******************************************************************************************** 615 // Byte from JsonArray 616 // ******************************************************************************************** 617 // ******************************************************************************************** 618 619 620 /** 621 * Retrieve a {@link JsonArray} element, and transform it to a {@code java.lang.Byte}. 622 * 623 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_NULLNOTE> 624 * <EMBED CLASS=defs DATA-JTYPE=JsonNumber DATA-TYPE='java.lang.Byte' DATA-M=byteValueExact> 625 * 626 * @param ja Any instance of {@link JsonArray} 627 * @param index <EMBED CLASS='external-html' DATA-FILE-ID=JR_INDEX_JA> 628 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JR_RET_JA> 629 * 630 * @throws IndexOutOfBoundsException If {@code 'index'} is out of the bounds of {@code 'ja'} 631 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JTAEX> 632 * @throws JsonArithmeticArrException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JAEX> 633 * 634 * @see RJInternal#GET(JsonArray, int, Function, Class) 635 * @see JsonNumber#bigDecimalValue() 636 */ 637 public static Byte getByte(JsonArray ja, int index) 638 { return GET(ja, index, jn -> jn.bigDecimalValue().byteValueExact(), Byte.class); } 639 640 /** 641 * Retrieve a {@link JsonArray} element, and transform it to a {@code java.lang.Byte}. 642 * 643 * <EMBED CLASS=defs DATA-TYPE='java.lang.Byte' DATA-PTYPE=byte DATA-THIS=getByte 644 * DATA-JTYPE=JsonNumber> 645 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC> 646 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_JA> 647 * 648 * @param ja Any instance of {@link JsonArray} 649 * @param index The array index containing the element to retrieve. 650 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 651 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 652 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_RET_JA> 653 * 654 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 655 * @throws JsonArithmeticArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 656 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNAEX> 657 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTAEX> 658 * 659 * @see RJInternal#GET(JsonArray, int, int, Number, Class, Function, Function) 660 * @see JsonNumber#bigDecimalValue() 661 */ 662 public static Byte getByte(JsonArray ja, int index, int FLAGS, byte defaultValue) 663 { 664 return GET( 665 ja, index, FLAGS, defaultValue, Byte.class, 666 jn -> jn.bigDecimalValue().byteValueExact(), 667 jn -> jn.bigDecimalValue().byteValue() 668 ); 669 } 670 671 /** 672 * Retrieve a {@link JsonArray} element containing a {@link JsonString}, and transform it to a 673 * {@code java.lang.Byte}, with either a user-provided parser, or the standard java 674 * byte parser 675 * 676 * <EMBED CLASS=defs DATA-TYPE='java.lang.Byte' DATA-PTYPE=byte DATA-THIS=parseByte 677 * DATA-JTYPE=JsonString DATA-PARSER='Byte.parseByte'> 678 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC_STR> 679 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_STR_JA> 680 * 681 * @param ja Any instance of {@link JsonArray} 682 * @param index The array index containing the {@link JsonString} element to retrieve. 683 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 684 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 685 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSER> 686 * 687 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSERET_JA> 688 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 689 * @throws JsonArithmeticArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 690 * @throws JsonStrParseArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JSPAEX> 691 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNAEX> 692 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTAEX> 693 * 694 * @see RJInternal#PARSE(JsonObject, String, int, Number, Class, Function, Function, Function) 695 */ 696 public static Byte parseByte( 697 JsonArray ja, int index, int FLAGS, byte defaultValue, 698 Function<String, Byte> optionalParser 699 ) 700 { 701 return PARSE( 702 ja, index, FLAGS, defaultValue, Byte.class, optionalParser, 703 BigDecimal::byteValueExact, BigDecimal::byteValue 704 ); 705 } 706 707 708 // ******************************************************************************************** 709 // ******************************************************************************************** 710 // Byte from JsonObject 711 // ******************************************************************************************** 712 // ******************************************************************************************** 713 714 715 /** 716 * Extract a {@link JsonObject} property, and transform it to a {@code java.lang.Byte}. 717 * 718 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_NULLNOTE> 719 * <EMBED CLASS=defs DATA-TYPE='java.lang.Byte' DATA-JTYPE=JsonNumber DATA-M=byteValueExact> 720 * 721 * @param jo Any instance of {@link JsonObject}. 722 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 723 * @param isOptional <EMBED CLASS='external-html' DATA-FILE-ID=JR_ISOPT_JO> 724 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JR_RET_JO> 725 * 726 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JPMEX> 727 * @throws JsonArithmeticObjException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JAEX> 728 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JTOEX> 729 * 730 * @see RJInternal#GET(JsonObject, String, boolean, Function, Class) 731 * @see JsonNumber#bigDecimalValue() 732 */ 733 public static Byte getByte(JsonObject jo, String propertyName, boolean isOptional) 734 { 735 return GET( 736 jo, propertyName, isOptional, jn -> jn.bigDecimalValue().byteValueExact(), 737 Byte.class 738 ); 739 } 740 741 /** 742 * Retrieve a {@link JsonObject} property, and transform it to a {@code java.lang.Byte}. 743 * 744 * <EMBED CLASS=defs DATA-TYPE='java.lang.Byte' DATA-PTYPE=int DATA-THIS=getByte 745 * DATA-JTYPE=JsonNumber> 746 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC> 747 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_JO> 748 * 749 * @param jo Any instance of {@link JsonObject} 750 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 751 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 752 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 753 * 754 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_RET_JO> 755 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 756 * @throws JsonArithmeticObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 757 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNOEX> 758 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTOEX> 759 * 760 * @see RJInternal#GET(JsonObject, String, int, Number, Class, Function, Function) 761 * @see JsonNumber#bigDecimalValue() 762 */ 763 public static Byte getByte 764 (JsonObject jo, String propertyName, int FLAGS, byte defaultValue) 765 { 766 return GET( 767 jo, propertyName, FLAGS, defaultValue, Byte.class, 768 jn -> jn.bigDecimalValue().byteValueExact(), 769 jn -> jn.bigDecimalValue().byteValue() 770 ); 771 } 772 773 /** 774 * Retrieve a {@link JsonObject} element containing a {@link JsonString}, and transform it to 775 * a {@code java.lang.Byte}, with either a user-provided parser, or the standard java 776 * byte parser 777 * 778 * <EMBED CLASS=defs DATA-TYPE='java.lang.Byte' DATA-PTYPE=byte DATA-THIS=parseByte 779 * DATA-JTYPE=JsonString DATA-PARSER='Byte.parseByte'> 780 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC_STR> 781 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_STR_JO> 782 * 783 * @param jo Any instance of {@link JsonObject} 784 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 785 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 786 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 787 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSER> 788 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSERET_JO> 789 * 790 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 791 * @throws JsonArithmeticObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 792 * @throws JsonStrParseObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JSPOEX> 793 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNOEX> 794 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTOEX> 795 * 796 * @see RJInternal#PARSE(JsonObject, String, int, Number, Class, Function, Function, Function) 797 */ 798 public static Byte parseByte( 799 JsonObject jo, String propertyName, int FLAGS, byte defaultValue, 800 Function<String, Byte> optionalParser 801 ) 802 { 803 return PARSE( 804 jo, propertyName, FLAGS, defaultValue, Byte.class, optionalParser, 805 BigDecimal::byteValueExact, BigDecimal::byteValue 806 ); 807 } 808 809 810 // ******************************************************************************************** 811 // ******************************************************************************************** 812 // Double from JsonArray 813 // ******************************************************************************************** 814 // ******************************************************************************************** 815 816 817 /** 818 * Retrieve a {@link JsonArray} element, and transform it to a {@code java.lang.Double}. 819 * 820 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_NULLNOTE> 821 * <EMBED CLASS=defs DATA-JTYPE=JsonNumber DATA-TYPE='java.lang.Double' DATA-M=doubleValue 822 * DATA-INFINITY=Double> 823 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_FLOAT> 824 * 825 * @param ja Any instance of {@link JsonArray} 826 * @param index <EMBED CLASS='external-html' DATA-FILE-ID=JR_INDEX_JA> 827 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JR_RET_JA> 828 * 829 * @throws IndexOutOfBoundsException If {@code 'index'} is out of the bounds of {@code 'ja'} 830 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JTAEX> 831 * @throws JsonArithmeticArrException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JAEX_INF> 832 * 833 * @see RJInternal#GET(JsonArray, int, Function, Class) 834 * @see RJInternal#DOUBLE_WITH_CHECK(JsonNumber) 835 */ 836 public static Double getDouble(JsonArray ja, int index) 837 { return GET(ja, index, RJInternal::DOUBLE_WITH_CHECK, Double.class); } 838 839 /** 840 * Retrieve a {@link JsonArray} element, and transform it to a {@code java.lang.Double}. 841 * 842 * <EMBED CLASS=defs DATA-TYPE='java.lang.Double' DATA-JTYPE=JsonNumber DATA-M=doubleValue 843 * DATA-PTYPE=double DATA-THIS=getDouble> 844 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC> 845 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_JA> 846 * 847 * @param ja Any instance of {@link JsonArray} 848 * @param index The array index containing the element to retrieve. 849 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 850 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 851 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_RET_JA> 852 * 853 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 854 * @throws JsonArithmeticArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 855 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNAEX> 856 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTAEX> 857 * 858 * @see RJInternal#GET(JsonArray, int, int, Number, Class, Function, Function) 859 * @see RJInternal#DOUBLE_WITH_CHECK(JsonNumber) 860 * @see JsonNumber#bigDecimalValue() 861 */ 862 public static Double getDouble(JsonArray ja, int index, int FLAGS, double defaultValue) 863 { 864 return GET( 865 ja, index, FLAGS, defaultValue, Double.class, 866 RJInternal::DOUBLE_WITH_CHECK, jn -> jn.bigDecimalValue().doubleValue() 867 ); 868 } 869 870 /** 871 * Retrieve a {@link JsonArray} element containing a {@link JsonString}, and transform it to a 872 * {@code java.lang.Double}, with either a user-provided parser, or the standard java 873 * double parser 874 * 875 * <EMBED CLASS=defs DATA-TYPE='java.lang.Double' DATA-PTYPE=double DATA-THIS=parseDouble 876 * DATA-JTYPE=JsonString DATA-PARSER='Double.parseDouble'> 877 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC_STR> 878 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_STR_JA> 879 * 880 * @param ja Any instance of {@link JsonArray} 881 * @param index The array index containing the {@link JsonString} element to retrieve. 882 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 883 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 884 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSER> 885 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSERET_JA> 886 * 887 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 888 * @throws JsonArithmeticArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 889 * @throws JsonArithmeticArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 890 * @throws JsonStrParseArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JSPAEX> 891 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNAEX> 892 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTAEX> 893 * 894 * @see RJInternal#PARSE(JsonObject, String, int, Number, Class, Function, Function, Function) 895 */ 896 public static Double parseDouble( 897 JsonArray ja, int index, int FLAGS, double defaultValue, 898 Function<String, Double> optionalParser 899 ) 900 { 901 return PARSE( 902 ja, index, FLAGS, defaultValue, Double.class, optionalParser, 903 RJInternal::DOUBLE_WITH_CHECK, BigDecimal::doubleValue 904 ); 905 } 906 907 908 // ******************************************************************************************** 909 // ******************************************************************************************** 910 // Double from JsonObject 911 // ******************************************************************************************** 912 // ******************************************************************************************** 913 914 915 /** 916 * Extract a {@link JsonObject} property, and transform it to a {@code java.lang.Double}. 917 * 918 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_NULLNOTE> 919 * <EMBED CLASS=defs DATA-TYPE='java.lang.Double' DATA-JTYPE=JsonNumber DATA-M=doubleValue 920 * DATA-INFINITY=Double> 921 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_FLOAT> 922 * 923 * @param jo Any instance of {@link JsonObject}. 924 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 925 * @param isOptional <EMBED CLASS='external-html' DATA-FILE-ID=JR_ISOPT_JO> 926 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JR_RET_JO> 927 * 928 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JPMEX> 929 * @throws JsonArithmeticObjException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JAEX_INF> 930 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JTOEX> 931 * 932 * @see RJInternal#GET(JsonObject, String, boolean, Function, Class) 933 * @see RJInternal#DOUBLE_WITH_CHECK(JsonNumber) 934 */ 935 public static Double getDouble(JsonObject jo, String propertyName, boolean isOptional) 936 { return GET(jo, propertyName, isOptional, RJInternal::DOUBLE_WITH_CHECK, Double.class); } 937 938 /** 939 * Retrieve a {@link JsonObject} property, and transform it to a {@code java.lang.Double}. 940 * <EMBED CLASS=defs DATA-TYPE='java.lang.Double' DATA-THIS=getDouble DATA-PTYPE=double 941 * 942 * DATA-M=doubleValue DATA-JTYPE=JsonNumber> 943 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC> 944 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_JO> 945 * 946 * @param jo Any instance of {@link JsonObject} 947 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 948 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 949 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 950 * 951 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_RET_JO> 952 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 953 * @throws JsonArithmeticObjException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JAEX> 954 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNOEX> 955 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTOEX> 956 * 957 * @see RJInternal#GET(JsonObject, String, int, Number, Class, Function, Function) 958 * @see RJInternal#DOUBLE_WITH_CHECK(JsonNumber) 959 * @see JsonNumber#bigDecimalValue() 960 */ 961 public static Double getDouble 962 (JsonObject jo, String propertyName, int FLAGS, double defaultValue) 963 { 964 return GET( 965 jo, propertyName, FLAGS, defaultValue, Double.class, 966 RJInternal::DOUBLE_WITH_CHECK, jn -> jn.bigDecimalValue().doubleValue() 967 ); 968 } 969 970 /** 971 * Retrieve a {@link JsonObject} property containing a {@link JsonString}, and transform it to 972 * a {@code java.lang.Double}, with either a user-provided parser, or the standard java 973 * double parser 974 * 975 * <EMBED CLASS=defs DATA-TYPE='java.lang.Double' DATA-PTYPE=double DATA-THIS=parseDouble 976 * DATA-JTYPE=JsonString DATA-PARSER='Double.parseDouble'> 977 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC_STR> 978 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_STR_JO> 979 * 980 * @param jo Any instance of {@link JsonObject} 981 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 982 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 983 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 984 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSER> 985 * 986 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSERET_JO> 987 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 988 * @throws JsonArithmeticObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 989 * @throws JsonStrParseObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JSPOEX> 990 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNOEX> 991 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTOEX> 992 * 993 * @see RJInternal#PARSE(JsonObject, String, int, Number, Class, Function, Function, Function) 994 */ 995 public static Double parseDouble( 996 JsonObject jo, String propertyName, int FLAGS, double defaultValue, 997 Function<String, Double> optionalParser 998 ) 999 { 1000 return PARSE( 1001 jo, propertyName, FLAGS, defaultValue, Double.class, optionalParser, 1002 RJInternal::DOUBLE_WITH_CHECK, BigDecimal::doubleValue 1003 ); 1004 } 1005 1006 1007 // ******************************************************************************************** 1008 // ******************************************************************************************** 1009 // Float from JsonArray 1010 // ******************************************************************************************** 1011 // ******************************************************************************************** 1012 1013 1014 /** 1015 * Retrieve a {@link JsonArray} element, and transform it to a {@code java.lang.Float}. 1016 * 1017 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_NULLNOTE> 1018 * <EMBED CLASS=defs DATA-JTYPE=JsonNumber DATA-TYPE='java.lang.Float' DATA-M=floatValue 1019 * DATA-INFINITY=Float> 1020 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_FLOAT> 1021 * 1022 * @param ja Any instance of {@link JsonArray} 1023 * @param index <EMBED CLASS='external-html' DATA-FILE-ID=JR_INDEX_JA> 1024 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JR_RET_JA> 1025 * 1026 * @throws IndexOutOfBoundsException If {@code 'index'} is out of the bounds of {@code 'ja'} 1027 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JTAEX> 1028 * @throws JsonArithmeticArrException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JAEX_INF> 1029 * 1030 * @see RJInternal#GET(JsonArray, int, Function, Class) 1031 * @see RJInternal#FLOAT_WITH_CHECK(JsonNumber) 1032 */ 1033 public static Float getFloat(JsonArray ja, int index) 1034 { return GET(ja, index, RJInternal::FLOAT_WITH_CHECK, Float.class); } 1035 1036 /** 1037 * Retrieve a {@link JsonArray} element, and transform it to a {@code java.lang.Float}. 1038 * 1039 * <EMBED CLASS=defs DATA-TYPE='java.lang.Float' DATA-PTYPE=float DATA-THIS=getFloat 1040 * DATA-JTYPE=JsonNumber DATA-M=floatValue> 1041 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC> 1042 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_JA> 1043 * 1044 * @param ja Any instance of {@link JsonArray} 1045 * @param index The array index containing the element to retrieve. 1046 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 1047 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 1048 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_RET_JA> 1049 * 1050 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 1051 * @throws JsonArithmeticArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 1052 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNAEX> 1053 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTAEX> 1054 * 1055 * @see RJInternal#GET(JsonArray, int, int, Number, Class, Function, Function) 1056 * @see RJInternal#FLOAT_WITH_CHECK(JsonNumber) 1057 * @see JsonNumber#bigDecimalValue() 1058 */ 1059 public static Float getFloat(JsonArray ja, int index, int FLAGS, float defaultValue) 1060 { 1061 return GET( 1062 ja, index, FLAGS, defaultValue, Float.class, 1063 RJInternal::FLOAT_WITH_CHECK, jn -> jn.bigDecimalValue().floatValue() 1064 ); 1065 } 1066 1067 /** 1068 * Retrieve a {@link JsonArray} element containing a {@link JsonString}, and transform it to a 1069 * {@code java.lang.Float}, with either a user-provided parser, or the standard java 1070 * float parser 1071 * 1072 * <EMBED CLASS=defs DATA-TYPE='java.lang.Float' DATA-PTYPE=float DATA-THIS=parseFloat 1073 * DATA-JTYPE=JsonString DATA-PARSER='Float.parseFloat'> 1074 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC_STR> 1075 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_STR_JA> 1076 * 1077 * @param ja Any instance of {@link JsonArray} 1078 * @param index The array index containing the {@link JsonString} element to retrieve. 1079 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 1080 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 1081 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSER> 1082 * 1083 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSERET_JA> 1084 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 1085 * @throws JsonArithmeticArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 1086 * @throws JsonStrParseArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JSPAEX> 1087 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNAEX> 1088 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTAEX> 1089 * 1090 * @see RJInternal#PARSE(JsonObject, String, int, Number, Class, Function, Function, Function) 1091 */ 1092 public static Float parseFloat( 1093 JsonArray ja, int index, int FLAGS, float defaultValue, 1094 Function<String, Float> optionalParser 1095 ) 1096 { 1097 return PARSE( 1098 ja, index, FLAGS, defaultValue, Float.class, optionalParser, 1099 RJInternal::FLOAT_WITH_CHECK, BigDecimal::floatValue 1100 ); 1101 } 1102 1103 1104 // ******************************************************************************************** 1105 // ******************************************************************************************** 1106 // Float from JsonObject 1107 // ******************************************************************************************** 1108 // ******************************************************************************************** 1109 1110 1111 /** 1112 * Extract a {@link JsonObject} property, and transform it to a {@code java.lang.Float}. 1113 * 1114 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_NULLNOTE> 1115 * <EMBED CLASS=defs DATA-TYPE='java.lang.Float' DATA-JTYPE=JsonNumber DATA-M=floatValue 1116 * DATA-INFINITY=Float> 1117 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_FLOAT> 1118 * 1119 * @param jo Any instance of {@link JsonObject}. 1120 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 1121 * @param isOptional <EMBED CLASS='external-html' DATA-FILE-ID=JR_ISOPT_JO> 1122 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JR_RET_JO> 1123 * 1124 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JPMEX> 1125 * @throws JsonArithmeticObjException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JAEX_INF> 1126 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JTOEX> 1127 * 1128 * @see RJInternal#GET(JsonObject, String, boolean, Function, Class) 1129 * @see RJInternal#FLOAT_WITH_CHECK(JsonNumber) 1130 */ 1131 public static Float getFloat(JsonObject jo, String propertyName, boolean isOptional) 1132 { return GET(jo, propertyName, isOptional, RJInternal::FLOAT_WITH_CHECK, Float.class); } 1133 1134 /** 1135 * Retrieve a {@link JsonObject} property, and transform it to a {@code java.lang.Float}. 1136 * 1137 * <EMBED CLASS=defs DATA-TYPE='java.lang.Float' DATA-PTYPE=int DATA-THIS=getFloat 1138 * DATA-JTYPE=JsonNumber DATA-M=doubleValue DATA-INFINITY=Double> 1139 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC> 1140 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_JO> 1141 * 1142 * @param jo Any instance of {@link JsonObject} 1143 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 1144 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 1145 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 1146 * 1147 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_RET_JO> 1148 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 1149 * @throws JsonArithmeticObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 1150 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNOEX> 1151 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTOEX> 1152 * 1153 * @see RJInternal#GET(JsonObject, String, int, Number, Class, Function, Function) 1154 * @see RJInternal#FLOAT_WITH_CHECK(JsonNumber) 1155 * @see JsonNumber#bigDecimalValue() 1156 */ 1157 public static Float getFloat 1158 (JsonObject jo, String propertyName, int FLAGS, float defaultValue) 1159 { 1160 return GET( 1161 jo, propertyName, FLAGS, defaultValue, Float.class, 1162 RJInternal::FLOAT_WITH_CHECK, jn -> jn.bigDecimalValue().floatValue() 1163 ); 1164 } 1165 1166 /** 1167 * Retrieve a {@link JsonObject} property containing a {@link JsonString}, and transform it to 1168 * a {@code java.lang.Float}, with either a user-provided parser, or the standard java 1169 * float parser 1170 * 1171 * <EMBED CLASS=defs DATA-TYPE='java.lang.Float' DATA-PTYPE=float DATA-THIS=parseFloat 1172 * DATA-JTYPE=JsonString DATA-PARSER='Float.parseFloat'> 1173 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DESC_STR> 1174 * <EMBED CLASS='external-html' DATA-FILE-ID=JRF_XTRA_STR_JO> 1175 * 1176 * @param jo Any instance of {@link JsonObject} 1177 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 1178 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 1179 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 1180 * @param parser <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSER> 1181 * 1182 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSERET_JO> 1183 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 1184 * @throws JsonArithmeticObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JAEX> 1185 * @throws JsonStrParseObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JSPOEX> 1186 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNOEX> 1187 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTOEX> 1188 * 1189 * @see RJInternal#PARSE(JsonObject, String, int, Number, Class, Function, Function, Function) 1190 */ 1191 public static Float parseFloat( 1192 JsonObject jo, String propertyName, int FLAGS, float defaultValue, 1193 Function<String, Float> parser 1194 ) 1195 { 1196 return PARSE( 1197 jo, propertyName, FLAGS, defaultValue, Float.class, parser, 1198 RJInternal::FLOAT_WITH_CHECK, BigDecimal::floatValue 1199 ); 1200 } 1201 1202 1203 // ******************************************************************************************** 1204 // ******************************************************************************************** 1205 // Boolean from a JsonArray 1206 // ******************************************************************************************** 1207 // ******************************************************************************************** 1208 1209 1210 /** 1211 * Retrieve a {@link JsonArray} element, and transform it to a {@code java.lang.Boolean}. 1212 * 1213 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_NULLNOTE> 1214 * <EMBED CLASS=defs DATA-JTYPE='JSON-BOOLEAN' DATA-TYPE='java.lang.Boolean'> 1215 * 1216 * @param ja Any instance of {@link JsonArray} 1217 * @param index <EMBED CLASS='external-html' DATA-FILE-ID=JR_INDEX_JA> 1218 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JR_RET_JA> 1219 * @throws IndexOutOfBoundsException If {@code 'index'} is out of the bounds of {@code 'ja'} 1220 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JTAEX> 1221 * 1222 * @see JsonValue#getValueType() 1223 * @see JsonValue.ValueType#TRUE 1224 * @see JsonValue.ValueType#FALSE 1225 * @see JsonValue#TRUE 1226 * @see JsonValue#FALSE 1227 */ 1228 public static Boolean getBoolean(JsonArray ja, int index) 1229 { 1230 // This will throw an IndexOutOfBoundsException if the index is out of bounds. 1231 JsonValue jv = ja.get(index); 1232 1233 switch (jv.getValueType()) 1234 { 1235 // This method 'getBoolean' allows for null-returns. If Json-Null, return Java-Null. 1236 case NULL: return null; 1237 1238 // AGAIN: "Type-Mapping" or "Type-Translating" really isn't rocket-science 1239 case TRUE: return true; 1240 case FALSE: return false; 1241 1242 // The JsonValue at the specified array-index does not contain one of the two 1243 // Json-Boolean Types. Throw an exception. 1244 1245 default: throw new JsonTypeArrException(ja, index, TRUE, jv, Boolean.class); 1246 } 1247 } 1248 1249 /** 1250 * Retrieve a {@link JsonArray} element, and transform it to a {@code java.lang.Boolean}. 1251 * 1252 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_NULLNOTE> 1253 * <EMBED CLASS=defs DATA-JTYPE='JSON-BOOLEAN' DATA-TYPE='java.lang.Boolean'> 1254 * 1255 * @param ja Any instance of {@link JsonArray} 1256 * @param index <EMBED CLASS='external-html' DATA-FILE-ID=JR_INDEX_JA> 1257 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 1258 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 1259 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_RET_JA> 1260 * 1261 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 1262 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNOEX> 1263 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTOEX> 1264 * 1265 * @see JsonValue#getValueType() 1266 * @see JsonValue.ValueType#TRUE 1267 * @see JsonValue.ValueType#FALSE 1268 * @see JsonValue#TRUE 1269 * @see JsonValue#FALSE 1270 */ 1271 public static Boolean getBoolean(JsonArray ja, int index, int FLAGS, boolean defaultValue) 1272 { 1273 // When TRUE, the index provided turned out to be outside of the bounds of the array. The 1274 // IndexOutOfBounds "handler" (the method called here) will check the FLAGS, and: 1275 // 1276 // 1) return the defaultValue (if Requested by 'FLAGS' for IOOBEX) 1277 // 2) return null (if Requested by 'FLAGS' for IOOBEX) 1278 // 3) throw IndexOutOfBoundsException 1279 1280 if (index >= ja.size()) return IOOBEX(ja, index, defaultValue, FLAGS); 1281 1282 JsonValue jv = ja.get(index); // Throw an IndexOutOfBoundsException 1283 1284 switch (jv.getValueType()) 1285 { 1286 // When a 'NULL' (Json-Null) JsonValue is present, the JsonNullArrException 'handler' 1287 // will do one of the following: 1288 // 1289 // 1) return the defaultValue (if Requested by 'FLAGS' for JNAEX) 1290 // 2) return null (if Requested by 'FLAGS' for JNAEX) 1291 // 3) throw JsonNullArrException 1292 1293 case NULL: return JNAEX(ja, index, defaultValue, FLAGS, TRUE, Boolean.class); 1294 1295 // AGAIN: "Type-Mapping" or "Type-Translating" really isn't rocket-science 1296 case TRUE: return true; 1297 case FALSE: return false; 1298 1299 // The JsonValue at the specified array-index does not contain one of the two 1300 // Json-Boolean Types. The "JsonTypeArrException Handler" will do one of these: 1301 // 1302 // 1) return the defaultValue (if Requested by 'FLAGS' for JTAEX) 1303 // 2) return null (if Requested by 'FLAGS' for JTAEX) 1304 // 3) throw JsonTypeArrException 1305 1306 default: return JTAEX(ja, index, defaultValue, FLAGS, TRUE, jv, Boolean.class); 1307 } 1308 } 1309 1310 /** 1311 * Retrieve a {@link JsonArray} element containing a {@link JsonString}, and transform it to a 1312 * {@code java.lang.Boolean}, with either a user-provided parser, or the standard java 1313 * boolean parser 1314 * 1315 * <EMBED CLASS=defs DATA-TYPE='java.lang.Boolean' DATA-PTYPE=boolean 1316 * DATA-JTYPE=JsonString DATA-PARSER='Boolean.parseBoolean'> 1317 * 1318 * @param ja Any instance of {@link JsonArray} 1319 * @param index The array index containing the {@link JsonString} element to retrieve. 1320 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 1321 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 1322 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSER> 1323 * 1324 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSERET_JA> 1325 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 1326 * @throws JsonStrParseArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JSPAEX> 1327 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNAEX> 1328 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTAEX> 1329 */ 1330 public static Boolean parseBoolean( 1331 JsonArray ja, int index, int FLAGS, boolean defaultValue, 1332 Function<String, Boolean> optionalParser 1333 ) 1334 { 1335 // When TRUE, the index provided turned out to be outside of the bounds of the array. The 1336 // IndexOutOfBounds "handler" (the method called here) will check the FLAGS, and: 1337 // 1338 // 1) return the defaultValue (if Requested by 'FLAGS' for IOOBEX) 1339 // 2) return null (if Requested by 'FLAGS' for IOOBEX) 1340 // 3) throw IndexOutOfBoundsException 1341 1342 if (index >= ja.size()) return IOOBEX(ja, index, defaultValue, FLAGS); 1343 1344 JsonValue jv = ja.get(index); 1345 1346 switch (jv.getValueType()) 1347 { 1348 // When a 'NULL' (Json-Null) JsonValue is present, the JsonNullArrException 'handler' 1349 // will do one of the following: 1350 // 1351 // 1) return the defaultValue (if Requested by 'FLAGS' for JNAEX) 1352 // 2) return null (if Requested by 'FLAGS' for JNAEX) 1353 // 3) throw JsonNullArrException 1354 1355 case NULL: return JNAEX(ja, index, defaultValue, FLAGS, STRING, Boolean.class); 1356 1357 case STRING: 1358 1359 String s = ((JsonString) jv).getString(); 1360 1361 // NOTE: This isn't actually an "Exception Case", and if the user hasn't made 1362 // a request, the empty-string is passed to whatever parser is configured 1363 1364 if (s.length() == 0) 1365 { 1366 if ((FLAGS & RETURN_NULL_ON_0LEN_STR) != 0) return null; 1367 if ((FLAGS & RETURN_DEFVAL_ON_0LEN_STR) != 0) return defaultValue; 1368 if ((FLAGS & RETURN_NULL_ON_ANY_ALL) != 0) return null; 1369 if ((FLAGS & RETURN_DEFVAL_ON_ANY_ALL) != 0) return defaultValue; 1370 } 1371 1372 try 1373 { 1374 return (optionalParser != null) 1375 ? optionalParser.apply(s) 1376 : Boolean.parseBoolean(s.trim()); 1377 } 1378 1379 // HANDLER STRIKES AGAIN! - but this time for "JsonStrParseArrException" 1380 // RETURNS: null, or defaultValue, (otherwise throws JsonStrParseArrException) 1381 1382 catch (Exception e) 1383 { return JSPAEX(e, ja, index, defaultValue, FLAGS, jv, Boolean.class); } 1384 1385 // The JsonValue at the specified array-index does not contain an JsonString. 1386 // The "JsonTypeArrException Handler" will do one of these: 1387 // 1388 // 1) return the defaultValue (if Requested by 'FLAGS' for JTAEX) 1389 // 2) return null (if Requested by 'FLAGS' for JTAEX) 1390 // 3) throw JsonTypeArrException 1391 1392 default: return JTAEX(ja, index, defaultValue, FLAGS, STRING, jv, Boolean.class); 1393 } 1394 } 1395 1396 1397 // ******************************************************************************************** 1398 // ******************************************************************************************** 1399 // Boolean from a JsonObject 1400 // ******************************************************************************************** 1401 // ******************************************************************************************** 1402 1403 1404 /** 1405 * Extract a {@link JsonObject} property, and transform it to a {@code java.lang.Boolean}. 1406 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_NULLNOTE> 1407 * <EMBED CLASS=defs DATA-TYPE='java.lang.Boolean' DATA-JTYPE='JSON-BOOLEAN'> 1408 * 1409 * @param jo Any instance of {@link JsonObject}. 1410 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 1411 * @param isOptional <EMBED CLASS='external-html' DATA-FILE-ID=JR_ISOPT_JO> 1412 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JR_RET_JO> 1413 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JPMEX> 1414 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JR_JTOEX> 1415 * 1416 * @see JsonValue#getValueType() 1417 * @see JsonValue.ValueType#TRUE 1418 * @see JsonValue.ValueType#FALSE 1419 * @see JsonValue#TRUE 1420 * @see JsonValue#FALSE 1421 */ 1422 public static Boolean getBoolean(JsonObject jo, String propertyName, boolean isOptional) 1423 { 1424 if (! jo.containsKey(propertyName)) 1425 { 1426 if (isOptional) return null; 1427 1428 throw new JsonPropMissingException(jo, propertyName, TRUE, Boolean.class); 1429 } 1430 1431 JsonValue jv = jo.get(propertyName); 1432 1433 switch (jv.getValueType()) 1434 { 1435 // This method 'getBoolean' allows for null-returns. If Json-Null, return Java-Null. 1436 case NULL: return null; 1437 1438 // AGAIN: "Type-Mapping" or "Type-Translating" really isn't rocket-science 1439 case TRUE: return true; 1440 case FALSE: return false; 1441 1442 // The JsonValue at the specified array-index does not contain one of the two 1443 // Json-Boolean Types. Throw an exception. 1444 1445 default: throw new JsonTypeObjException 1446 (jo, propertyName, TRUE, jv, Boolean.class); 1447 } 1448 } 1449 1450 /** 1451 * Retrieve a {@link JsonObject} property, and transform it to a {@code java.lang.Boolean}. 1452 * <EMBED CLASS='external-html' DATA-FILE-ID=JR_NULLNOTE> 1453 * <EMBED CLASS=defs DATA-JTYPE='JSON-BOOLEAN' DATA-TYPE='java.lang.Boolean'> 1454 * 1455 * @param jo Any instance of {@link JsonObject} 1456 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 1457 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 1458 * 1459 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 1460 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_RET_JO> 1461 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 1462 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNOEX> 1463 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTOEX> 1464 * 1465 * @see JsonValue#getValueType() 1466 * @see JsonValue.ValueType#TRUE 1467 * @see JsonValue.ValueType#FALSE 1468 * @see JsonValue#TRUE 1469 * @see JsonValue#FALSE 1470 */ 1471 public static Boolean getBoolean 1472 (JsonObject jo, String propertyName, int FLAGS, boolean defaultValue) 1473 { 1474 JsonValue jv = jo.get(propertyName); 1475 1476 // When TRUE, the user-specified 'property' (named by 'propertyName') isn't actually one 1477 // of the listed properties inside the JsonObject. The JsonPropMissingException "handler" 1478 // (the method called here) will check the FLAGS, and: 1479 // 1480 // 1) return the defaultValue (if Requested by 'FLAGS' for JPMEX) 1481 // 2) return null (if Requested by 'FLAGS' for JPMEX) 1482 // 3) throw JsonPropMissingException 1483 1484 if (jv == null) return JPMEX(jo, propertyName, defaultValue, FLAGS, TRUE, Boolean.class); 1485 1486 switch (jv.getValueType()) 1487 { 1488 // When a 'NULL' (Json-Null) JsonValue is present, the JsonNullObjException 'handler' 1489 // will do one of the following: 1490 // 1491 // 1) return the defaultValue (if Requested by 'FLAGS' for JNOEX) 1492 // 2) return null (if Requested by 'FLAGS' for JNOEX) 1493 // 3) throw JsonNullArrException 1494 1495 case NULL: return JNOEX(jo, propertyName, defaultValue, FLAGS, TRUE, Boolean.class); 1496 1497 // AGAIN: "Type-Mapping" or "Type-Translating" really isn't rocket-science 1498 case TRUE: return true; 1499 case FALSE: return false; 1500 1501 // The property contains a JsonValue that is not one of the two 1502 // Json-Boolean Types. Throw an exception. 1503 1504 // The JsonValue of 'propertyName' does not contain an JsonString. 1505 // The "JsonTypeObjException Handler" will do one of these: 1506 // 1507 // 1) return the defaultValue (if Requested by 'FLAGS' for JTOEX) 1508 // 2) return null (if Requested by 'FLAGS' for JTOEX) 1509 // 3) throw JsonTypeObjException 1510 1511 default: return JTOEX(jo, propertyName, defaultValue, FLAGS, TRUE, jv, Boolean.class); 1512 } 1513 } 1514 1515 /** 1516 * Retrieve a {@link JsonObject} property containing a {@link JsonString}, and transform it to 1517 * a {@code java.lang.Boolean}, with either a user-provided parser, or the standard java 1518 * boolean parser 1519 * 1520 * <EMBED CLASS=defs DATA-TYPE='java.lang.Float' DATA-PTYPE=float 1521 * DATA-JTYPE=JsonString DATA-PARSER='Float.parseFloat'> 1522 * 1523 * @param jo Any instance of {@link JsonObject} 1524 * @param propertyName <EMBED CLASS='external-html' DATA-FILE-ID=JR_PN_JO> 1525 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 1526 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRF_DEFV> 1527 * @param parser <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSER> 1528 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRF_PARSERET_JO> 1529 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 1530 * @throws JsonStrParseObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JSPOEX> 1531 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JNOEX> 1532 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JTOEX> 1533 */ 1534 public static Boolean parseBoolean( 1535 JsonObject jo, String propertyName, int FLAGS, boolean defaultValue, 1536 Function<String, Boolean> parser 1537 ) 1538 { 1539 JsonValue jv = jo.get(propertyName); 1540 1541 // When TRUE, the user-specified 'property' (named by 'propertyName') isn't actually one 1542 // of the listed properties inside the JsonObject. The JsonPropMissingException "handler" 1543 // (the method called here) will check the FLAGS, and: 1544 // 1545 // 1) return the defaultValue (if Requested by 'FLAGS' for JPMEX) 1546 // 2) return null (if Requested by 'FLAGS' for JPMEX) 1547 // 3) throw JsonPropMissingException 1548 1549 if (jv == null) return JPMEX(jo, propertyName, defaultValue, FLAGS, STRING, Boolean.class); 1550 1551 switch (jv.getValueType()) 1552 { 1553 // When a 'NULL' (Json-Null) JsonValue is present, the JsonNullObjException 'handler' 1554 // will do one of the following: 1555 // 1556 // 1) return the defaultValue (if Requested by 'FLAGS' for JNOEX) 1557 // 2) return null (if Requested by 'FLAGS' for JNOEX) 1558 // 3) throw JsonNullArrException 1559 1560 case NULL: return JNOEX(jo, propertyName, defaultValue, FLAGS, STRING, Boolean.class); 1561 1562 case STRING: 1563 1564 String s = ((JsonString) jv).getString(); 1565 1566 // NOTE: This isn't actually an "Exception Case", and if the user hasn't made 1567 // a request, the empty-string is passed to whatever parser is configured 1568 1569 if (s.length() == 0) 1570 { 1571 if ((FLAGS & RETURN_NULL_ON_0LEN_STR) != 0) return null; 1572 if ((FLAGS & RETURN_DEFVAL_ON_0LEN_STR) != 0) return defaultValue; 1573 if ((FLAGS & RETURN_NULL_ON_ANY_ALL) != 0) return null; 1574 if ((FLAGS & RETURN_DEFVAL_ON_ANY_ALL) != 0) return defaultValue; 1575 } 1576 1577 try 1578 { return (parser != null) ? parser.apply(s) : Boolean.parseBoolean(s.trim()); } 1579 1580 // HANDLER STRIKES AGAIN! - but this time for "JsonStrParseObjException" 1581 // RETURNS: null, or defaultValue, (otherwise throws JsonStrParseObjException) 1582 1583 catch (Exception e) 1584 { return JSPOEX(e, jo, propertyName, defaultValue, FLAGS, jv, Boolean.class); } 1585 1586 // The JsonValue of 'propertyName' does not contain an JsonString. 1587 // The "JsonTypeObjException Handler" will do one of these: 1588 // 1589 // 1) return the defaultValue (if Requested by 'FLAGS' for JTOEX) 1590 // 2) return null (if Requested by 'FLAGS' for JTOEX) 1591 // 3) throw JsonTypeObjException 1592 1593 default: return JTOEX(jo, propertyName, defaultValue, FLAGS, STRING, jv, Boolean.class); 1594 } 1595 } 1596 1597 1598 // ******************************************************************************************** 1599 // ******************************************************************************************** 1600 // ReadBoxedJSON.XL 1601 // ******************************************************************************************** 1602 // ******************************************************************************************** 1603 1604 1605 /** 1606 * Utilities for parsing & converting <B><I>{@link JsonString}'s</I> 1607 * <SPAN STYLE='color: red;'>or</SPAN> <I>{@link JsonNumber}'s</I></B> into Java 1608 * Boxed-Primitive Types. 1609 * 1610 * <EMBED CLASS='external-html' DATA-FILE-ID=GLASS_FISH_NOTE> 1611 * <EMBED CLASS='external-html' DATA-CH='java.lang.Character' DATA-FILE-ID=JAVA_LANG_CHAR> 1612 * 1613 * @see Json 1614 * @see JsonObject 1615 * @see JsonArray 1616 */ 1617 @Torello.JavaDoc.StaticFunctional 1618 @Torello.JavaDoc.JDHeaderBackgroundImg(EmbedTagFileID="JSON_JDHBI") 1619 public static class XL 1620 { 1621 private XL() { } 1622 1623 1624 // **************************************************************************************** 1625 // **************************************************************************************** 1626 // JsonArray index location to Number 1627 // **************************************************************************************** 1628 // **************************************************************************************** 1629 1630 1631 /** 1632 * <EMBED CLASS=defs DATA-TYPE=Integer DATA-PARSER='Integer.parseInt'> 1633 * <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DESC_JA> 1634 * 1635 * @param ja Any {@link JsonArray} 1636 * @param i Any index into the {@code JsonArray} 1637 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 1638 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DEFVAL> 1639 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_PARSER> 1640 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_RET_JA> 1641 * 1642 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 1643 * @throws JsonStrParseArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JSPAEX> 1644 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JNAEX> 1645 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JTAEX> 1646 * 1647 * @see #getInteger(JsonArray, int, int, int) 1648 * @see #parseInteger(JsonArray, int, int, int, Function) 1649 */ 1650 public static Integer getInteger( 1651 JsonArray ja, int i, int FLAGS, int defaultValue, 1652 Function<String, Integer> optionalParser 1653 ) 1654 { 1655 JsonValue.ValueType t; 1656 1657 return ((i >= ja.size()) || ((t=ja.get(i).getValueType()) == NUMBER) || (t != STRING)) 1658 ? ReadBoxedJSON.getInteger(ja, i, FLAGS, defaultValue) 1659 : ReadBoxedJSON.parseInteger(ja, i, FLAGS, defaultValue, optionalParser); 1660 } 1661 1662 /** 1663 * <EMBED CLASS=defs DATA-TYPE=Long DATA-PARSER='Long.parseLong'> 1664 * <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DESC_JA> 1665 * 1666 * @param ja Any {@link JsonArray} 1667 * @param i Any index into the {@code JsonArray} 1668 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 1669 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DEFVAL> 1670 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_PARSER> 1671 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_RET_JA> 1672 * 1673 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 1674 * @throws JsonStrParseArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JSPAEX> 1675 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JNAEX> 1676 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JTAEX> 1677 * 1678 * @see #getLong(JsonArray, int, int, long) 1679 * @see #parseLong(JsonArray, int, int, long, Function) 1680 */ 1681 public static Long getLong( 1682 JsonArray ja, int i, int FLAGS, long defaultValue, 1683 Function<String, Long> optionalParser 1684 ) 1685 { 1686 JsonValue.ValueType t; 1687 1688 return ((i >= ja.size()) || ((t=ja.get(i).getValueType()) == NUMBER) || (t != STRING)) 1689 ? ReadBoxedJSON.getLong(ja, i, FLAGS, defaultValue) 1690 : ReadBoxedJSON.parseLong(ja, i, FLAGS, defaultValue, optionalParser); 1691 } 1692 1693 /** 1694 * <EMBED CLASS=defs DATA-TYPE=Short DATA-PARSER='Short.parseShort'> 1695 * <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DESC_JA> 1696 * 1697 * @param ja Any {@link JsonArray} 1698 * @param i Any index into the {@code JsonArray} 1699 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 1700 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DEFVAL> 1701 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_PARSER> 1702 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_RET_JA> 1703 * 1704 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 1705 * @throws JsonStrParseArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JSPAEX> 1706 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JNAEX> 1707 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JTAEX> 1708 * 1709 * @see #getShort(JsonArray, int, int, short) 1710 * @see #parseShort(JsonArray, int, int, short, Function) 1711 */ 1712 public static Short getShort( 1713 JsonArray ja, int i, int FLAGS, short defaultValue, 1714 Function<String, Short> optionalParser 1715 ) 1716 { 1717 JsonValue.ValueType t; 1718 1719 return ((i >= ja.size()) || ((t=ja.get(i).getValueType()) == NUMBER) || (t != STRING)) 1720 ? ReadBoxedJSON.getShort(ja, i, FLAGS, defaultValue) 1721 : ReadBoxedJSON.parseShort(ja, i, FLAGS, defaultValue, optionalParser); 1722 } 1723 1724 /** 1725 * <EMBED CLASS=defs DATA-TYPE=Byte DATA-PARSER='Byte.parseByte'> 1726 * <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DESC_JA> 1727 * 1728 * @param ja Any {@link JsonArray} 1729 * @param i Any index into the {@code JsonArray} 1730 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 1731 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DEFVAL> 1732 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_PARSER> 1733 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_RET_JA> 1734 * 1735 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 1736 * @throws JsonStrParseArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JSPAEX> 1737 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JNAEX> 1738 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JTAEX> 1739 * 1740 * @see #getByte(JsonArray, int, int, byte) 1741 * @see #parseByte(JsonArray, int, int, byte, Function) 1742 */ 1743 public static Byte getByte( 1744 JsonArray ja, int i, int FLAGS, byte defaultValue, 1745 Function<String, Byte> optionalParser 1746 ) 1747 { 1748 JsonValue.ValueType t; 1749 1750 return ((i >= ja.size()) || ((t=ja.get(i).getValueType()) == NUMBER) || (t != STRING)) 1751 ? ReadBoxedJSON.getByte(ja, i, FLAGS, defaultValue) 1752 : ReadBoxedJSON.parseByte(ja, i, FLAGS, defaultValue, optionalParser); 1753 } 1754 1755 /** 1756 * <EMBED CLASS=defs DATA-TYPE=Double DATA-PARSER='Double.parseDouble'> 1757 * <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DESC_JA> 1758 * 1759 * @param ja Any {@link JsonArray} 1760 * @param i Any index into the {@code JsonArray} 1761 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 1762 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DEFVAL> 1763 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_PARSER> 1764 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_RET_JA> 1765 * 1766 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 1767 * @throws JsonStrParseArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JSPAEX> 1768 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JNAEX> 1769 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JTAEX> 1770 * 1771 * @see #getDouble(JsonArray, int, int, double) 1772 * @see #parseDouble(JsonArray, int, int, double, Function) 1773 */ 1774 public static Double getDouble( 1775 JsonArray ja, int i, int FLAGS, double defaultValue, 1776 Function<String, Double> optionalParser 1777 ) 1778 { 1779 JsonValue.ValueType t; 1780 1781 return ((i >= ja.size()) || ((t=ja.get(i).getValueType()) == NUMBER) || (t != STRING)) 1782 ? ReadBoxedJSON.getDouble(ja, i, FLAGS, defaultValue) 1783 : ReadBoxedJSON.parseDouble(ja, i, FLAGS, defaultValue, optionalParser); 1784 } 1785 1786 /** 1787 * <EMBED CLASS=defs DATA-TYPE=Float DATA-PARSER='Float.parseFloat'> 1788 * <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DESC_JA> 1789 * 1790 * @param ja Any {@link JsonArray} 1791 * @param i Any index into the {@code JsonArray} 1792 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 1793 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DEFVAL> 1794 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_PARSER> 1795 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_RET_JA> 1796 * 1797 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 1798 * @throws JsonStrParseArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JSPAEX> 1799 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JNAEX> 1800 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JTAEX> 1801 * 1802 * @see #getFloat(JsonArray, int, int, float) 1803 * @see #parseFloat(JsonArray, int, int, float, Function) 1804 */ 1805 public static Float getFloat( 1806 JsonArray ja, int i, int FLAGS, float defaultValue, 1807 Function<String, Float> optionalParser 1808 ) 1809 { 1810 JsonValue.ValueType t; 1811 1812 return ((i >= ja.size()) || ((t=ja.get(i).getValueType()) == NUMBER) || (t != STRING)) 1813 ? ReadBoxedJSON.getFloat(ja, i, FLAGS, defaultValue) 1814 : ReadBoxedJSON.parseFloat(ja, i, FLAGS, defaultValue, optionalParser); 1815 } 1816 1817 /** 1818 * <EMBED CLASS=defs DATA-TYPE=Boolean DATA-PARSER='Boolean.parseBoolean'> 1819 * <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DESC_JA> 1820 * 1821 * @param ja Any {@link JsonArray} 1822 * @param i Any index into the {@code JsonArray} 1823 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 1824 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DEFVAL> 1825 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_PARSER> 1826 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_RET_JA> 1827 * 1828 * @throws IndexOutOfBoundsException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_IOOBEX> 1829 * @throws JsonStrParseArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JSPAEX> 1830 * @throws JsonNullArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JNAEX> 1831 * @throws JsonTypeArrException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JTAEX> 1832 * 1833 * @see #getBoolean(JsonArray, int, int, boolean) 1834 * @see #parseBoolean(JsonArray, int, int, boolean, Function) 1835 */ 1836 public static Boolean getBoolean( 1837 JsonArray ja, int i, int FLAGS, boolean defaultValue, 1838 Function<String, Boolean> optionalParser 1839 ) 1840 { 1841 JsonValue.ValueType t; 1842 1843 return ( (i >= ja.size()) 1844 || ((t=ja.get(i).getValueType()) == TRUE) 1845 || (t == FALSE) 1846 || (t != STRING) 1847 ) 1848 ? ReadBoxedJSON.getBoolean(ja, i, FLAGS, defaultValue) 1849 : ReadBoxedJSON.parseBoolean(ja, i, FLAGS, defaultValue, optionalParser); 1850 } 1851 1852 1853 // **************************************************************************************** 1854 // **************************************************************************************** 1855 // JsonObject Property to Number 1856 // **************************************************************************************** 1857 // **************************************************************************************** 1858 1859 1860 /** 1861 * <EMBED CLASS=defs DATA-TYPE=Integer DATA-PARSER='Integer.parseInt'> 1862 * <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DESC_JO> 1863 * 1864 * @param jo Any {@link JsonObject} 1865 * @param propertyName Any of the properties defined in the {@code JsonObject} 1866 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 1867 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DEFVAL> 1868 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_PARSER> 1869 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_RET_JO> 1870 * 1871 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 1872 * @throws JsonStrParseObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JSPOEX> 1873 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JNOEX> 1874 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JTOEX> 1875 * 1876 * @see #getInteger(JsonObject, String, int, int) 1877 * @see #parseInteger(JsonObject, String, int, int, Function) 1878 */ 1879 public static Integer getInteger( 1880 JsonObject jo, String propertyName, int FLAGS, int defaultValue, 1881 Function<String, Integer> optionalParser 1882 ) 1883 { 1884 JsonValue.ValueType t; 1885 1886 return ( (! jo.containsKey(propertyName)) 1887 || ((t = jo.get(propertyName).getValueType()) == NUMBER) 1888 || (t != STRING) 1889 ) 1890 ? ReadBoxedJSON.getInteger(jo, propertyName, FLAGS, defaultValue) 1891 : ReadBoxedJSON.parseInteger(jo, propertyName, FLAGS, defaultValue, optionalParser); 1892 } 1893 1894 /** 1895 * <EMBED CLASS=defs DATA-TYPE=Long DATA-PARSER='Long.parseLong'> 1896 * <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DESC_JO> 1897 * 1898 * @param jo Any {@link JsonObject} 1899 * @param propertyName Any of the properties defined in the {@code JsonObject} 1900 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 1901 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DEFVAL> 1902 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_PARSER> 1903 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_RET_JO> 1904 * 1905 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 1906 * @throws JsonStrParseObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JSPOEX> 1907 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JNOEX> 1908 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JTOEX> 1909 * 1910 * @see #getLong(JsonObject, String, int, long) 1911 * @see #parseLong(JsonObject, String, int, long, Function) 1912 */ 1913 public static Long getLong( 1914 JsonObject jo, String propertyName, int FLAGS, long defaultValue, 1915 Function<String, Long> optionalParser 1916 ) 1917 { 1918 JsonValue.ValueType t; 1919 1920 return ( (! jo.containsKey(propertyName)) 1921 || ((t = jo.get(propertyName).getValueType()) == NUMBER) 1922 || (t != STRING) 1923 ) 1924 ? ReadBoxedJSON.getLong(jo, propertyName, FLAGS, defaultValue) 1925 : ReadBoxedJSON.parseLong(jo, propertyName, FLAGS, defaultValue, optionalParser); 1926 } 1927 1928 /** 1929 * <EMBED CLASS=defs DATA-TYPE=Short DATA-PARSER='Short.parseShort'> 1930 * <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DESC_JO> 1931 * 1932 * @param jo Any {@link JsonObject} 1933 * @param propertyName Any of the properties defined in the {@code JsonObject} 1934 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 1935 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DEFVAL> 1936 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_PARSER> 1937 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_RET_JO> 1938 * 1939 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 1940 * @throws JsonStrParseObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JSPOEX> 1941 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JNOEX> 1942 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JTOEX> 1943 * 1944 * @see #getShort(JsonObject, String, int, short) 1945 * @see #parseShort(JsonObject, String, int, short, Function) 1946 */ 1947 public static Short getShort( 1948 JsonObject jo, String propertyName, int FLAGS, short defaultValue, 1949 Function<String, Short> optionalParser 1950 ) 1951 { 1952 JsonValue.ValueType t; 1953 1954 return ( (! jo.containsKey(propertyName)) 1955 || ((t = jo.get(propertyName).getValueType()) == NUMBER) 1956 || (t != STRING) 1957 ) 1958 ? ReadBoxedJSON.getShort(jo, propertyName, FLAGS, defaultValue) 1959 : ReadBoxedJSON.parseShort(jo, propertyName, FLAGS, defaultValue, optionalParser); 1960 } 1961 1962 /** 1963 * <EMBED CLASS=defs DATA-TYPE=Byte DATA-PARSER='Byte.parseByte'> 1964 * <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DESC_JO> 1965 * 1966 * @param jo Any {@link JsonObject} 1967 * @param propertyName Any of the properties defined in the {@code JsonObject} 1968 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 1969 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DEFVAL> 1970 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_PARSER> 1971 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_RET_JO> 1972 * 1973 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 1974 * @throws JsonStrParseObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JSPOEX> 1975 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JNOEX> 1976 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JTOEX> 1977 * 1978 * @see #getByte(JsonObject, String, int, byte) 1979 * @see #parseByte(JsonObject, String, int, byte, Function) 1980 */ 1981 public static Byte getByte( 1982 JsonObject jo, String propertyName, int FLAGS, byte defaultValue, 1983 Function<String, Byte> optionalParser 1984 ) 1985 { 1986 JsonValue.ValueType t; 1987 1988 return ( (! jo.containsKey(propertyName)) 1989 || ((t = jo.get(propertyName).getValueType()) == NUMBER) 1990 || (t != STRING) 1991 ) 1992 ? ReadBoxedJSON.getByte(jo, propertyName, FLAGS, defaultValue) 1993 : ReadBoxedJSON.parseByte(jo, propertyName, FLAGS, defaultValue, optionalParser); 1994 } 1995 1996 /** 1997 * <EMBED CLASS=defs DATA-TYPE=Double DATA-PARSER='Double.parseDouble'> 1998 * <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DESC_JO> 1999 * 2000 * @param jo Any {@link JsonObject} 2001 * @param propertyName Any of the properties defined in the {@code JsonObject} 2002 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 2003 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DEFVAL> 2004 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_PARSER> 2005 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_RET_JO> 2006 * 2007 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 2008 * @throws JsonStrParseObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JSPOEX> 2009 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JNOEX> 2010 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JTOEX> 2011 * 2012 * @see #getDouble(JsonObject, String, int, double) 2013 * @see #parseDouble(JsonObject, String, int, double, Function) 2014 */ 2015 public static Double getDouble( 2016 JsonObject jo, String propertyName, int FLAGS, double defaultValue, 2017 Function<String, Double> optionalParser 2018 ) 2019 { 2020 JsonValue.ValueType t; 2021 2022 return ( (! jo.containsKey(propertyName)) 2023 || ((t = jo.get(propertyName).getValueType()) == NUMBER) 2024 || (t != STRING) 2025 ) 2026 ? ReadBoxedJSON.getDouble(jo, propertyName, FLAGS, defaultValue) 2027 : ReadBoxedJSON.parseDouble(jo, propertyName, FLAGS, defaultValue, optionalParser); 2028 } 2029 2030 /** 2031 * <EMBED CLASS=defs DATA-TYPE=Float DATA-PARSER='Float.parseFloat'> 2032 * <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DESC_JO> 2033 * 2034 * @param jo Any {@link JsonObject} 2035 * @param propertyName Any of the properties defined in the {@code JsonObject} 2036 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 2037 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DEFVAL> 2038 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_PARSER> 2039 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_RET_JO> 2040 * 2041 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 2042 * @throws JsonStrParseObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JSPOEX> 2043 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JNOEX> 2044 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JTOEX> 2045 * 2046 * @see #getFloat(JsonObject, String, int, float) 2047 * @see #parseFloat(JsonObject, String, int, float, Function) 2048 */ 2049 public static Float getFloat( 2050 JsonObject jo, String propertyName, int FLAGS, float defaultValue, 2051 Function<String, Float> optionalParser 2052 ) 2053 { 2054 JsonValue.ValueType t; 2055 2056 return ( (! jo.containsKey(propertyName)) 2057 || ((t = jo.get(propertyName).getValueType()) == NUMBER) 2058 || (t != STRING) 2059 ) 2060 ? ReadBoxedJSON.getFloat(jo, propertyName, FLAGS, defaultValue) 2061 : ReadBoxedJSON.parseFloat(jo, propertyName, FLAGS, defaultValue, optionalParser); 2062 } 2063 2064 /** 2065 * <EMBED CLASS=defs DATA-TYPE=Boolean DATA-PARSER='Boolean.parseBoolean'> 2066 * <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DESC_JO> 2067 * 2068 * @param jo Any {@link JsonObject} 2069 * @param propertyName Any of the properties defined in the {@code JsonObject} 2070 * @param FLAGS Return-value / exception-throw constants defined in {@link JFlag} 2071 * @param defaultValue <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_DEFVAL> 2072 * @param optionalParser <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_PARSER> 2073 * @return <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_RET_JO> 2074 * 2075 * @throws JsonPropMissingException <EMBED CLASS='external-html' DATA-FILE-ID=JRF_JPMEX> 2076 * @throws JsonStrParseObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JSPOEX> 2077 * @throws JsonNullObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JNOEX> 2078 * @throws JsonTypeObjException <EMBED CLASS='external-html' DATA-FILE-ID=JRXL_JTOEX> 2079 * 2080 * @see #getBoolean(JsonObject, String, int, boolean) 2081 * @see #parseBoolean(JsonObject, String, int, boolean, Function) 2082 */ 2083 public static Boolean getBoolean( 2084 JsonObject jo, String propertyName, int FLAGS, boolean defaultValue, 2085 Function<String, Boolean> optionalParser 2086 ) 2087 { 2088 JsonValue.ValueType t; 2089 2090 return ( (! jo.containsKey(propertyName)) 2091 || ((t = jo.get(propertyName).getValueType()) == TRUE) 2092 || (t == FALSE) 2093 || (t != STRING) 2094 ) 2095 ? ReadBoxedJSON.getBoolean(jo, propertyName, FLAGS, defaultValue) 2096 : ReadBoxedJSON.parseBoolean(jo, propertyName, FLAGS, defaultValue, optionalParser); 2097 } 2098 } 2099}