1 10 package com.hp.hpl.jena.reasoner.rulesys.builtins; 11 12 import com.hp.hpl.jena.reasoner.rulesys.*; 13 import com.hp.hpl.jena.graph.*; 14 15 21 public class Product extends BaseBuiltin { 22 23 27 public String getName() { 28 return "product"; 29 } 30 31 34 public int getArgLength() { 35 return 3; 36 } 37 38 48 public boolean bodyCall(Node[] args, int length, RuleContext context) { 49 checkArgs(length, context); 50 BindingEnvironment env = context.getEnv(); 51 Node n1 = getArg(0, args, context); 52 Node n2 = getArg(1, args, context); 53 if (n1.isLiteral() && n2.isLiteral()) { 54 Object v1 = n1.getLiteral().getValue(); 55 Object v2 = n2.getLiteral().getValue(); 56 Node sum = null; 57 if (v1 instanceof Number && v2 instanceof Number ) { 58 Number nv1 = (Number )v1; 59 Number nv2 = (Number )v2; 60 if (v1 instanceof Float || v1 instanceof Double 61 || v2 instanceof Float || v2 instanceof Double ) { 62 sum = Util.makeDoubleNode(nv1.doubleValue() * nv2.doubleValue()); 63 } else { 64 sum = Util.makeLongNode(nv1.longValue() * nv2.longValue()); 65 } 66 env.bind(args[2], sum); 67 return true; 68 } 69 } 70 return false; 72 } 73 74 } 75 76 77 78 | Popular Tags |