001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.record; 016 017 import org.apache.hivemind.util.Defense; 018 019 /** 020 * Used to identify a property change. 021 * 022 * @author Howard Lewis Ship 023 */ 024 025 public class ChangeKey 026 { 027 private int _hashCode = -1; 028 029 private String _componentPath; 030 031 private String _propertyName; 032 033 public ChangeKey(String componentPath, String propertyName) 034 { 035 Defense.notNull(propertyName, "propertyName"); 036 037 _componentPath = componentPath; 038 _propertyName = propertyName; 039 } 040 041 public boolean equals(Object object) 042 { 043 if (object == null) 044 return false; 045 046 if (this == object) 047 return true; 048 049 if (!(object instanceof ChangeKey)) 050 return false; 051 052 ChangeKey other = (ChangeKey) object; 053 054 return same(_propertyName, other._propertyName) 055 && same(_componentPath, other._componentPath); 056 } 057 058 private boolean same(String s1, String s2) 059 { 060 return s1 == s2 || (s1 != null && s1.equals(s2)); 061 } 062 063 public String getComponentPath() 064 { 065 return _componentPath; 066 } 067 068 public String getPropertyName() 069 { 070 return _propertyName; 071 } 072 073 /** 074 * Returns a hash code computed from the property name and component path. 075 */ 076 077 public int hashCode() 078 { 079 if (_hashCode == -1) 080 { 081 _hashCode = 31 * 27 + _propertyName.hashCode(); 082 083 if (_componentPath != null) 084 _hashCode = 31 * _hashCode + _componentPath.hashCode(); 085 } 086 087 return _hashCode; 088 } 089 }