package hirondelle.fish.translate.locale;
import java.util.*;
import hirondelle.web4j.model.ModelCtorException;
import hirondelle.web4j.model.ModelUtil;
import hirondelle.web4j.model.Check;
import hirondelle.web4j.model.Id;
import static hirondelle.web4j.util.Consts.FAILS;
import hirondelle.web4j.security.SafeText;
public final class SupportedLocale {
public SupportedLocale(Id aId, SafeText aShortForm, SafeText aDescription) throws ModelCtorException {
fId = aId;
fShortForm = aShortForm;
fDescription = aDescription;
validateState();
}
public Id getId(){ return fId; }
public SafeText getShortForm() { return fShortForm; }
public SafeText getDescription() { return fDescription; }
@Override public String toString(){
return ModelUtil.toStringFor(this);
}
@Override public boolean equals(Object aThat){
Boolean result = ModelUtil.quickEquals(this, aThat);
if ( result == null ){
SupportedLocale that = (SupportedLocale) aThat;
result = ModelUtil.equalsFor(this.getSignificantFields(), that.getSignificantFields());
}
return result;
}
@Override public int hashCode(){
if (fHashCode == 0){
fHashCode = ModelUtil.hashCodeFor(getSignificantFields());
}
return fHashCode;
}
private final Id fId;
private final SafeText fShortForm;
private final SafeText fDescription;
private int fHashCode;
private void validateState() throws ModelCtorException {
ModelCtorException ex = new ModelCtorException();
if ( FAILS == Check.optional(fId, Check.range(1, 50)) ) {
ex.add("Id is optional, 1..50 chars.");
}
if ( FAILS == Check.required(fShortForm, Check.range(2,50)) ) {
ex.add("Short Form is required, 2..50 chars.");
}
if ( FAILS == Check.required(fDescription, Check.range(2,50)) ) {
ex.add("Description is required, 2..50 chars.");
}
if ( ! ex.isEmpty() ) throw ex;
}
private Object[] getSignificantFields(){
return new Object[] {fShortForm, fDescription};
}
}