1 10 package com.hp.hpl.jena.reasoner.rulesys.builtins; 11 12 13 import com.hp.hpl.jena.reasoner.rulesys.*; 14 import com.hp.hpl.jena.vocabulary.RDF; 15 import com.hp.hpl.jena.graph.*; 16 17 24 public class ListContains extends BaseBuiltin { 25 26 30 public String getName() { 31 return "listContains"; 32 } 33 34 37 public int getArgLength() { 38 return 2; 39 } 40 41 51 public boolean bodyCall(Node[] args, int length, RuleContext context) { 52 checkArgs(length, context); 53 Node n0 = getArg(0, args, context); 54 Node n1 = getArg(1, args, context); 55 return listContains(n0, n1, context); 56 } 57 58 62 protected static boolean listContains(Node list, Node element, RuleContext context ) { 63 if (list == null || list.equals(RDF.Nodes.nil)) { 64 return false; 65 } else { 66 Node elt = Util.getPropValue(list, RDF.Nodes.first, context); 67 if (elt.sameValueAs(element)) { 68 return true; 69 } else { 70 Node next = Util.getPropValue(list, RDF.Nodes.rest, context); 71 return listContains(next, element, context); 72 } 73 } 74 } 75 } 76 77 78 | Popular Tags |