001/* 002 * ModeShape (http://www.modeshape.org) 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.modeshape.schematic.document; 017 018import org.modeshape.schematic.annotation.Immutable; 019 020/** 021 * An object representation of 'null'. This is sometimes more convenient than dealing with 'null' as values. 022 * 023 * @author Randall Hauch <rhauch@redhat.com> (C) 2011 Red Hat Inc. 024 */ 025@Immutable 026public class Null { 027 028 protected static final Null INSTANCE = new Null(); 029 030 public static final Null getInstance() { 031 return INSTANCE; 032 } 033 034 public static final boolean matches( Object value ) { 035 return value == null || value == INSTANCE || value instanceof Null; 036 } 037 038 private Null() { 039 // prevent instantiation 040 } 041 042 @Override 043 public int hashCode() { 044 return INSTANCE.hashCode(); 045 } 046 047 @Override 048 public boolean equals( Object obj ) { 049 return obj == null || obj == this || obj instanceof Null; 050 } 051 052 @Override 053 public String toString() { 054 return "null"; 055 } 056 057 /** 058 * There should only be on instance of this (though there may be others due to serialization). 059 */ 060 @Override 061 protected final Object clone() { 062 return INSTANCE; 063 } 064}