Skip to content

Commit

Permalink
Java: Restore original toString() formatting.
Browse files Browse the repository at this point in the history
C: Not restored, so .NET and C works in the ".0" style yet.
[wip]
  • Loading branch information
agdavydov81 committed Mar 25, 2024
1 parent cecb163 commit 3dd2021
Show file tree
Hide file tree
Showing 9 changed files with 348 additions and 146 deletions.
24 changes: 24 additions & 0 deletions java/dfp/src/main/java/com/epam/deltix/dfp/Decimal64.java
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,10 @@ public static String toScientificString(final Decimal64 decimal64) {
return null == decimal64 ? "null" : Decimal64Utils.toScientificString(decimal64.value);
}

public static String toFloatString(final Decimal64 decimal64) {
return null == decimal64 ? "null" : Decimal64Utils.toFloatString(decimal64.value);
}

public Appendable appendTo(final Appendable appendable) throws IOException {
return Decimal64Utils.appendTo(value, appendable);
}
Expand All @@ -883,6 +887,10 @@ public Appendable scientificAppendTo(final Appendable appendable) throws IOExcep
return Decimal64Utils.scientificAppendTo(value, appendable);
}

public Appendable floatAppendTo(final Appendable appendable) throws IOException {
return Decimal64Utils.floatAppendTo(value, appendable);
}

public StringBuilder appendTo(final StringBuilder builder) {
return Decimal64Utils.appendTo(value, builder);
}
Expand All @@ -891,6 +899,10 @@ public StringBuilder scientificAppendTo(final StringBuilder builder) {
return Decimal64Utils.scientificAppendTo(value, builder);
}

public StringBuilder floatAppendTo(final StringBuilder builder) {
return Decimal64Utils.floatAppendTo(value, builder);
}

public static Appendable appendTo(final Decimal64 decimal64, final Appendable appendable) throws IOException {
return null == decimal64 ? appendable.append("null") : Decimal64Utils.appendTo(decimal64.value, appendable);
}
Expand All @@ -899,6 +911,10 @@ public static Appendable scientificAppendTo(final Decimal64 decimal64, final App
return null == decimal64 ? appendable.append("null") : Decimal64Utils.scientificAppendTo(decimal64.value, appendable);
}

public static Appendable floatAppendTo(final Decimal64 decimal64, final Appendable appendable) throws IOException {
return null == decimal64 ? appendable.append("null") : Decimal64Utils.floatAppendTo(decimal64.value, appendable);
}

public static StringBuilder appendTo(final Decimal64 decimal64, final StringBuilder builder) {
return null == decimal64 ? builder.append("null") : Decimal64Utils.appendTo(decimal64.value, builder);
}
Expand All @@ -907,6 +923,10 @@ public static StringBuilder scientificAppendTo(final Decimal64 decimal64, final
return null == decimal64 ? builder.append("null") : Decimal64Utils.scientificAppendTo(decimal64.value, builder);
}

public static StringBuilder floatAppendTo(final Decimal64 decimal64, final StringBuilder builder) {
return null == decimal64 ? builder.append("null") : Decimal64Utils.floatAppendTo(decimal64.value, builder);
}

/**
* Try parse a dfp floating-point value from the given textual representation.
* <p>
Expand Down Expand Up @@ -1137,6 +1157,10 @@ public String toScientificString() {
return Decimal64Utils.toScientificString(value);
}

public String toFloatString() {
return Decimal64Utils.toFloatString(value);
}

/// endregion

/// region Number Interface Implementation
Expand Down
156 changes: 150 additions & 6 deletions java/dfp/src/main/java/com/epam/deltix/dfp/Decimal64Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ public static int hashCode(@Decimal final long value) {


public static String toString(@Decimal final long value) {
return JavaImpl.fastToString(value, DECIMAL_MARK_DEFAULT);
return JavaImpl.fastToString(value, DECIMAL_MARK_DEFAULT, false);
}

public static String toString(@Decimal final long value, final char decimalMark) {
return JavaImpl.fastToString(value, decimalMark);
return JavaImpl.fastToString(value, decimalMark, false);
}

public static String toScientificString(@Decimal final long value) {
Expand All @@ -211,6 +211,14 @@ public static String toScientificString(@Decimal final long value, final char de
return JavaImpl.fastToScientificString(value, decimalMark);
}

public static String toFloatString(@Decimal final long value) {
return JavaImpl.fastToString(value, DECIMAL_MARK_DEFAULT, true);
}

public static String toFloatString(@Decimal final long value, final char decimalMark) {
return JavaImpl.fastToString(value, decimalMark, true);
}

static String toDebugString(@Decimal final long value) {
return JavaImpl.toDebugString(value);
}
Expand Down Expand Up @@ -1249,7 +1257,7 @@ public static long canonize(@Decimal final long value) {
* @throws IOException from {@link Appendable#append(char)}
*/
public static Appendable appendTo(@Decimal final long value, final Appendable appendable) throws IOException {
return JavaImpl.fastAppendToAppendable(value, DECIMAL_MARK_DEFAULT, appendable);
return JavaImpl.fastAppendToAppendable(value, DECIMAL_MARK_DEFAULT, false, appendable);
}

/**
Expand All @@ -1264,7 +1272,7 @@ public static Appendable appendTo(@Decimal final long value, final Appendable ap
* @throws IOException from {@link Appendable#append(char)}
*/
public static Appendable appendTo(@Decimal final long value, final char decimalMark, final Appendable appendable) throws IOException {
return JavaImpl.fastAppendToAppendable(value, decimalMark, appendable);
return JavaImpl.fastAppendToAppendable(value, decimalMark, false, appendable);
}

/**
Expand Down Expand Up @@ -1325,6 +1333,63 @@ public static Appendable scientificAppendToChecked(@Decimal final long value, fi
return scientificAppendTo(value, decimalMark, appendable);
}

/**
* Append string representation of {@code DFP} {@code value} to {@link Appendable} {@code appendable}
* <p>
* Same as {@code appendable.append(value.toFloatString())}, but more efficient.
*
* @param value {@code DFP64} argument
* @param appendable {@link Appendable} instance to which the string representation of the {@code value} will be appended
* @return the 2nd argument ({@link Appendable} {@code appendable})
* @throws IOException from {@link Appendable#append(char)}
*/
public static Appendable floatAppendTo(@Decimal final long value, final Appendable appendable) throws IOException {
return JavaImpl.fastAppendToAppendable(value, DECIMAL_MARK_DEFAULT, true, appendable);
}

/**
* Append string representation of {@code DFP} {@code value} to {@link Appendable} {@code appendable}
* <p>
* Same as {@code appendable.append(value.toFloatString())}, but more efficient.
*
* @param value {@code DFP64} argument
* @param decimalMark A decimal separator used to separate the integer part from the fractional part.
* @param appendable {@link Appendable} instance to which the string representation of the {@code value} will be appended
* @return the 2nd argument ({@link Appendable} {@code appendable})
* @throws IOException from {@link Appendable#append(char)}
*/
public static Appendable floatAppendTo(@Decimal final long value, final char decimalMark, final Appendable appendable) throws IOException {
return JavaImpl.fastAppendToAppendable(value, decimalMark, true, appendable);
}

/**
* Implements {@link Decimal64#floatAppendTo(Appendable)}, adds null check; do not use directly.
*
* @param value DFP argument
* @param appendable an object, implementing Appendable interface
* @return ..
* @throws IOException from {@link Appendable#append(char)}
*/
@Deprecated
public static Appendable floatAppendToChecked(@Decimal final long value, final Appendable appendable) throws IOException {
checkNull(value);
return floatAppendTo(value, appendable);
}

/**
* Implements {@link Decimal64#floatAppendTo(Appendable)}, adds null check; do not use directly.
*
* @param value DFP argument
* @param decimalMark A decimal separator used to separate the integer part from the fractional part.
* @param appendable an object, implementing Appendable interface
* @return ..
* @throws IOException from {@link Appendable#append(char)}
*/
@Deprecated
public static Appendable floatAppendToChecked(@Decimal final long value, final char decimalMark, final Appendable appendable) throws IOException {
checkNull(value);
return floatAppendTo(value, decimalMark, appendable);
}

/**
* Append string representation of {@code DFP} value to {@link StringBuilder} {@code sb}
Expand All @@ -1336,7 +1401,7 @@ public static Appendable scientificAppendToChecked(@Decimal final long value, fi
* @return the value of 2nd argument ({@link StringBuilder} {@code sb})
*/
public static StringBuilder appendTo(@Decimal final long value, final StringBuilder sb) {
return JavaImpl.fastAppendToStringBuilder(value, DECIMAL_MARK_DEFAULT, sb);
return JavaImpl.fastAppendToStringBuilder(value, DECIMAL_MARK_DEFAULT, false, sb);
}

/**
Expand All @@ -1350,7 +1415,7 @@ public static StringBuilder appendTo(@Decimal final long value, final StringBuil
* @return the value of 2nd argument ({@link StringBuilder} {@code sb})
*/
public static StringBuilder appendTo(@Decimal final long value, final char decimalMark, final StringBuilder sb) {
return JavaImpl.fastAppendToStringBuilder(value, decimalMark, sb);
return JavaImpl.fastAppendToStringBuilder(value, decimalMark, false, sb);
}

/**
Expand Down Expand Up @@ -1407,6 +1472,60 @@ public static StringBuilder scientificAppendToChecked(@Decimal final long value,
return scientificAppendTo(value, decimalMark, sb);
}

/**
* Append string representation of {@code DFP} value to {@link StringBuilder} {@code sb}
* <p>
* Same as {@code sb.append(value.toFloatString());}, but more efficient.
*
* @param value {@code DFP64} argument
* @param sb {@link StringBuilder} instance to which the string representation of the {@code value} will be appended
* @return the value of 2nd argument ({@link StringBuilder} {@code sb})
*/
public static StringBuilder floatAppendTo(@Decimal final long value, final StringBuilder sb) {
return JavaImpl.fastAppendToStringBuilder(value, DECIMAL_MARK_DEFAULT, true, sb);
}

/**
* Append string representation of {@code DFP} value to {@link StringBuilder} {@code sb}
* <p>
* Same as {@code sb.append(value.toFloatString());}, but more efficient.
*
* @param value {@code DFP64} argument
* @param decimalMark A decimal separator used to separate the integer part from the fractional part.
* @param sb {@link StringBuilder} instance to which the string representation of the {@code value} will be appended
* @return the value of 2nd argument ({@link StringBuilder} {@code sb})
*/
public static StringBuilder floatAppendTo(@Decimal final long value, final char decimalMark, final StringBuilder sb) {
return JavaImpl.fastAppendToStringBuilder(value, decimalMark, true, sb);
}

/**
* Implements {@link Decimal64#floatAppendTo(StringBuilder)}, adds null check; do not use directly.
*
* @param value DFP argument
* @param sb {@link StringBuilder} instance to which the string representation of the {@code value} will be appended
* @return ..
*/
@Deprecated
public static StringBuilder floatAppendToChecked(@Decimal final long value, final StringBuilder sb) {
checkNull(value);
return floatAppendTo(value, sb);
}

/**
* Implements {@link Decimal64#floatAppendTo(StringBuilder)}, adds null check; do not use directly.
*
* @param value DFP argument
* @param decimalMark A decimal separator used to separate the integer part from the fractional part.
* @param sb {@link StringBuilder} instance to which the string representation of the {@code value} will be appended
* @return ..
*/
@Deprecated
public static StringBuilder floatAppendToChecked(@Decimal final long value, final char decimalMark, final StringBuilder sb) {
checkNull(value);
return floatAppendTo(value, decimalMark, sb);
}

/**
* Try parse a dfp floating-point value from the given textual representation.
* <p>
Expand Down Expand Up @@ -2676,6 +2795,31 @@ public static String toScientificStringChecked(@Decimal final long value, final
return toScientificString(value, decimalMark);
}

/**
* Implements {@link Decimal64#toFloatString()}, adds null checks; do not use directly.
*
* @param value DFP argument
* @return ..
*/
@Deprecated
public static String toFloatStringChecked(@Decimal final long value) {
checkNull(value);
return toFloatString(value);
}

/**
* Implements {@link Decimal64#toFloatString()}, adds null checks; do not use directly.
*
* @param value DFP argument
* @param decimalMark A decimal separator used to separate the integer part from the fractional part.
* @return ..
*/
@Deprecated
public static String toFloatStringChecked(@Decimal final long value, final char decimalMark) {
checkNull(value);
return toFloatString(value, decimalMark);
}

/**
* Implements {@link Decimal64#equals(Decimal64)}, adds null checks; do not use directly.
*
Expand Down
Loading

0 comments on commit 3dd2021

Please sign in to comment.