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 AddOne extends BaseBuiltin { 22 23 27 public String getName() { 28 return "addOne"; 29 } 30 31 34 public int getArgLength() { 35 return 2; 36 } 37 38 48 public boolean bodyCall(Node[] args, int length, RuleContext context) { 49 checkArgs(length, context); 50 BindingEnvironment env = context.getEnv(); 51 boolean ok = false; 52 Node a0 = getArg(0, args, context); 53 Node a1 = getArg(1, args, context); 54 if (Util.isNumeric(a0)) { 55 Node newVal = Util.makeIntNode( Util.getIntValue(a0) + 1 ); 56 ok = env.bind(args[1], newVal); 57 } else if (Util.isNumeric(a1)) { 58 Node newVal = Util.makeIntNode( Util.getIntValue(a1) - 1 ); 59 ok = env.bind(args[0], newVal); 60 } 61 return ok; 62 } 63 64 } 65 66 | Popular Tags |