@Test public void literalsInDataset() throws Exception { final RDFDataset dataset = new RDFDataset(); dataset.addQuad("http://example.com/p", "http://example.com/p", "Same", null, null, "http://example.com/g1"); dataset.addQuad("http://example.com/p", "http://example.com/p", "Different", null, null, "http://example.com/g1"); final List<Quad> quads = dataset.getQuads("http://example.com/g1"); final Quad q1 = quads.get(0); final Quad q2 = quads.get(1); assertNotEquals(q1, q2); assertNotEquals(0, q1.compareTo(q2)); assertNotEquals(0, q1.getObject().compareTo(q2.getObject())); }
@Override public int compareTo(Quad o) { if (o == null) { return 1; } int rval = getGraph().compareTo(o.getGraph()); if (rval != 0) { return rval; } rval = getSubject().compareTo(o.getSubject()); if (rval != 0) { return rval; } rval = getPredicate().compareTo(o.getPredicate()); if (rval != 0) { return rval; } return getObject().compareTo(o.getObject()); } }
@Override public int compareTo(Quad o) { if (o == null) { return 1; } int rval = getGraph().compareTo(o.getGraph()); if (rval != 0) { return rval; } rval = getSubject().compareTo(o.getSubject()); if (rval != 0) { return rval; } rval = getPredicate().compareTo(o.getPredicate()); if (rval != 0) { return rval; } return getObject().compareTo(o.getObject()); } }
@Override public int compareTo(Node o) { // NOTE: this will also compare getValue() early! final int nodeCompare = super.compareTo(o); if (nodeCompare != 0) { // null, different type or different value return nodeCompare; } if (this.getLanguage() != null || o.getLanguage() != null) { // We'll ignore type-checking if either has language tag // as language tagged literals should always have the type // rdf:langString in RDF 1.1 return nullSafeCompare(this.getLanguage(), o.getLanguage()); } else { return nullSafeCompare(this.getDatatype(), o.getDatatype()); } // NOTE: getValue() already compared by super.compareTo() } }
@Override public int compareTo(Node o) { // NOTE: this will also compare getValue() early! final int nodeCompare = super.compareTo(o); if (nodeCompare != 0) { // null, different type or different value return nodeCompare; } if (this.getLanguage() != null || o.getLanguage() != null) { // We'll ignore type-checking if either has language tag // as language tagged literals should always have the type // rdf:langString in RDF 1.1 return nullSafeCompare(this.getLanguage(), o.getLanguage()); } else { return nullSafeCompare(this.getDatatype(), o.getDatatype()); } // NOTE: getValue() already compared by super.compareTo() } }
@Override public int compareTo(Quad o) { if (o == null) { return 1; } int rval = getGraph().compareTo(o.getGraph()); if (rval != 0) { return rval; } rval = getSubject().compareTo(o.getSubject()); if (rval != 0) { return rval; } rval = getPredicate().compareTo(o.getPredicate()); if (rval != 0) { return rval; } return getObject().compareTo(o.getObject()); } }
@Test public void iriSameIri() throws Exception { final Node iri = new IRI("http://example.com/same"); final Node same = new IRI("http://example.com/same"); assertEquals(iri, same); assertEquals(0, iri.compareTo(same)); }
@Test public void literalDifferentNull() throws Exception { final Node literal = new Literal("hello", null, null); assertNotEquals(0, literal.compareTo(null)); }
@Test public void iriDifferentNull() throws Exception { final Node iri = new IRI("http://example.com/"); assertNotEquals(0, iri.compareTo(null)); }
@Test public void iriDifferentBlankNode() throws Exception { // We'll use a relative IRI to avoid :-issues final Node iri = new IRI("b1"); final Node bnode = new BlankNode("b1"); assertNotEquals(iri, bnode); assertNotEquals(bnode, iri); assertNotEquals(0, iri.compareTo(bnode)); assertNotEquals(0, bnode.compareTo(iri)); }
@Test public void iriDifferentIri() throws Exception { final Node iri = new IRI("http://example.com/"); final Node other = new IRI("http://example.com/other"); assertNotEquals(iri, other); assertNotEquals(0, iri.compareTo(other)); }
@Test public void literalDifferentBlankNode() throws Exception { // We'll use a relative IRI to avoid :-issues final Node literal = new Literal("b1", null, null); final Node bnode = new BlankNode("b1"); assertNotEquals(literal, bnode); assertNotEquals(bnode, literal); assertNotEquals(0, literal.compareTo(bnode)); assertNotEquals(0, bnode.compareTo(literal)); }