use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class Rational method testDateTime_9.
public void testDateTime_9() {
// Years before 1000 : xsd:dateTime requires at least a four digit year.
// GregorianCalendar does not handle negative years. (.get(YEAR) triggers
// complete() which changes -77 into 78 (Java8)).
int[] years = { 0, 7, 77, 777, 7777 };
for (int y : years) {
Calendar calM1 = Calendar.getInstance();
calM1.set(Calendar.YEAR, y);
calM1.set(Calendar.MONTH, 10);
calM1.set(Calendar.DATE, 23);
XSDDateTime xdtM = new XSDDateTime(calM1);
LiteralLabel xdtM_ll = LiteralLabelFactory.createByValue(xdtM, "", XSDDatatype.XSDdateTime);
assertTrue("Pre-1000 calendar value", xdtM_ll.isWellFormed());
assertTrue("Pre-1000 calendar value", xdtM_ll.getLexicalForm().matches("^[0-9]{4}-.*"));
}
// Illegal dateTimes
boolean ok = false;
boolean old = JenaParameters.enableEagerLiteralValidation;
try {
JenaParameters.enableEagerLiteralValidation = true;
Literal l1 = m.createTypedLiteral(new Date(12345656l), XSDDatatype.XSDdateTime);
} catch (DatatypeFormatException e) {
ok = true;
} finally {
JenaParameters.enableEagerLiteralValidation = old;
}
assertTrue("Early detection of invalid literals", ok);
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class TestTriple method testTripleEquals.
public void testTripleEquals() {
// create some nodes to test
BlankNodeId id = BlankNodeId.create();
LiteralLabel L2 = LiteralLabelFactory.create(id.toString(), "", false);
String U2 = id.toString();
String N2 = id.toString();
Node[] nodes = new Node[] { Node.ANY, NodeFactory.createBlankNode(id), NodeFactory.createBlankNode(), NodeFactory.createLiteral(L), NodeFactory.createLiteral(L2), NodeFactory.createURI(U), NodeFactory.createURI(U2), NodeFactory.createVariable(N), NodeFactory.createVariable(N2) };
Triple[] triples = new Triple[nodes.length * nodes.length * nodes.length];
for (int i = 0; i < nodes.length; i++) {
for (int j = 0; j < nodes.length; j++) {
for (int k = 0; k < nodes.length; k++) {
triples[i * nodes.length * nodes.length + j * nodes.length + k] = new Triple(nodes[i], nodes[j], nodes[k]);
}
}
}
// set up the expected results matrix
// a expected[i][j] is true if triples[i] equals triples[j]
// triples are expected to be equals if there components are equal
boolean[][] expected = new boolean[triples.length][triples.length];
for (int i1 = 0; i1 < nodes.length; i1++) {
for (int j1 = 0; j1 < nodes.length; j1++) {
for (int k1 = 0; k1 < nodes.length; k1++) {
for (int i2 = 0; i2 < nodes.length; i2++) {
for (int j2 = 0; j2 < nodes.length; j2++) {
for (int k2 = 0; k2 < nodes.length; k2++) {
expected[i1 * nodes.length * nodes.length + j1 * nodes.length + k1][i2 * nodes.length * nodes.length + j2 * nodes.length + k2] = nodes[i1].equals(nodes[i2]) && nodes[j1].equals(nodes[j2]) && nodes[k1].equals(nodes[k2]);
}
}
}
}
}
}
assertEquals("triple, null", triples[0].equals(null), false);
assertDiffer("triple, string", triples[0], "string");
// now compare each triple with each other triple
for (int i = 0; i < triples.length; i++) {
for (int j = 0; j < triples.length; j++) {
if (expected[i][j]) {
assertEquals("triples " + i + ", " + j, triples[i], triples[j]);
} else {
assertDiffer("triples" + i + ", " + j, triples[i], triples[j]);
}
}
}
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class TestNode method eqTestCases.
/**
* test cases for equality: an array of (Node, String) pairs. [It's not worth
* making a special class for these pairs.] The nodes are created with caching
* off, to make sure that caching effects don't hide the effect of using .equals().
* The strings are "equality groups": the nodes should test equal iff their
* associated strings test equal.
*/
private Object[][] eqTestCases() {
BlankNodeId id = BlankNodeId.create();
LiteralLabel L2 = LiteralLabelFactory.create(id.toString(), "", false);
LiteralLabel LLang1 = LiteralLabelFactory.createByValue("xyz", "en", null);
LiteralLabel LLang2 = LiteralLabelFactory.createByValue("xyz", "EN", null);
String U2 = id.toString();
String N2 = id.toString();
return new Object[][] { { Node.ANY, "0" }, { NodeFactory.createBlankNode(id), "1" }, { NodeFactory.createBlankNode(), "2" }, { NodeFactory.createBlankNode(id), "1" }, { NodeFactory.createLiteral(L), "3" }, { NodeFactory.createLiteral(L2), "4" }, { NodeFactory.createLiteral(L), "3" }, { NodeFactory.createURI(U), "5" }, { NodeFactory.createURI(U2), "6" }, { NodeFactory.createURI(U), "5" }, { NodeFactory.createVariable(N), "7" }, { NodeFactory.createVariable(N2), "8" }, { NodeFactory.createVariable(N), "7" }, { NodeFactory.createLiteral(LLang1), "9" }, { NodeFactory.createLiteral(LLang2), "10" } };
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class TestLiteralLabels method testHashCodesForBase64Binary_2.
public void testHashCodesForBase64Binary_2() {
LiteralLabel A = node("'illgeal'http://www.w3.org/2001/XMLSchema#base64Binary").getLiteral();
LiteralLabel B = node("'illgeal'http://www.w3.org/2001/XMLSchema#base64Binary").getLiteral();
assertEquals(A.hashCode(), B.hashCode());
}
use of org.apache.jena.graph.impl.LiteralLabel in project jena by apache.
the class TestLiteralLabels method testHashCodesForBase64Binary_1.
public void testHashCodesForBase64Binary_1() {
LiteralLabel A = node("'0123'http://www.w3.org/2001/XMLSchema#base64Binary").getLiteral();
LiteralLabel B = node("'0123'http://www.w3.org/2001/XMLSchema#base64Binary").getLiteral();
assertEquals(A.hashCode(), B.hashCode());
}
Aggregations