objects method

Set objects({
  1. URIRef? sub,
  2. URIRef? pre,
})

Finds all objects which have a certain subject and predicate.

If sub is provided, it checks for the subject. If pre is provided, it checks for the predicate. If both are provided, it checks for both subject and predicate. If neither is provided, it returns all objects in the triples.

Implementation

Set<dynamic> objects({URIRef? sub, URIRef? pre}) {
  // Initialize an empty set to store the objects.
  Set<dynamic> objs = {};

  // Iterate over all triples in the graph.
  for (Triple t in triples) {
    // Check if the sub condition matches, if provided.
    bool subMatches = sub == null || t.sub == sub;
    // Check if the pre condition matches, if provided.
    bool preMatches = pre == null || t.pre == pre;

    // If both conditions match (or are not provided), add the object.
    if (subMatches && preMatches) {
      objs.add(t.obj);
    }
  }

  // Return the set of objects.
  return objs;
}