public abstract class AbstractBackend<Node> extends Object implements NodeBackend<Node>
**Value(Node node)
methods other than stringValue(Object)
.
This allows to implement RDFBackend
s without dealing with the actual
conversions needed for types literals not directly supported by a backend.
Backends however should implement - override default implementations provided
by this class - **Value(Node node)
methods with natively supported
types to avoid unnecessary type conversions.
An Example for a RDFRepository<Object> that directly uses the the
Java types for typed literals as nodes.
Here an other possible implementation that does not assume that the node is
of the requested type.
public Double doubleValue(Object node) {
//assume that this is typically only called on Double values
try {
return (Double)node;
} catch (ClassCastException e){
//not a Double - call super to trigger parsing from
//the lexical form.
return super.doubleValue(node);
}
It will depend on the use cases what of the two implementations performs
better.
public Double doubleValue(Object node) {
if(node instanceof Double){
return (Double)node;
} else {
//not a Double - call super to trigger parsing from
//the lexical form.
return super.doubleValue(node);
}
Constructor and Description |
---|
AbstractBackend() |
Modifier and Type | Method and Description |
---|---|
Boolean |
booleanValue(Node node)
Parses the boolean value from the
lexical form . |
Date |
dateTimeValue(Node node)
Parses dateTime value based on the
lexical form
of the parsed node. |
Date |
dateValue(Node node)
Parses date vales based on the ISO8601 specification by using the
lexical form of the parsed node. |
BigDecimal |
decimalValue(Node node)
Parses the
BigDecimal value from the lexical form of the parsed
node as returned by NodeBackend.stringValue(Object) . |
Double |
doubleValue(Node node)
Parses the Double value of the parsed node based on its lexical form as
returned by
stringValue(Object) . |
Float |
floatValue(Node node)
Parses the Float value of the parsed node based on its lexical form as
returned by
stringValue(Object) . |
BigInteger |
integerValue(Node node)
Parses the
BugIneger value of the parsed
node by using decimalValue(Object) . |
Integer |
intValue(Node node)
Parses the
Integer value of the parsed
node by using decimalValue(Object) . |
Long |
longValue(Node node)
Parses the
Long value of the parsed
node by using decimalValue(Object) . |
protected Date |
parseDate(String dateString)
Utility to parse xsd:date strings
|
protected Date |
parseTime(String timeString)
Utility to parse xsd:time strings
|
abstract String |
stringValue(Node node)
Return the lexial representation of a node.
|
Date |
timeValue(Node node)
Parses time value based on the ISO8601 specification by using the
lexical form of the parsed node. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createLiteral, createLiteral, createURI, getLiteralLanguage, getLiteralType, isBlank, isLiteral, isURI
public Double doubleValue(Node node)
stringValue(Object)
.doubleValue
in interface NodeBackend<Node>
node
- the literal node for which to return the double valueNumberFormatException
- if the lexical form can not be converted
to a Double.NodeBackend.doubleValue(java.lang.Object)
public Float floatValue(Node node)
stringValue(Object)
.floatValue
in interface NodeBackend<Node>
node
- the literal node for which to return the float valueNumberFormatException
- if the lexical form can not be converted
to a Double.NodeBackend.floatValue(java.lang.Object)
public Long longValue(Node node)
Long value
of the parsed
node by using decimalValue(Object)
. This has the advantage, that
decimal values that are also valid long values - such as '1.0' are also
correctly converted to long.longValue
in interface NodeBackend<Node>
node
- the literal node for which to return the long valueNumberFormatException
- if the lexical form can not be converted
to an Long.ArithmeticException
- if the lexical form can not be converted
to a Long.NodeBackend.longValue(java.lang.Object)
public Integer intValue(Node node)
Integer value
of the parsed
node by using decimalValue(Object)
. This has the advantage, that
decimal values that are also valid integer values - such as '1.0' are also
correctly converted to Integer
.intValue
in interface NodeBackend<Node>
node
- the literal node for which to return the Integer (xsd:int) valueNumberFormatException
- if the lexical form can not be converted
to an Long.ArithmeticException
- if the lexical form can not be converted
to a Long.NodeBackend.intValue(java.lang.Object)
public BigDecimal decimalValue(Node node)
BigDecimal
value from the lexical form of the parsed
node as returned by NodeBackend.stringValue(Object)
. This
trims loading '+' sings.decimalValue
in interface NodeBackend<Node>
node
- the literal node for which to return the xsd:decimal valueNumberFormatException
- if the lexical form can not be converted
to an Long.ArithmeticException
- if the lexical form can not be converted
to a Long.NodeBackend.decimalValue(java.lang.Object)
public BigInteger integerValue(Node node)
BugIneger value
of the parsed
node by using decimalValue(Object)
. This has the advantage, that
decimal values that are also valid integer values - such as '1.0' are also
correctly converted to BigInteger
.integerValue
in interface NodeBackend<Node>
node
- the literal node for which to return the xsd:integer
valueNodeBackend.integerValue(java.lang.Object)
public Boolean booleanValue(Node node)
lexical form
.
Supports both '1' and Boolean.parseBoolean(String)
.booleanValue
in interface NodeBackend<Node>
node
- the literal node for which to return the boolean valueNodeBackend.booleanValue(java.lang.Object)
public Date dateValue(Node node)
lexical form
of the parsed node.dateValue
in interface NodeBackend<Node>
node
- the literal node for which to return the date valueDate
representing the parsed date.IllegalArgumentException
- on any ParseException
while
parsing the lexical form
of the parsed
node.NodeBackend.dateValue(java.lang.Object)
public Date timeValue(Node node)
lexical form
of the parsed node.timeValue
in interface NodeBackend<Node>
node
- the literal node for which to return the time valueDate
representing the parsed date.IllegalArgumentException
- on any ParseException
while
parsing the lexical form
of the parsed
node.NodeBackend.timeValue(java.lang.Object)
public Date dateTimeValue(Node node)
lexical form
of the parsed node. For details about parsing see
FormatUtils.parseDate(String)
.dateTimeValue
in interface NodeBackend<Node>
node
- the literal node for which to return the dateTime valueDate
representing the parsed date.IllegalArgumentException
- if the parsed node can not be converted
to an Date
.NodeBackend.dateTimeValue(java.lang.Object)
public abstract String stringValue(Node node)
NodeBackend
stringValue
in interface NodeBackend<Node>
protected Date parseDate(String dateString) throws ParseException
dateString
- ParseException
protected Date parseTime(String timeString) throws ParseException
timeString
- ParseException
Copyright © 2012–2018 The Apache Software Foundation. All rights reserved.