|
|||||||||||||||||||
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ChangeKey.java | 100% | 100% | 100% | 100% |
|
1 | // Copyright 2004, 2005 The Apache Software Foundation | |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
14 | ||
15 | package org.apache.tapestry.record; | |
16 | ||
17 | import org.apache.hivemind.util.Defense; | |
18 | ||
19 | /** | |
20 | * Used to identify a property change. | |
21 | * | |
22 | * @author Howard Lewis Ship | |
23 | */ | |
24 | ||
25 | public class ChangeKey | |
26 | { | |
27 | private int _hashCode = -1; | |
28 | ||
29 | private String _componentPath; | |
30 | ||
31 | private String _propertyName; | |
32 | ||
33 | 14 | public ChangeKey(String componentPath, String propertyName) |
34 | { | |
35 | 14 | Defense.notNull(propertyName, "propertyName"); |
36 | ||
37 | 14 | _componentPath = componentPath; |
38 | 14 | _propertyName = propertyName; |
39 | } | |
40 | ||
41 | 6 | public boolean equals(Object object) |
42 | { | |
43 | 6 | if (object == null) |
44 | 1 | return false; |
45 | ||
46 | 5 | if (this == object) |
47 | 1 | return true; |
48 | ||
49 | 4 | if (!(object instanceof ChangeKey)) |
50 | 1 | return false; |
51 | ||
52 | 3 | ChangeKey other = (ChangeKey) object; |
53 | ||
54 | 3 | return same(_propertyName, other._propertyName) |
55 | && same(_componentPath, other._componentPath); | |
56 | } | |
57 | ||
58 | 5 | private boolean same(String s1, String s2) |
59 | { | |
60 | 5 | return s1 == s2 || (s1 != null && s1.equals(s2)); |
61 | } | |
62 | ||
63 | 7 | public String getComponentPath() |
64 | { | |
65 | 7 | return _componentPath; |
66 | } | |
67 | ||
68 | 7 | public String getPropertyName() |
69 | { | |
70 | 7 | return _propertyName; |
71 | } | |
72 | ||
73 | /** | |
74 | * Returns a hash code computed from the property name and component path. | |
75 | */ | |
76 | ||
77 | 10 | public int hashCode() |
78 | { | |
79 | 10 | if (_hashCode == -1) |
80 | { | |
81 | 9 | _hashCode = 31 * 27 + _propertyName.hashCode(); |
82 | ||
83 | 9 | if (_componentPath != null) |
84 | 8 | _hashCode = 31 * _hashCode + _componentPath.hashCode(); |
85 | } | |
86 | ||
87 | 10 | return _hashCode; |
88 | } | |
89 | } |
|