1 10 11 package com.hp.hpl.jena.reasoner.rulesys.builtins; 12 13 import com.hp.hpl.jena.reasoner.rulesys.*; 14 import com.hp.hpl.jena.graph.*; 15 16 23 24 public class Difference extends BaseBuiltin { 25 26 30 public String getName() { 31 return "difference"; 32 } 33 34 37 public int getArgLength() { 38 return 3; 39 } 40 41 51 public boolean bodyCall(Node[] args, int length, RuleContext context) { 52 checkArgs(length, context); 53 BindingEnvironment env = context.getEnv(); 54 Node n1 = getArg(0, args, context); 55 Node n2 = getArg(1, args, context); 56 if (n1.isLiteral() && n2.isLiteral()) { 57 Object v1 = n1.getLiteral().getValue(); 58 Object v2 = n2.getLiteral().getValue(); 59 Node sum = null; 60 if (v1 instanceof Number && v2 instanceof Number ) { 61 Number nv1 = (Number )v1; 62 Number nv2 = (Number )v2; 63 if (v1 instanceof Float || v1 instanceof Double 64 || v2 instanceof Float || v2 instanceof Double ) { 65 sum = Util.makeDoubleNode(nv1.doubleValue() - nv2.doubleValue()); 66 } else { 67 sum = Util.makeLongNode(nv1.longValue() - nv2.longValue()); 68 } 69 env.bind(args[2], sum); 70 return true; 71 } 72 } 73 return false; 75 } 76 77 } 78 79 80 109 | Popular Tags |