KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > util > Null


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.util;
23
24 import java.io.Serializable JavaDoc;
25
26 /**
27  * A class that represents <tt>null</tt>.
28  *
29  * <p>{@link Null#VALUE} is used to given an object variable a dual-mode
30  * nullified value, where <tt>null</tt> would indicate that the value is
31  * empty, and {@link Null#VALUE} would idicate that the value has been
32  * set to <tt>null</tt> (or something to that effect).
33  *
34  * @version <tt>$Revision: 1958 $</tt>
35  * @author <a HREF="mailto:jason@planet57.com">Jason Dillon</a>
36  */

37 public final class Null
38    implements Serializable JavaDoc
39 {
40    /** The primary instance of Null. */
41    public static final Null VALUE = new Null();
42
43    /** Do not allow public construction. */
44    private Null() {}
45
46    /**
47     * Return a string representation.
48     *
49     * @return Null
50     */

51    public String JavaDoc toString() {
52       return null;
53    }
54
55    /**
56     * Returns zero.
57     *
58     * @return Zero.
59     */

60    public int hashCode() {
61       return 0;
62    }
63
64    /**
65     * Check if the given object is a Null instance or <tt>null</tt>.
66     *
67     * @param obj Object to test.
68     * @return True if the given object is a Null instance or <tt>null</tt>.
69     */

70    public boolean equals(final Object JavaDoc obj) {
71       if (obj == this) return true;
72       return (obj == null || obj.getClass() == getClass());
73    }
74 }
75
76
Popular Tags