KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > rulesys > builtins > GreaterThan


1 /******************************************************************
2  * File: GreaterThan.java
3  * Created by: Dave Reynolds
4  * Created on: 24-Aug-2003
5  *
6  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
7  * [See end of file]
8  * $Id: GreaterThan.java,v 1.6 2005/02/21 12:17:23 andy_seaborne Exp $
9  *****************************************************************/

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
16 //Thanks to Bradley Schatz (Bradley@greystate.com) for code patches
17
//to support XSDDateTime comparisons
18

19 /**
20  * Tests if the first argument is greater than the second.
21  *
22  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
23  * @version $Revision: 1.6 $ on $Date: 2005/02/21 12:17:23 $
24  */

25 public class GreaterThan extends BaseBuiltin {
26
27     /**
28      * Return a name for this builtin, normally this will be the name of the
29      * functor that will be used to invoke it.
30      */

31     public String JavaDoc getName() {
32         return "greaterThan";
33     }
34     
35     /**
36      * Return the expected number of arguments for this functor or 0 if the number is flexible.
37      */

38     public int getArgLength() {
39         return 2;
40     }
41
42     /**
43      * This method is invoked when the builtin is called in a rule body.
44      * @param args the array of argument values for the builtin, this is an array
45      * of Nodes, some of which may be Node_RuleVariables.
46      * @param context an execution context giving access to other relevant data
47      * @return return true if the buildin predicate is deemed to have succeeded in
48      * the current environment
49      */

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         if ( Util.isNumeric(n0) && Util.isNumeric(n1) ) {
55             return Util.compareNumbers(n0, n1) > 0;
56         } else if (Util.isInstant(n0) && Util.isInstant(n1)) {
57             return Util.compareInstants(n0, n1) > 0;
58         } else {
59             return false;
60         }
61     }
62     
63 }
64
65
66 /*
67     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
68     All rights reserved.
69
70     Redistribution and use in source and binary forms, with or without
71     modification, are permitted provided that the following conditions
72     are met:
73
74     1. Redistributions of source code must retain the above copyright
75        notice, this list of conditions and the following disclaimer.
76
77     2. Redistributions in binary form must reproduce the above copyright
78        notice, this list of conditions and the following disclaimer in the
79        documentation and/or other materials provided with the distribution.
80
81     3. The name of the author may not be used to endorse or promote products
82        derived from this software without specific prior written permission.
83
84     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
85     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
86     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
87     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
88     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
89     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
90     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
91     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
92     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
93     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
94 */
Popular Tags