Exemplo n.º 1
0
  /** returns true if old triples from r were removed */
  public static boolean setUniqueObject(
      Model r, Resource subject, Resource predicate, RDFNode object) throws ModelException {

    Model old = r.find(subject, predicate, null);
    SetOperations.subtract(r, old);
    Statement stmt = get1(old);

    if (subject == null && stmt != null) subject = stmt.subject();
    if (predicate == null && stmt != null) predicate = stmt.predicate();

    r.add(r.getNodeFactory().createStatement(subject, predicate, object));
    return !old.isEmpty();
  }
Exemplo n.º 2
0
 /** Returns the first triple of the model */
 public static Statement get1(Model m) throws ModelException {
   if (m == null || m.isEmpty()) return null;
   //    if(m.size() > 1)
   //      throw new RuntimeException("Model contains more than one triple");
   return (Statement) m.elements().nextElement();
 }