initial load
[DTRules.git] / DTRules / src / main / java / com / dtrules / interpreter / RNull.java
blobff95d94736d9880d9dc3f19e85887ee20e2231b5
1 /*
2 * $Id$
3 *
4 * Copyright 2004-2007 MTBJ, Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
19 package com.dtrules.interpreter;
21 import com.dtrules.infrastructure.RulesException;
23 public class RNull extends ARObject {
25 /**
26 * returns 0 if both are equal. -1 Otherwise. A Null is considered
27 * less than anything else. We do this just so sorting arrays were
28 * some values are null doesn't blow up.
30 public int compare(IRObject irObject) throws RulesException {
31 if(irObject.equals(this))return 0; // A Null is equal to other nulls.
32 return -1; // A Null is less than anything else.
37 static RNull theNullObject = new RNull();
38 /**
39 * Nobody needs the constructor.
42 private RNull(){}
44 /**
45 * Returns the RNull object. There is no need for more than
46 * one of these objects.
47 * @return
49 public static RNull getRNull(){ return theNullObject; }
51 /**
52 * A Null is only equal to the null object
54 public boolean equals(IRObject o) {
55 return o.type()==iNull;
58 public String stringValue() {
59 return "null";
62 /**
63 * A Null is only equal to the null object, i.e. any
64 * Null object. They are all equal.
66 public boolean equals(Object arg0) {
67 return arg0.getClass().equals(this.getClass());
70 /**
71 * We override toString() to simply return "null".
72 * Because we do this, we override hashcode() as well.
74 public String toString() {
75 return "null";
78 public int hashCode() {
79 return 0;
82 public int type() {
83 return iNull;