use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class TestLiteralLabels method testHashCodesForHexBinary_1.
public void testHashCodesForHexBinary_1() {
LiteralLabel A = node("'0123'http://www.w3.org/2001/XMLSchema#hexBinary").getLiteral();
LiteralLabel B = node("'0123'http://www.w3.org/2001/XMLSchema#hexBinary").getLiteral();
assertEquals(A.hashCode(), B.hashCode());
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class TestLiteralLabels method testEquality2.
public void testEquality2() {
LiteralLabel A = LiteralLabelFactory.createTypedLiteral("xyz");
LiteralLabel B = LiteralLabelFactory.createTypedLiteral("XYZ");
assertFalse(A.equals(B));
assertFalse(A.sameValueAs(B));
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class TestLiteralLabels method testEquality4.
public void testEquality4() {
LiteralLabel A = LiteralLabelFactory.create("xyz", "en-UK");
LiteralLabel B = LiteralLabelFactory.create("xyz", "en-uk");
assertFalse(A.equals(B));
assertTrue(A.sameValueAs(B));
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class NodeIdInline method inline$.
private static NodeId inline$(Node node) {
if (!hasInlineDatatype(node))
return null;
LiteralLabel lit = node.getLiteral();
if (node.getLiteralDatatype().equals(XSDDatatype.XSDdecimal)) {
// Check lexical form.
if (!XSDDatatype.XSDdecimal.isValidLiteral(lit))
return null;
// Not lit.getValue() because that may be a narrower type e.g. Integer.
// .trim is how Jena does it but it rather savage. spc, \n \r \t.
// But at this point we know it's a valid literal so the excessive
// chopping by .trim is safe.
BigDecimal decimal = new BigDecimal(lit.getLexicalForm().trim());
// Does range checking.
DecimalNode56 dn = DecimalNode56.valueOf(decimal);
// null is "does not fit"
if (dn != null)
// setType
return NodeId.createRaw(XSD_DECIMAL, dn.pack());
else
return null;
} else {
// Not decimal.
if (XSDDatatype.XSDinteger.isValidLiteral(lit)) {
// Quick check.
if (lit.getLexicalForm().length() > 19)
return null;
// Derived types.
NodeIdType type = derivedTypeMap.inverse().getOrDefault(lit.getDatatype(), NodeIdType.XSD_INTEGER);
try {
long v = ((Number) lit.getValue()).longValue();
v = IntegerNode.pack56(v);
// Value -1 is "does not fit"
if (v == -1)
return null;
return NodeId.createRaw(type, v);
}// Out of range for the type, not a long etc etc.
catch (Throwable ex) {
return null;
}
}
}
if (XSDDatatype.XSDdouble.isValidLiteral(lit)) {
double d = ((Number) lit.getValue()).doubleValue();
long v = DoubleNode62.pack(d);
if (v == DoubleNode62.NO_ENCODING)
return null;
// The special byte encoding of XSD_DOUBLE is handled in NodeIdFactory.encode/.decode.
return NodeId.createRaw(XSD_DOUBLE, v);
}
if (XSDDatatype.XSDfloat.isValidLiteral(lit)) {
float f = ((Number) lit.getValue()).floatValue();
long v = FloatNode.pack(f);
return NodeId.createRaw(XSD_FLOAT, v);
}
if (lit.getDatatype().equals(XSDDatatype.XSDdateTimeStamp) && XSDDatatype.XSDdateTimeStamp.isValidLiteral(lit)) {
long v = DateTimeNode.packDateTime(lit.getLexicalForm());
if (v == -1)
return null;
return NodeId.createRaw(XSD_DATETIMESTAMP, v);
}
if (XSDDatatype.XSDdateTime.isValidLiteral(lit)) {
// Could use the Jena/XSDDateTime object here rather than reparse the lexical form.
// But this works and it's close to a release ...
long v = DateTimeNode.packDateTime(lit.getLexicalForm());
if (v == -1)
return null;
return NodeId.createRaw(XSD_DATETIME, v);
}
if (XSDDatatype.XSDdate.isValidLiteral(lit)) {
long v = DateTimeNode.packDate(lit.getLexicalForm());
if (v == -1)
return null;
return NodeId.createRaw(XSD_DATE, v);
}
if (XSDDatatype.XSDboolean.isValidLiteral(lit)) {
long v = 0;
boolean b = (Boolean) lit.getValue();
// return new NodeValueBoolean(b, node);
if (b)
v = v | 0x01;
return NodeId.createRaw(XSD_BOOLEAN, v);
}
return null;
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class NodeFactoryExtra method nodeToInt.
/**
* Node to int
*
* @param node
* @return The int value or Integer.MIN_VALUE.
*/
public static int nodeToInt(Node node) {
LiteralLabel lit = node.getLiteral();
if (!XSDDatatype.XSDint.isValidLiteral(lit))
return Integer.MIN_VALUE;
int i = ((Number) lit.getValue()).intValue();
return i;
}
Aggregations