Skip to content

djutils v2.1.9

Compare
Choose a tag to compare
@averbraeck averbraeck released this 30 Apr 11:20
· 347 commits to main since this release

In this version of djutils, two additions were made in djutils-base:

  • Issue #10 : Addition of a NumberParser class. Locale-dependent parsing can be quite difficult. The classes provided in Java are very strict, which means that an extra space or plus at the start of the parsed String already leads to a partially parsed String or to an exception. The new NumberParser class in djutils-base tries to address this issue. and provides many options to parse Strings to numbers (int, long, float, and double). It allows for the use of different Locales, and it can parse in a strict manner (only allowing the exact format that the Locale prescribes) or in a lenient manner (allowing for leading plus sign for the number and leading plus sign for the exponent, and allowing for the wrong case of the exponent character). Both strict and lenient parsing ignores leading and trailing whitespace. The parser also allows for trailing characters (such as units) and keeps a pointer where the first trailing character begins.
  • Addition of Mutable Primitives. Mutable Primitives These classes augment the Java primitive wrappers with mutable variants. Sometimes, we want to return one or more primitive values after a method call in addition to the return value itself. As an example, consider a parser that returns the parsed value, but also an index for the character where the parsing stopped. Often, 'ugly' constructs are used, such as providing a new int[1] {} to the method, or an AtomicInteger. Both can be written. Instead of these solutions, djutils-base contains the classes MutableInt, MutableLong, MutableFloat, MutableDouble, MutableShort, MutableByte, and MutableBoolean.

Note that the interpretation of a strictly formatted number string (related to Issue #10) can differ per Java version (!). Jdk11 uses the CLDR version 33 (see https://cldr.unicode.org/index/downloads/cldr-33) and Jdk17 uses the CLDR version 35.1 (see https://cldr.unicode.org/index/downloads/cldr-35). In the Unit tests, this means that, for instance, both the French and the Arabic NumberFormat test are different and version-dependent.