View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20  */
21  
22  
23  
24  package zeus.concepts.fn;
25  
26  import java.util.*;
27  import zeus.util.*;
28  import zeus.concepts.*;
29  
30  public class RealFn extends ValueFunction 
31                      implements PrimitiveFn, PrimitiveNumericFn {
32  
33     protected double arg;
34  
35     public RealFn(double arg) {
36        super(REAL,10);
37        this.arg = arg;
38     }
39     public RealFn(String arg) {
40        super(REAL,10);
41        this.arg = (Double.valueOf(arg)).doubleValue();
42     }
43     public ValueFunction mirror() {
44        return new RealFn(arg);
45     }
46     public String toString() {
47        return Double.toString(arg);
48     }
49     Object getArg(int position) {
50        if (position != 0) throw new ArrayIndexOutOfBoundsException(position);
51        return new Double(arg);
52     }
53     public double getValue() {
54        return arg;
55     }
56     public double doubleValue() {
57        return arg;
58     }
59     public int intValue() {
60        return (int)arg;
61     }
62     public long longValue() {
63        return (long)arg;
64     }
65     public boolean references(ValueFunction var) {
66        return false;
67     }
68     public boolean isDeterminate() {
69        return true;
70     }
71     public boolean equals(Object any) {
72        if ( !(any instanceof ValueFunction) ) return false;
73        ValueFunction fn = (ValueFunction)any;
74        switch( fn.getID() ) {
75           case INT:
76                return arg == ((IntFn)fn).getValue();
77           case REAL:
78                return arg == ((RealFn)fn).getValue();
79        }
80        return false;
81     }
82     public boolean less(Object any) {
83        if ( !(any instanceof ValueFunction) ) return false;
84        ValueFunction fn = (ValueFunction)any;
85        switch( fn.getID() ) {
86           case INT:
87                return arg < ((IntFn)fn).getValue();
88           case REAL:
89                return arg < ((RealFn)fn).getValue();
90        }
91        return false;
92     }
93     ValueFunction unify(ValueFunction fn, Bindings b) {
94        return null;
95     }
96  }