Skip to content

Commit

Permalink
Support BigDecimal and BigInteger in SesameUtils.
Browse files Browse the repository at this point in the history
  • Loading branch information
ledsoft committed Jan 10, 2022
1 parent 3d71109 commit 1c3f972
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.eclipse.rdf4j.model.vocabulary.XSD;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;

/**
Expand Down Expand Up @@ -113,6 +115,10 @@ public static Literal createLiteral(Object value, String language, ValueFactory
return vf.createLiteral((Double) value);
} else if (value instanceof Long) {
return vf.createLiteral((Long) value);
} else if (value instanceof BigInteger) {
return vf.createLiteral((BigInteger) value);
} else if (value instanceof BigDecimal) {
return vf.createLiteral((BigDecimal) value);
} else if (value instanceof Date) {
return vf.createLiteral((Date) value);
} else if (value.getClass().isEnum()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import org.eclipse.rdf4j.model.vocabulary.XSD;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.math.BigInteger;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -145,4 +148,20 @@ void getLiteralValueReturnsOntoDriverLiteralForUnsupportedDatatype() {
assertEquals(literal.getLabel(), literalResult.getLexicalForm());
assertEquals(literal.getDatatype().stringValue(), literalResult.getDatatype());
}

@Test
void createLiteralReturnsXsdIntegerForBigInteger() {
final BigInteger value = BigInteger.valueOf(System.currentTimeMillis());
final Literal result = SesameUtils.createLiteral(value, null, vf);
assertEquals(value.toString(), result.getLabel());
assertEquals(XSD.INTEGER, result.getDatatype());
}

@Test
void createLiteralReturnsXsdDecimalForBigDecimal() {
final BigDecimal value = BigDecimal.valueOf(Math.PI);
final Literal result = SesameUtils.createLiteral(value, null, vf);
assertEquals(value.toString(), result.getLabel());
assertEquals(XSD.DECIMAL, result.getDatatype());
}
}

0 comments on commit 1c3f972

Please sign in to comment.