/
ToStringNullMarker.java
44 lines (36 loc) · 1.09 KB
/
ToStringNullMarker.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.search.bridge.util.impl;
import org.hibernate.search.bridge.spi.NullMarker;
/**
* A null marker that uses toString() to retrieve the null string representation.
*
* @author Yoann Rodiere
*/
public class ToStringNullMarker implements NullMarker {
private final Object indexNullAs;
private final String stringRepresentation;
public ToStringNullMarker(final Object indexNullAs) {
if ( indexNullAs == null ) {
throw new NullPointerException( "The constructor parameter is mandatory" );
}
this.indexNullAs = indexNullAs;
this.stringRepresentation = indexNullAs.toString();
}
@Override
public String nullRepresentedAsString() {
return stringRepresentation;
}
@Override
public Object nullEncoded() {
return indexNullAs;
}
@Override
public String toString() {
return getClass().getSimpleName() + "[" + indexNullAs + "]";
}
}