
com.enterprisemath.dao.relational.EntityProfile Maven / Gradle / Ivy
package com.enterprisemath.dao.relational;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import com.enterprisemath.utils.ValidationUtils;
/**
* Entity profile object. Profile object is a tuple of entity code, profile key and profile value.
*
* @author radek.hecl
*
*/
public final class EntityProfile {
/**
* Builder object.
*/
public static class Builder {
/**
* Identification code.
*/
private String code;
/**
* Entity code.
*/
private String entityCode;
/**
* Profile key.
*/
private String profileKey;
/**
* Profile value.
*/
private String profileValue;
/**
* Sets identification code.
*
* @param code identification code
* @return this instance
*/
public Builder setCode(String code) {
this.code = code;
return this;
}
/**
* Sets entity code.
*
* @param entityCode entity code
* @return this instance
*/
public Builder setEntityCode(String entityCode) {
this.entityCode = entityCode;
return this;
}
/**
* Sets profile key.
*
* @param profileKey profile key
* @return this instance
*/
public Builder setProfileKey(String profileKey) {
this.profileKey = profileKey;
return this;
}
/**
* Sets profile value.
*
* @param profileValue profile value
* @return this instance
*/
public Builder setProfileValue(String profileValue) {
this.profileValue = profileValue;
return this;
}
/**
* Builds the result object.
*
* @return created object
*/
public EntityProfile build() {
return new EntityProfile(this);
}
}
/**
* Identification code.
*/
private String code;
/**
* Entity code.
*/
private String entityCode;
/**
* Profile key.
*/
private String profileKey;
/**
* Profile value.
*/
private String profileValue;
/**
* Creates new instance.
*
* @param builder builder object
*/
public EntityProfile(Builder builder) {
code = builder.code;
entityCode = builder.entityCode;
profileKey = builder.profileKey;
profileValue = builder.profileValue;
guardInvariants();
}
/**
* Guards this object to be consistent. Throws exception if this is not the case.
*/
private void guardInvariants() {
ValidationUtils.guardNotEmpty(code, "code cannot be empty");
ValidationUtils.guardNotEmpty(entityCode, "entityCode cannot be empty");
ValidationUtils.guardNotEmpty(profileKey, "profileKey cannot be empty");
ValidationUtils.guardNotNull(profileKey, "profileKey cannot be null");
}
/**
* Returns identification code.
*
* @return identification code
*/
public String getCode() {
return code;
}
/**
* Returns entity code.
*
* @return entity code
*/
public String getEntityCode() {
return entityCode;
}
/**
* Returns profile key.
*
* @return profile key
*/
public String getProfileKey() {
return profileKey;
}
/**
* Returns profile value.
*
* @return profile value
*/
public String getProfileValue() {
return profileValue;
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
/**
* Creates new instance.
*
* @param code identification code
* @param entityCode entity code
* @param profileKey profile key
* @param profileValue profile value
* @return created profile
*/
public static EntityProfile create(String code, String entityCode, String profileKey, String profileValue) {
return new EntityProfile.Builder().
setCode(code).
setEntityCode(entityCode).
setProfileKey(profileKey).
setProfileValue(profileValue).
build();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy