Top Fields Constructors Methods
org.codehaus.groovy.runtime

public Class NullObject

extends GroovyObjectSupport
Class Inheritance
Imports
groovy.lang.Closure, .GroovyObjectSupport, java.util.Collections, .Iterator

Field Summary

Modifier and TypeField and Description
private static final NullObject

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

false
asBoolean
()

A null object coerces to false.

public Object

Returns:

null
asType
(final Class<T> c)

Type conversion method for null.

public Object

Returns:

never
clone
()

Overrides java.lang.Object.clone.

Since this is implemented as a singleton, avoid the use of the clone method.
public boolean

Returns:

true if this object is the same as the to argument
equals
(final Object
the reference object with which to compare
o
)

Overrides java.lang.Object.equals.

null is only equal to null.
public static NullObject

Returns:

the null object
getNullObject
()

Returns the NullObject reference.

public Object

Returns:

never
getProperty
(final String
the name of the property of interest
name
)

Overrides default groovy.lang.GroovyObject.getProperty.

Tries to get a property on null, which fails.
public int

Returns:

never
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public Object

Returns:

never
invokeMethod
(final String
the name of the method to call
name
,
final Object
the arguments to use for the method call
arguments
)

Overrides default groovy.lang.GroovyObject.invokeMethod.

Tries to invoke a method on null, which falis.
public boolean

Returns:

true if object is null
is
(final Object o)

Tests for equal references.

public Iterator<E>

Returns:

an empty iterator
iterator
()

Provides ability to iterate on null.

public Object

Returns:

never
plus
(final Object o)

Fallback for null+null.

public Object

Returns:

the concatenated string
plus
(final String s)

Allows to add a String to null.

public void
setProperty(final String
the name of the property of interest
name
,
final Object
the new value for the property
value
)

Overrides default groovy.lang.GroovyObject.setProperty.

Tries to set a property on null, which fails.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public <T> T

Returns:

result of calling the closure
with
(final Closure<T>
the closure to call on the object
closure
)

Allows the closure to be called for NullObject.

Inherited from groovy.lang.GroovyObjectSupport:
getMetaClasssetMetaClass

Field Detail

INSTANCEback to summary
private static final NullObject INSTANCE

Constructor Detail

NullObjectback to summary
private NullObject()

Method Detail

asBooleanback to summary
public boolean asBoolean()

A null object coerces to false.

Returns:boolean

false

asTypeback to summary
public Object asType(final Class<T> c)

Type conversion method for null.

Returns:Object

null

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Since this is implemented as a singleton, avoid the use of the clone method.

Returns:Object

never

Annotations
@Override
equalsback to summary
public boolean equals(final Object o)

Overrides java.lang.Object.equals.

null is only equal to null.

Parameters
o:Object

the reference object with which to compare

Returns:boolean

true if this object is the same as the to argument

Annotations
@Override
getNullObjectback to summary
public static NullObject getNullObject()

Returns the NullObject reference.

Returns:NullObject

the null object

getPropertyback to summary
public Object getProperty(final String name)

Overrides default groovy.lang.GroovyObject.getProperty.

Tries to get a property on null, which fails.

Parameters
name:String

Doc from groovy.lang.GroovyObject.getProperty.

the name of the property of interest

Returns:Object

never

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

never

Annotations
@Override
invokeMethodback to summary
public Object invokeMethod(final String name, final Object arguments)

Overrides default groovy.lang.GroovyObject.invokeMethod.

Tries to invoke a method on null, which falis.

Parameters
name:String

Doc from groovy.lang.GroovyObject.invokeMethod.

the name of the method to call

arguments:Object

Doc from groovy.lang.GroovyObject.invokeMethod.

the arguments to use for the method call

Returns:Object

never

Annotations
@Override
isback to summary
public boolean is(final Object o)

Tests for equal references.

Returns:boolean

true if object is null

iteratorback to summary
public Iterator<E> iterator()

Provides ability to iterate on null.

Returns:Iterator<E>

an empty iterator

plusback to summary
public Object plus(final Object o)

Fallback for null+null. The plus(String) variant catches the case of adding a non-null String to null.

Returns:Object

never

plusback to summary
public Object plus(final String s)

Allows to add a String to null. The result is concatenated String of the result of calling toString() on this object and the String in the parameter.

Returns:Object

the concatenated string

setPropertyback to summary
public void setProperty(final String name, final Object value)

Overrides default groovy.lang.GroovyObject.setProperty.

Tries to set a property on null, which fails.

Parameters
name:String

Doc from groovy.lang.GroovyObject.setProperty.

the name of the property of interest

value:Object

Doc from groovy.lang.GroovyObject.setProperty.

the new value for the property

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
withback to summary
public <T> T with(final Closure<T> closure)

Allows the closure to be called for NullObject.

Parameters
closure:Closure<T>

the closure to call on the object

Returns:T

result of calling the closure