1   /*
2    * RDFpro - An extensible tool for building stream-oriented RDF processing libraries.
3    * 
4    * Written in 2015 by Francesco Corcoglioniti with support by Alessio Palmero Aprosio and Marco
5    * Rospocher. Contact info on http://rdfpro.fbk.eu/
6    * 
7    * To the extent possible under law, the authors have dedicated all copyright and related and
8    * neighboring rights to this software to the public domain worldwide. This software is
9    * distributed without any warranty.
10   * 
11   * You should have received a copy of the CC0 Public Domain Dedication along with this software.
12   * If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
13   */
14  package eu.fbk.rdfpro.internal;
15  
16  import org.openrdf.model.Value;
17  import org.openrdf.model.ValueFactory;
18  import org.openrdf.model.vocabulary.RDF;
19  import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
20  import org.openrdf.query.algebra.evaluation.function.Function;
21  
22  import eu.fbk.rdfpro.vocab.RR;
23  
24  public class FunctionStarSelectGraph implements Function {
25  
26      @Override
27      public String getURI() {
28          return RR.STAR_SELECT_GRAPH.stringValue();
29      }
30  
31      @Override
32      public Value evaluate(final ValueFactory valueFactory, final Value... args)
33              throws ValueExprEvaluationException {
34  
35          final Value global = args[0];
36  
37          Value result = null;
38          for (int i = 1; i < args.length; ++i) {
39              final Value graph = args[i];
40              if (!graph.equals(global)) {
41                  if (result == null) {
42                      result = graph;
43                  } else {
44                      return RDF.NIL;
45                  }
46              }
47          }
48  
49          return result != null ? result : global;
50      }
51  
52  }