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.graph.*; 15 16 22 public class Min extends BaseBuiltin { 23 24 28 public String getName() { 29 return "min"; 30 } 31 32 35 public int getArgLength() { 36 return 3; 37 } 38 39 49 public boolean bodyCall(Node[] args, int length, RuleContext context) { 50 checkArgs(length, context); 51 BindingEnvironment env = context.getEnv(); 52 Node n1 = getArg(0, args, context); 53 Node n2 = getArg(1, args, context); 54 if (n1.isLiteral() && n2.isLiteral()) { 55 Object v1 = n1.getLiteral().getValue(); 56 Object v2 = n2.getLiteral().getValue(); 57 Node res = null; 58 if (v1 instanceof Number && v2 instanceof Number ) { 59 Number nv1 = (Number )v1; 60 Number nv2 = (Number )v2; 61 if (v1 instanceof Float || v1 instanceof Double 62 || v2 instanceof Float || v2 instanceof Double ) { 63 res = (nv1.doubleValue() > nv2.doubleValue()) ? n2 : n1; 64 } else { 65 res = (nv1.longValue() > nv2.longValue()) ? n2 : n1; 66 } 67 env.bind(args[2], res); 68 return true; 69 } 70 } 71 return false; 73 } 74 75 } 76 77 | Popular Tags |