@Override public N getNode(NODE node) { if (node.isLiteral()) { return getLiteral(node.asLiteral()); } else if (node.isBNode()) { return getBNode(node.asBNode()); } else { return getURI(node.asURI()); } }
@Override public int compare(NODE o1, NODE o2) { if (o1 == null) { return o2 == null ? 0 : -1; } else if (o2 == null) { return 1; } // node type if (o1.getNodeType() != o2.getNodeType()) { return o1.getNodeType().compareTo(o2.getNodeType()); } // value if (!o1.getValue().equals(o2.getValue())) { return o1.getValue().compareTo(o2.getValue()); } if (o1.isLiteral() && o2.isLiteral()) { LIT l1 = o1.asLiteral(); LIT l2 = o2.asLiteral(); // datatype if (!l1.getDatatype().equals(l2.getDatatype())) { return compare(l1.getDatatype(), l2.getDatatype()); } // locale Locale loc1 = l1.getLang() == null ? new Locale("") : l1.getLang(); Locale loc2 = l2.getLang() == null ? new Locale("") : l2.getLang(); return loc1.toString().compareTo(loc2.toString()); } return 0; }
public static String toString(NODE node) { if (node.isURI()) { return toString(node.asURI()); } else if (node.isLiteral()) { return toString(node.asLiteral()); } else { return toString(node.asBNode()); } }
private void append(NODE node) throws IOException { if (node.isURI()) { append(node.asURI()); } else if (node.isLiteral()) { append(node.asLiteral()); } else { append(node.asBNode()); } }
LIT lit = stmt.getObject().asLiteral(); if (lit.getLang() != null) { writer.append(" xml:lang=\"" + LocaleUtil.toLang(lit.getLang()) + "\"");
if (dataType == null || !stmt.getObject().asLiteral().getDatatype().equals(dataType)) { continue;
@Test public void test() { NODE uri = RDF.type; NODE bnode = new BID(); NODE lit = new LIT(""); assertEquals(uri, uri.asURI()); assertEquals(bnode, bnode.asBNode()); assertEquals(lit, lit.asLiteral()); }