-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from kbss-cvut/development
[0.15.1] Release
- Loading branch information
Showing
29 changed files
with
594 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/cz/cvut/kbss/jsonld/serialization/serializer/compact/NumberSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cz.cvut.kbss.jsonld.serialization.serializer.compact; | ||
|
||
import cz.cvut.kbss.jopa.vocabulary.XSD; | ||
import cz.cvut.kbss.jsonld.serialization.model.JsonNode; | ||
import cz.cvut.kbss.jsonld.serialization.serializer.SerializerUtils; | ||
import cz.cvut.kbss.jsonld.serialization.serializer.ValueSerializer; | ||
import cz.cvut.kbss.jsonld.serialization.traversal.SerializationContext; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Serializes numeric values. | ||
*/ | ||
public class NumberSerializer implements ValueSerializer<Number> { | ||
|
||
@Override | ||
public JsonNode serialize(Number value, SerializationContext<Number> ctx) { | ||
Objects.requireNonNull(value); | ||
return SerializerUtils.createdTypedValueNode(ctx.getTerm(), value, getDatatype(value)); | ||
} | ||
|
||
protected String getDatatype(Number value) { | ||
if (value instanceof Integer) { | ||
return XSD.INT; | ||
} else if (value instanceof Long) { | ||
return XSD.LONG; | ||
} else if (value instanceof Double) { | ||
return XSD.DOUBLE; | ||
} else if (value instanceof Float) { | ||
return XSD.FLOAT; | ||
} else if (value instanceof Short) { | ||
return XSD.SHORT; | ||
} else if (value instanceof BigInteger) { | ||
return XSD.INTEGER; | ||
} else if (value instanceof BigDecimal) { | ||
return XSD.DECIMAL; | ||
} else { | ||
throw new IllegalArgumentException("Unsupported numeric literal type " + value.getClass()); | ||
} | ||
} | ||
|
||
/** | ||
* Gets a list of Java types supported by this serializer. | ||
* | ||
* @return List of Java classes | ||
*/ | ||
public static List<Class<? extends Number>> getSupportedTypes() { | ||
return List.of(Integer.class, Long.class, Double.class, Float.class, Short.class, BigInteger.class, | ||
BigDecimal.class); | ||
} | ||
} |
Oops, something went wrong.