use of org.apache.jena.tdb2.store.NodeIdType in project jena by apache.
the class NodeIdFactory method create.
private static NodeId create(int v1, long v2) {
if (!BitsInt.isSet(v1, 32))
return createPtrLong(v1, v2);
int t = v1 >> 24;
NodeIdType type = NodeIdType.intToEnum(t);
if (type == NodeIdType.SPECIAL)
throw new TDBException(String.format("Attempt to create a special from a long: 0x%016", v2));
return createNew(type, 0, v2);
}
use of org.apache.jena.tdb2.store.NodeIdType in project jena by apache.
the class NodeIdFactory method create64.
// ---- Create from binary.
// 64 bit create
private static NodeId create64(long value2) {
if (!BitsLong.isSet(value2, 63))
return createPtr(value2);
// Inline.
long v2 = value2;
if (BitsLong.isSet(v2, 62)) {
// XSD_DOUBLE
v2 = DoubleNode62.removeType(v2);
return NodeId.createRaw(NodeIdType.XSD_DOUBLE, v2);
}
// 7 bits
int t = (int) BitsLong.unpack(v2, 56, 63);
v2 = BitsLong.clear(v2, 56, 64);
NodeIdType type = NodeIdType.intToEnum(t);
if (type == NodeIdType.SPECIAL)
throw new TDBException(String.format("Attempt to create a special from a long: 0x%016", v2));
return NodeId.createRaw(type, v2);
}
use of org.apache.jena.tdb2.store.NodeIdType 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;
}
Aggregations