public List asList() throws OpenRDFException { return asResult().asList(); }
public Set asSet() throws OpenRDFException { return asResult().asSet(); }
public CharSequence asCharSequence() throws OpenRDFException { Result<CharSequence> result = asResult(CharSequence.class); if (result.hasNext()) return result.singleResult(); return null; }
/** * Loads a single Object that is assumed to be of the given concept. */ public <T> T getObject(Class<T> concept, Resource resource) throws RepositoryException, QueryEvaluationException { return getObjects(concept, resource).singleResult(); }
@Override protected T getNextElement() throws QueryEvaluationException { T next = result.next(); if (next != null) { list.remove(((RDFObject) next).getResource()); return next; } if (!list.isEmpty()) return (T) of.createObject(list.remove(0)); return null; } };
public MutableTupleResult(Collection<String> bindingNames, Result<? extends BindingSet> bindingSetIter) throws StoreException { this.bindingNames.addAll(bindingNames); bindingSetIter.addTo(this.bindingSets); }
public char asChar() throws OpenRDFException { return asResult(Character.class).singleResult().charValue(); }
@Override protected T getNextElement() throws QueryEvaluationException { T next = result.next(); if (next != null) { list.remove(((RDFObject) next).getResource()); return next; } if (!list.isEmpty()) return (T) cache(of.createObject(list.remove(0))); return null; } };
public Set asSet() throws OpenRDFException { return asResult().asSet(); }
public <T> T as(Class<T> of) throws OpenRDFException { Result<T> result = asResult(of); if (result.hasNext()) return result.singleResult(); return null; }
public List asList() throws OpenRDFException { return asResult().asList(); }
public long asLong() throws OpenRDFException { return asResult(Long.class).singleResult().longValue(); }
/** * Finds a single object of given concept and uri. */ public synchronized <T> T findObject(Class<T> concept, Resource resource) throws RepositoryException, QueryEvaluationException { try { ObjectQuery query = getObjectQuery(concept, 0); query.setBinding("subj", resource); return query.evaluate(concept).next(); } catch (MalformedQueryException e) { throw new AssertionError(e); } }
/** * Returns all instances of the given type (and its subtypes) that are present in this parsers Anno4j instance. * @param type An {@link org.openrdf.annotations.Iri}-annotated type that all returned objects must have. * @param <T> The type of the returned objects. * @return Returns all instances present in the Anno4j connected triplestore having the given {@code type}. * Doesn't contain duplicates. * @throws RepositoryException Thrown if an error occurs accessing the connected triplestore. */ private <T extends ResourceObject> List<T> getInstancesOfType(Class<? extends T> type) throws RepositoryException { List<T> instances = new ArrayList<>(); ObjectConnection connection = anno4j.getObjectRepository().getConnection(); try { instances.addAll(connection.getObjects(type).asSet()); } catch (QueryEvaluationException e) { throw new RepositoryException(e); } return instances; }
public String asString() throws OpenRDFException { Result<String> result = asResult(String.class); if (result.hasNext()) return result.singleResult(); return null; }
public <T> List<T> asList(Class<T> of) throws OpenRDFException { if (of == null || Object.class.equals(of)) return asList(); return asResult(of).asList(); }
public float asFloat() throws OpenRDFException { return asResult(Float.class).singleResult().floatValue(); }