Skip to content

Commit

Permalink
Rename LenientDoubleParser to ConfigurableDoubleParser.
Browse files Browse the repository at this point in the history
Add javadoc comments.
  • Loading branch information
wrandelshofer committed Oct 13, 2024
1 parent 81c870a commit f856d02
Show file tree
Hide file tree
Showing 22 changed files with 560 additions and 203 deletions.
2 changes: 1 addition & 1 deletion deployment/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ can upload to the nexus repository manager.

```shell
cp ../fastdoubleparser/target/*.jar .
cp ../fastdoubleparser-java21/target/*javadoc.jar fastdoubleparser-1.0.1-javadoc.jar
cp ../fastdoubleparser-java23/target/*javadoc.jar fastdoubleparser-1.0.1-javadoc.jar
rm -rf META-INF
mkdir META-INF
cp ../LICENSE META-INF
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)AbstractLenientFloatingPointBitsFromCharArray.java
* @(#)AbstractConfigurableFloatingPointBitsFromCharArray.java
* Copyright © 2024 Werner Randelshofer, Switzerland. MIT License.
*/
package ch.randelshofer.fastdoubleparser;
Expand All @@ -8,9 +8,9 @@
import java.util.Set;

/**
* Lenient floating point parser.
* Formattable floating point parser.
*/
abstract class AbstractLenientFloatingPointBitsFromCharArray extends AbstractFloatValueParser {
abstract class AbstractConfigurableFloatingPointBitsFromCharArray extends AbstractFloatValueParser {
private final char zeroChar;
private final CharSet minusSignChar;
private final CharSet plusSignChar;
Expand All @@ -22,7 +22,7 @@ abstract class AbstractLenientFloatingPointBitsFromCharArray extends AbstractFlo
private final CharSet exponentSeparatorChar;
private final CharTrie exponentSeparatorTrie;

public AbstractLenientFloatingPointBitsFromCharArray(NumberFormatSymbols symbols) {
public AbstractConfigurableFloatingPointBitsFromCharArray(NumberFormatSymbols symbols) {
this.decimalSeparator = CharSet.copyOf(symbols.decimalSeparator());
this.groupingSeparator = CharSet.copyOf(symbols.groupingSeparator());
this.zeroChar = symbols.zeroDigit();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)AbstractLenientFloatingPointBitsFromCharSequence.java
* @(#)AbstractConfigurableFloatingPointBitsFromCharSequence.java
* Copyright © 2024 Werner Randelshofer, Switzerland. MIT License.
*/
package ch.randelshofer.fastdoubleparser;
Expand All @@ -8,9 +8,9 @@
import java.util.Set;

/**
* Lenient floating point parser.
* Formattable floating point parser.
*/
abstract class AbstractLenientFloatingPointBitsFromCharSequence extends AbstractFloatValueParser {
abstract class AbstractConfigurableFloatingPointBitsFromCharSequence extends AbstractFloatValueParser {
private final char zeroChar;
private final CharSet minusSignChar;
private final CharSet plusSignChar;
Expand All @@ -22,7 +22,7 @@ abstract class AbstractLenientFloatingPointBitsFromCharSequence extends Abstract
private final CharSet exponentSeparatorChar;
private final CharTrie exponentSeparatorTrie;

public AbstractLenientFloatingPointBitsFromCharSequence(NumberFormatSymbols symbols) {
public AbstractConfigurableFloatingPointBitsFromCharSequence(NumberFormatSymbols symbols) {
this.decimalSeparator = CharSet.copyOf(symbols.decimalSeparator());
this.groupingSeparator = CharSet.copyOf(symbols.groupingSeparator());
this.zeroChar = symbols.zeroDigit();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
/*
* @(#)CharSetOfOne.java
* @(#)CharSetOfNone.java
* Copyright © 2024 Werner Randelshofer, Switzerland. MIT License.
*/
package ch.randelshofer.fastdoubleparser;

import java.util.Set;
class CharSetOfNone implements CharSet {

public class CharSetOfNone implements CharSet {

public CharSetOfNone() {
CharSetOfNone() {
}

public boolean contains(char ch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import java.util.Set;

public class CharSetOfOne implements CharSet {
class CharSetOfOne implements CharSet {
private final char ch;

public CharSetOfOne(Set<Character> set) {
CharSetOfOne(Set<Character> set) {
if (set.size() != 1) throw new IllegalArgumentException("set size must be 1, size=" + set.size());
this.ch = set.iterator().next();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import java.util.Set;

public interface CharTrie {
interface CharTrie {
/**
* Searches for the longest matching string in the trie
* that matches the provided string.
Expand Down Expand Up @@ -35,6 +35,8 @@ default int match(char[] str) {
* that matches the provided string.
*
* @param str a string
* @param startIndex start index (inclusive)
* @param endIndex end index (exclusive)
* @return the length of the longest matching string, or 0 if no string matches
*/
int match(CharSequence str, int startIndex, int endIndex);
Expand All @@ -44,6 +46,8 @@ default int match(char[] str) {
* that matches the provided string.
*
* @param str a string
* @param startIndex start index (inclusive)
* @param endIndex end index (exclusive)
* @return the length of the longest matching string, or 0 if no string matches
*/
int match(char[] str, int startIndex, int endIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
package ch.randelshofer.fastdoubleparser;

public class CharTrieOfNone implements CharTrie {
class CharTrieOfNone implements CharTrie {
@Override
public int match(CharSequence str) {
return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* @(#)CharTrieOfNone.java
* @(#)CharTrieOfOne.java
* Copyright © 2024 Werner Randelshofer, Switzerland. MIT License.
*/
package ch.randelshofer.fastdoubleparser;

import java.util.Set;

public class CharTrieOfOne implements CharTrie {
class CharTrieOfOne implements CharTrie {
private final char[] chars;

public CharTrieOfOne(Set<String> set) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
* @(#)LenientDoubleBitsFromCharArray.java
* @(#)ConfigurableDoubleBitsFromCharArray.java
* Copyright © 2024 Werner Randelshofer, Switzerland. MIT License.
*/
package ch.randelshofer.fastdoubleparser;

/**
* Parses a {@code double} from a {@link char[]}.
* Parses a {@code double} from a {@code char[]} with configurable {@link NumberFormatSymbols}.
*/
final class LenientDoubleBitsFromCharArray extends AbstractLenientFloatingPointBitsFromCharArray {
final class ConfigurableDoubleBitsFromCharArray extends AbstractConfigurableFloatingPointBitsFromCharArray {
/**
* Creates a new instance.
*/
public LenientDoubleBitsFromCharArray(NumberFormatSymbols symbols) {
public ConfigurableDoubleBitsFromCharArray(NumberFormatSymbols symbols) {
super(symbols);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
* @(#)LenientDoubleBitsFromCharSequence.java
* @(#)ConfigurableDoubleBitsFromCharSequence.java
* Copyright © 2024 Werner Randelshofer, Switzerland. MIT License.
*/
package ch.randelshofer.fastdoubleparser;

/**
* Parses a {@code double} from a {@link CharSequence}.
* Parses a {@code double} from a {@link CharSequence} with configurable {@link NumberFormatSymbols}.
*/
final class LenientDoubleBitsFromCharSequence extends AbstractLenientFloatingPointBitsFromCharSequence {
final class ConfigurableDoubleBitsFromCharSequence extends AbstractConfigurableFloatingPointBitsFromCharSequence {
/**
* Creates a new instance.
*/
public LenientDoubleBitsFromCharSequence(NumberFormatSymbols symbols) {
public ConfigurableDoubleBitsFromCharSequence(NumberFormatSymbols symbols) {
super(symbols);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/*
* @(#)ConfigurableDoubleParser.java
* Copyright © 2024 Werner Randelshofer, Switzerland. MIT License.
*/
package ch.randelshofer.fastdoubleparser;

import java.text.DecimalFormatSymbols;

/**
* Parses a floating point value with configurable {@link NumberFormatSymbols}.
* <p>
* <b>Syntax</b>
* <p>
* Leading {@link Character#FORMAT} characters in the string are ignored.
* <blockquote>
* <dl>
* <dt><i>FloatingPointLiteral:</i></dt>
* <dd><i>[Sign] NaN</i></dd>
* <dd><i>[Sign] Infinity</i></dd>
* <dd><i>[Sign] DecimalFloatingPointLiteral</i></dd>
* </dl>
*
* <dl>
* <dt><i>DecimalFloatingPointLiteral:</i>
* <dd><i>DecSignificand [DecExponent]</i>
* </dl>
*
* <dl>
* <dt><i>DecSignificand:</i>
* <dd><i>IntegerPart DecimalSeparator [FractionPart]</i>
* <dd><i>DecimalSeparator FractionPart</i>
* <dd><i>IntegerPart</i>
* </dl>
*
* <dl>
* <dt><i>IntegerPart:</i>
* <dd><i>GroupedDigits</i>
* </dl>
*
* <dl>
* <dt><i>FractionPart:</i>
* <dd><i>Digits</i>
* </dl>
*
* <dl>
* <dt><i>DecimalSeparator:</i>
* <dd><i>(one of {@link NumberFormatSymbols#decimalSeparator()})</i>
* </dl>
*
* <dl>
* <dt><i>DecExponent:</i>
* <dd><i>ExponentIndicator [Sign] Digits</i>
* </dl>
*
* <dl>
* <dt><i>ExponentIndicator:</i>
* <dd><i>(one of {@link NumberFormatSymbols#exponentSeparator()})</i>
* </dl>
*
* <dl>
* <dt><i>Sign:</i>
* <dd><i>(one of {@link NumberFormatSymbols#minusSign()})</i>
* <dd><i>(one of {@link NumberFormatSymbols#plusSign()})</i>
* </dl>
*
* <dl>
* <dt><i>Digits:</i>
* <dd><i>Digit {Digit}</i>
* </dl>
*
* <dl>
* <dt><i>GroupedDigits:</i>
* <dd><i>DigitOrGrouping {DigitOrGrouping}</i>
* </dl>
*
* <dl>
* <dt><i>DigitOrGrouping:</i>
* <dd><i>Digit</i>
* <dd><i>Grouping</i>
* </dl>
*
* <dl>
* <dt><i>Digit:</i>
* <dd><i>(one of digits 0 through 9 starting with {@link NumberFormatSymbols#zeroDigit()})</i>
* </dl>
*
* <dl>
* <dt><i>Sign:</i>
* <dd><i>(one of {@link NumberFormatSymbols#groupingSeparator()})</i>
* </dl>
*
* <dl>
* <dt><i>NaN:</i>
* <dd><i>(one of {@link NumberFormatSymbols#nan()})</i>
* </dl>
*
* <dl>
* <dt><i>Infinity:</i>
* <dd><i>(one of {@link NumberFormatSymbols#infinity()})</i>
* </dl>
* </blockquote>
* Maximal input length supported by this parser:
* <ul>
* <li>{@code FloatingPointLiteral} with leading {@link Character#FORMAT} characters:
* {@link Integer#MAX_VALUE} - 4 = 2,147,483,643 characters.</li>
* </ul>
*/
public class ConfigurableDoubleParser {
private final NumberFormatSymbols symbols;
private ConfigurableDoubleBitsFromCharSequence charSequenceParser;
private ConfigurableDoubleBitsFromCharArray charArrayParser;

/**
* Creates a new instance with the specified number format symbols.
*
* @param symbols the number format symbols
*/
public ConfigurableDoubleParser(NumberFormatSymbols symbols) {
this.symbols = symbols;
}

/**
* Creates a new instance with number format symbols derived
* from the specified symbols by calling
* {@link NumberFormatSymbols#fromDecimalFormatSymbols(DecimalFormatSymbols)}.
*
* @param symbols the decimal format symbols
*/
public ConfigurableDoubleParser(DecimalFormatSymbols symbols) {
this(NumberFormatSymbols.fromDecimalFormatSymbols(symbols));
}

/**
* Creates a new instance with {@link NumberFormatSymbols#fromDefault()}.
*/
public ConfigurableDoubleParser() {
this(NumberFormatSymbols.fromDefault());
}

private ConfigurableDoubleBitsFromCharArray getCharArrayParser() {
if (charArrayParser == null) {
this.charArrayParser = new ConfigurableDoubleBitsFromCharArray(symbols);
}
return charArrayParser;
}

private ConfigurableDoubleBitsFromCharSequence getCharSequenceParser() {
if (charSequenceParser == null) {
this.charSequenceParser = new ConfigurableDoubleBitsFromCharSequence(symbols);
}
return charSequenceParser;
}

/**
* Parses a double value from the specified char sequence.
*
* @param str a char sequence
* @return a double value
* @throws NumberFormatException if the provided char sequence could not be parsed
*/
public double parseDouble(CharSequence str) {
return Double.longBitsToDouble(getCharSequenceParser().parseFloatingPointLiteral(str, 0, str.length()));
}

/**
* Parses a double value from a substring of the specified char sequence.
*
* @param str a char sequence
* @param offset the start offset
* @param length the length
* @throws NumberFormatException if the provided char sequence could not be parsed
*/
public double parseDouble(CharSequence str, int offset, int length) {
return Double.longBitsToDouble(getCharSequenceParser().parseFloatingPointLiteral(str, offset, length));
}

/**
* Parses a double value from the specified char array.
*
* @param str a char array
* @return a double value
* @throws NumberFormatException if the provided char array could not be parsed
*/
public double parseDouble(char[] str) {
return Double.longBitsToDouble(getCharArrayParser().parseFloatingPointLiteral(str, 0, str.length));
}

/**
* Parses a double value from a substring of the specified char array.
*
* @param str a char array
* @param offset the start offset
* @param length the length
* @throws NumberFormatException if the provided char array could not be parsed
*/
public double parseDouble(char[] str, int offset, int length) {
return Double.longBitsToDouble(getCharArrayParser().parseFloatingPointLiteral(str, offset, length));
}
}
Loading

0 comments on commit f856d02

Please sign in to comment.