[ https://issues.apache.org/jira/browse/JENA-1391?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16155844#comment-16155844 ]
A. Soroka commented on JENA-1391: --------------------------------- I can see the relevance of the lambda question with respect to {{add}} and {{remove}} but not WRT the others. If that is a particular motivation for this ticket, perhaps it might worthwhile to keep the {{Dataset}} simple, introduce a {{DatasetLib}} (as [~andy.seaborne] suggests) for everything but {{add}} and {{remove}} and introduce some {{java.util.stream.Collector}} s for adding and removing from a {{Dataset}}. Something along the lines of: {code} class Collectors { public Collector<Dataset, ?, Dataset> adder(Dataset d) { .... } public Collector<Dataset, ?, Dataset> remover(Dataset d) { .... } public Collector<Model, ?, Model> adder(Model m) { .... } public Collector<Model, ?, Model> remover(Model m) { .... } } {code} which would collect things up from {{Stream}} s as needed. That could find a more general audience. In fact, I wouldn't mind dealing with JENA-1390 in a similar way, by putting a simple {{collect}} method in someplace like the {{Iter}} library in {{jena-base}} and then having factories of common "collectors" available in the modules where they would make sense. If that sounds attractive, I can work up a PR. > Add Convenience Methods to Dataset > ---------------------------------- > > Key: JENA-1391 > URL: https://issues.apache.org/jira/browse/JENA-1391 > Project: Apache Jena > Issue Type: Improvement > Components: ARQ > Affects Versions: Jena 3.4.0 > Reporter: Adam Jacobs > Priority: Trivial > > The Dataset interface could provide several convenience methods similar to > the Model interface, allowing usability of RDF quads on par with RDF triples. > Specific examples include, > # add(Dataset) > # remove(Dataset) > # union(Dataset) > # intersection(Dataset) > # difference(Dataset) > # isEmpty() > Following is a possible implementation of these methods. > {code:java} > default Dataset add(Dataset d) { > this.getDefaultModel().add(d.getDefaultModel()); > d.listNames().forEachRemaining(name -> > this.getNamedModel(name).add(d.getNamedModel(name))); > return this; > } > default Dataset remove(Dataset d) { > this.getDefaultModel().remove(d.getDefaultModel()); > d.listNames().forEachRemaining(name -> > this.getNamedModel(name).remove(d.getNamedModel(name))); > return this; > } > default Dataset union(Dataset d) { > return DatasetFactory.create().add(this).add(d); > } > default Dataset difference(Dataset d) { > Dataset output = DatasetFactory.create(); > > output.setDefaultModel(this.getDefaultModel().difference(d.getDefaultModel())); > this.listNames().forEachRemaining(name -> { > Model difference = > this.getNamedModel(name).difference(d.getNamedModel(name)); > if (!difference.isEmpty()) output.addNamedModel(name, difference); > }); > return output; > } > default Dataset intersection(Dataset d) { > Dataset output = DatasetFactory.create(); > > output.setDefaultModel(this.getDefaultModel().intersection(d.getDefaultModel())); > Set<String> names = this.names(); > names.retainAll(d.names()); > names.forEach(name -> { > Model intersection = > this.getNamedModel(name).intersection(d.getNamedModel(name)); > if (!intersection.isEmpty()) output.addNamedModel(name, > intersection); > }); > return output; > } > default Set<String> names() { > Set<String> names = new HashSet<>(); > this.listNames().forEachRemaining(names::add); > return names; > } > default boolean isEmpty() { > return this.asDatasetGraph().isEmpty(); > } > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029)