|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover 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.commons.lang.builder.EqualsBuilder;
|
|
18 |
import org.apache.commons.lang.builder.HashCodeBuilder;
|
|
19 |
import org.apache.hivemind.util.Defense;
|
|
20 |
|
|
21 |
/**
|
|
22 |
* Used to identify a property change.
|
|
23 |
*
|
|
24 |
* @author Howard Lewis Ship
|
|
25 |
*/
|
|
26 |
|
|
27 |
public class ChangeKey |
|
28 |
{ |
|
29 |
private int _hashCode = -1; |
|
30 |
|
|
31 |
private String _componentPath;
|
|
32 |
|
|
33 |
private String _propertyName;
|
|
34 |
|
|
35 | 14 |
public ChangeKey(String componentPath, String propertyName)
|
36 |
{ |
|
37 | 14 |
Defense.notNull(propertyName, "propertyName");
|
38 |
|
|
39 | 14 |
_componentPath = componentPath; |
40 | 14 |
_propertyName = propertyName; |
41 |
} |
|
42 |
|
|
43 | 6 |
public boolean equals(Object object) |
44 |
{ |
|
45 | 6 |
if (object == null) |
46 | 1 |
return false; |
47 |
|
|
48 | 5 |
if (this == object) |
49 | 1 |
return true; |
50 |
|
|
51 | 4 |
if (!(object instanceof ChangeKey)) |
52 | 1 |
return false; |
53 |
|
|
54 | 3 |
ChangeKey other = (ChangeKey) object; |
55 |
|
|
56 | 3 |
EqualsBuilder builder = new EqualsBuilder();
|
57 |
|
|
58 | 3 |
builder.append(_propertyName, other._propertyName); |
59 | 3 |
builder.append(_componentPath, other._componentPath); |
60 |
|
|
61 | 3 |
return builder.isEquals();
|
62 |
} |
|
63 |
|
|
64 | 7 |
public String getComponentPath()
|
65 |
{ |
|
66 | 7 |
return _componentPath;
|
67 |
} |
|
68 |
|
|
69 | 7 |
public String getPropertyName()
|
70 |
{ |
|
71 | 7 |
return _propertyName;
|
72 |
} |
|
73 |
|
|
74 |
/**
|
|
75 |
* Returns a hash code computed from the property name and component path.
|
|
76 |
*/
|
|
77 |
|
|
78 | 10 |
public int hashCode() |
79 |
{ |
|
80 | 10 |
if (_hashCode == -1)
|
81 |
{ |
|
82 | 9 |
HashCodeBuilder builder = new HashCodeBuilder(257, 23); // Random |
83 |
|
|
84 | 9 |
builder.append(_propertyName); |
85 | 9 |
builder.append(_componentPath); |
86 |
|
|
87 | 9 |
_hashCode = builder.toHashCode(); |
88 |
} |
|
89 |
|
|
90 | 10 |
return _hashCode;
|
91 |
} |
|
92 |
} |
|