1 10 package com.hp.hpl.jena.reasoner.rulesys.builtins; 11 12 import java.util.*; 13 14 import com.hp.hpl.jena.reasoner.rulesys.*; 15 import com.hp.hpl.jena.graph.*; 16 17 23 public class ListEqual extends BaseBuiltin { 24 25 29 public String getName() { 30 return "listEqual"; 31 } 32 33 36 public int getArgLength() { 37 return 2; 38 } 39 40 50 public boolean bodyCall(Node[] args, int length, RuleContext context) { 51 checkArgs(length, context); 52 Node n0 = getArg(0, args, context); 53 Node n1 = getArg(1, args, context); 54 return listEqual(n0, n1, context); 55 } 56 57 60 protected static boolean listEqual(Node list1, Node list2, RuleContext context ) { 61 List elts1 = Util.convertList(list1, context); 62 List elts2 = Util.convertList(list2, context); 63 if (elts1.size() != elts2.size()) return false; 64 for (Iterator i = elts1.iterator(); i.hasNext(); ) { 65 Node elt = (Node)i.next(); 66 boolean matched = false; 67 for (Iterator j = elts2.iterator(); j.hasNext(); ) { 68 Node elt2 = (Node)j.next(); 69 if (elt.sameValueAs(elt2)) { 70 j.remove(); 72 matched = true; 73 break; 74 } 75 } 76 if (!matched) { 77 return false; 78 } 79 } 80 return true; 81 } 82 } 83 84 85 86 | Popular Tags |