001/* 002 * Copyright 2002-2017 the original author or authors. 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 * https://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 */ 016 017package org.springframework.cache.support; 018 019import java.io.Serializable; 020 021import org.springframework.lang.Nullable; 022 023/** 024 * Simple serializable class that serves as a {@code null} replacement 025 * for cache stores which otherwise do not support {@code null} values. 026 * 027 * @author Juergen Hoeller 028 * @since 4.2.2 029 * @see AbstractValueAdaptingCache 030 */ 031public final class NullValue implements Serializable { 032 033 /** 034 * The canonical representation of a {@code null} replacement, as used by the 035 * default implementation of {@link AbstractValueAdaptingCache#toStoreValue}/ 036 * {@link AbstractValueAdaptingCache#fromStoreValue}. 037 * @since 4.3.10 038 */ 039 public static final Object INSTANCE = new NullValue(); 040 041 private static final long serialVersionUID = 1L; 042 043 044 private NullValue() { 045 } 046 047 private Object readResolve() { 048 return INSTANCE; 049 } 050 051 052 @Override 053 public boolean equals(@Nullable Object obj) { 054 return (this == obj || obj == null); 055 } 056 057 @Override 058 public int hashCode() { 059 return NullValue.class.hashCode(); 060 } 061 062 @Override 063 public String toString() { 064 return "null"; 065 } 066 067}