001 /** 002 * 003 */ 004 package org.springframework.binding.value.support; 005 006 import org.springframework.binding.value.ValueChangeDetector; 007 008 /** 009 * An implementation of ValueChangeDetector that provides the same semantics as 010 * {@link org.springframework.util.ObjectUtils#nullSafeEquals(java.lang.Object, java.lang.Object)}. 011 * If the objects are not the same object, they are compared using the equals method of 012 * the first object. Nulls are handled safely. 013 * 014 * @author Larry Streepy 015 * 016 */ 017 public class EqualsValueChangeDetector implements ValueChangeDetector { 018 019 /** 020 * Determines if there has been a change in value between the provided arguments. The 021 * objects are compared using the <code>equals</code> method. 022 * 023 * @param oldValue Original object value 024 * @param newValue New object value 025 * @return true if the objects are different enough to indicate a change in the value 026 * model 027 */ 028 public boolean hasValueChanged(Object oldValue, Object newValue) { 029 return !(oldValue == newValue || (oldValue != null && oldValue.equals( newValue ))); 030 } 031 }