Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ceb8a0
commit 93e563b
Showing
3 changed files
with
62 additions
and
85 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...main/java/org/hibernate/validator/internal/engine/resolver/AbstractTraversableHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Hibernate Validator, declare and validate application constraints | ||
* | ||
* License: Apache License, Version 2.0 | ||
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>. | ||
*/ | ||
package org.hibernate.validator.internal.engine.resolver; | ||
|
||
import javax.validation.Path; | ||
|
||
abstract class AbstractTraversableHolder { | ||
|
||
private final Object traversableObject; | ||
private final Path.Node traversableProperty; | ||
private final int hashCode; | ||
|
||
protected AbstractTraversableHolder(Object traversableObject, Path.Node traversableProperty) { | ||
this.traversableObject = traversableObject; | ||
this.traversableProperty = traversableProperty; | ||
this.hashCode = buildHashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if ( this == o ) { | ||
return true; | ||
} | ||
if ( o == null || !( o instanceof AbstractTraversableHolder ) ) { | ||
return false; | ||
} | ||
|
||
AbstractTraversableHolder that = (AbstractTraversableHolder) o; | ||
|
||
if ( traversableObject != null ? !traversableObject.equals( that.traversableObject ) : that.traversableObject != null ) { | ||
return false; | ||
} | ||
if ( !traversableProperty.equals( that.traversableProperty ) ) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return hashCode; | ||
} | ||
|
||
public int buildHashCode() { | ||
// HV-1013 Using identity hash code in order to avoid calling hashCode() of objects which may | ||
// be handling null properties not correctly | ||
int result = traversableObject != null ? System.identityHashCode( traversableObject ) : 0; | ||
result = 31 * result + traversableProperty.hashCode(); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters