br.com.anteros.bean.validation.ConstraintValidatorIdentity Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Anteros-Bean-Validation Show documentation
Show all versions of Anteros-Bean-Validation Show documentation
Anteros Bean Validation for Java.
/*******************************************************************************
* Copyright 2012 Anteros Tecnologia
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package br.com.anteros.bean.validation;
import br.com.anteros.validation.api.ConstraintValidator;
import br.com.anteros.validation.api.Path;
/**
* Class that stores the needed properties to ensure that a validation is not
* checked more than once.
*
* These properties are:
*
* - The ref of the bean to which the validation would be applied.
* - The path of the property.
* - The ref of the {@link ConstraintValidator}.
*
*
* @author Carlos Vara
*/
final class ConstraintValidatorIdentity {
private final Object bean;
private final Path path;
private final ConstraintValidator, ?> constraintValidator;
/**
* Create a new ConstraintValidatorIdentity instance.
* @param bean
* @param path
* @param constraintValidator
*/
public ConstraintValidatorIdentity(Object bean, Path path, ConstraintValidator, ?> constraintValidator) {
this.bean = bean;
this.path = path;
this.constraintValidator = constraintValidator;
}
/**
* Get the referenced bean.
* @return Object
*/
public Object getBean() {
return bean;
}
/**
* Get the referenced property {@link Path}.
* @return Path
*/
public Path getPath() {
return path;
}
/**
* Get the associated {@link ConstraintValidator}.
* @return {@link ConstraintValidator}
*/
public ConstraintValidator, ?> getConstraintValidator() {
return constraintValidator;
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof ConstraintValidatorIdentity)) {
return false;
}
ConstraintValidatorIdentity other = (ConstraintValidatorIdentity) obj;
// Bean ref must be the same
if (this.bean != other.bean) {
return false;
}
// ConstraintValidator ref must be the same
if (this.constraintValidator != other.constraintValidator) {
return false;
}
// Path must be equals
if (!this.path.equals(other.path)) {
return false;
}
return true;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((this.bean == null) ? 0 : this.bean.hashCode());
result = prime * result
+ ((this.path == null) ? 0 : this.path.hashCode());
result = prime * result
+ ((this.constraintValidator == null) ? 0 : this.constraintValidator.hashCode());
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy