Skip to content

Commit

Permalink
Rename skipDoubleFormatting to enableDoubleFormatting
Browse files Browse the repository at this point in the history
  • Loading branch information
fkleedorfer committed Sep 16, 2024
1 parent 1cc463a commit b1f6bb0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ One of `LATIN1`, `UTF_16_BE`, `UTF_16_LE`, `UTF_8`, `UTF_8_BOM`
</td>
<td>

A [NumberFormat](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/text/NumberFormat.html) that describes how `xsd:double` literals are formatted
A [NumberFormat](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/text/NumberFormat.html) that describes how `xsd:double` literals are formatted if `enableDoubleFormatting` is `true`.

</td>
<td>
Expand All @@ -314,12 +314,12 @@ A [NumberFormat](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/ja
<tr>
<td>

`skipDoubleFormatting`
`enableDoubleFormatting`

</td>
<td>

Allows for suppressing double formatting
Enables formatting of `xsd:double` values (see `doubleFormat` option)

</td>
<td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class FormattingStyle {
public NumberFormat doubleFormat = new DecimalFormat("0.####E0" , DecimalFormatSymbols.getInstance(Locale.US));

@Builder.Default
public boolean skipDoubleFormatting = true;
public boolean enableDoubleFormatting = false;

@Builder.Default
public EndOfLineStyle endOfLine = EndOfLineStyle.LF;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,12 @@ private State writeUriResource( final Resource resource, final State state ) {

private State writeLiteral( final Literal literal, final State state ) {
String datatypeUri = literal.getDatatypeURI();
if (style.skipDoubleFormatting && datatypeUri.equals(XSD.xdouble.getURI())){
if (datatypeUri.equals(XSD.xdouble.getURI())) {
if (style.enableDoubleFormatting){
return state.write(style.doubleFormat.format(literal.getDouble()));
} else {
return state.write(literal.getLexicalForm());
}
} else {
if (datatypeUri.equals(XSD.xboolean.getURI())) {
return state.write(literal.getBoolean() ? "true" : "false");
Expand All @@ -641,9 +645,6 @@ private State writeLiteral( final Literal literal, final State state ) {
if (datatypeUri.equals(XSD.integer.getURI())) {
return state.write(literal.getValue().toString());
}
if (datatypeUri.equals(XSD.xdouble.getURI())) {
return state.write(style.doubleFormat.format(literal.getDouble()));
}
if (datatypeUri.equals(RDF.langString.getURI())) {
return state.write(quoteAndEscape(literal) + "@" + literal.getLanguage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.Statement;
import org.apache.jena.rdf.model.impl.PropertyImpl;
import org.apache.jena.vocabulary.RDF;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -1020,23 +1019,23 @@ void testBlankNodeTriangleWithBlankNodeTriple(){
}

@Test
public void testSkipFormattingValueOfPredicate() {
public void testEnableDoubleFormatting() {
final String modelString = """
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix ex: <http://example.com/ns#> .
ex:something ex:decimalProp 0.0000000006241509074460762607776240980930446 ;
ex:doubleProp 6.241509074460762607776240980930446E-10 .""";

final FormattingStyle style = FormattingStyle.builder().skipDoubleFormatting(true).build();
final FormattingStyle style = FormattingStyle.builder().enableDoubleFormatting(false).build();

final TurtleFormatter formatter = new TurtleFormatter( style );
final String result = formatter.applyToContent( modelString );
assertThat(result.trim()).isEqualTo(modelString);
}

@Test
public void testDoubleFormatDefault() {
public void testDoubleFormattingDefault() {
final String modelString = """
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix ex: <http://example.com/ns#> .
Expand All @@ -1052,15 +1051,15 @@ public void testDoubleFormatDefault() {
}

@Test
public void testDoubleFormat() {
public void testDisableDoubleFormatting() {
final String modelString = """
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix ex: <http://example.com/ns#> .
ex:something ex:decimalProp 0.0000000006241509074460762607776240980930446 ;
ex:doubleProp 6.2415E-10 .""";

final FormattingStyle style = FormattingStyle.builder().skipDoubleFormatting(false).build();
final FormattingStyle style = FormattingStyle.builder().enableDoubleFormatting(true).build();

final TurtleFormatter formatter = new TurtleFormatter( style );
final String result = formatter.applyToContent( modelString );
Expand Down

0 comments on commit b1f6bb0

Please sign in to comment.