private Map<Locale, String> convertLocalizedMap(MappedPath propertyPath, Set<? extends NODE> values) { Map<Locale, String> result = new HashMap<Locale, String>(); for (NODE value : values) { if (value.isLiteral()) { LIT literal = (LIT) value; Locale lang = literal.getLang(); if (lang == null) { lang = Locale.ROOT; } result.put(lang, literal.getValue()); } else { throw new IllegalArgumentException("Expected Literal, got " + value.getNodeType()); } } return result; }
@Override public long count() { TupleQuery query = createTupleQuery(true); if (!connection.getQueryOptions().isCountViaAggregation()) { long counter = 0; CloseableIterator<Map<String, NODE>> tuples = query.getTuples(); try { while (tuples.hasNext()) { counter++; tuples.next(); } } finally { tuples.close(); } return counter; } else { List<Map<String, NODE>> results = IteratorAdapter.asList(query.getTuples()); NODE result = results.get(0).values().iterator().next(); if (result.isLiteral()) { return Long.valueOf(result.getValue()); } else { throw new IllegalArgumentException(result.toString()); } } }
private Object convertValue(NODE node, Class<?> targetClass) { UID targetType = configuration.getConverterRegistry().getDatatype(targetClass); if (targetClass.isAssignableFrom(node.getClass())) { return node; } else if (targetType != null && node.isLiteral()) { // TODO : make sure this works also with untyped literals etc if (((LIT) node).getDatatype().equals(targetType)) { return configuration.getConverterRegistry().fromString(node.getValue(), targetClass); } else { throw new IllegalArgumentException("Literal " + node + " is not of type " + targetType); } } else if (targetType == null && node.isURI()) { return get(targetClass, node.asURI()); } else { throw new IllegalArgumentException("Node " + node + " could not be converted to " + targetClass.getName()); } }
@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()); } }
writer.append(" <" + prefix + ":" + stmt.getPredicate().ln()); if (stmt.getObject().isLiteral()) { LIT lit = stmt.getObject().asLiteral(); if (lit.getLang() != null) {