*/
package org.opendaylight.yangtools.yang.model.util;
-import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
-
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import java.util.Objects;
+import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
/**
* {@link Immutable} implementation of {@link PatternConstraint}
private final String errorAppTag;
private final String errorMessage;
- public PatternConstraintImpl(final String regex, final Optional<String> description,
- final Optional<String> reference) {
- super();
+ PatternConstraintImpl(final String regex, final Optional<String> description, final Optional<String> reference) {
+ this(regex, description, reference, "invalid-regular-expression", String.format(
+ "String %s is not valid regular expression.", regex));
+ }
+
+ PatternConstraintImpl(final String regex, final Optional<String> description, final Optional<String> reference,
+ final String errorAppTag, final String errorMessage) {
this.regex = Preconditions.checkNotNull(regex, "regex must not be null.");
this.description = description.orNull();
this.reference = reference.orNull();
-
- // FIXME: Lookup better suitable error tag.
- errorAppTag = "invalid-regular-expression";
- // TODO: add erro message
- errorMessage = "";
+ this.errorAppTag = errorAppTag != null ? errorAppTag : "invalid-regular-expression";
+ this.errorMessage = errorMessage != null ? errorMessage : String.format(
+ "String %s is not valid regular expression.", regex);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((description == null) ? 0 : description.hashCode());
- result = prime * result + ((errorAppTag == null) ? 0 : errorAppTag.hashCode());
- result = prime * result + ((errorMessage == null) ? 0 : errorMessage.hashCode());
- result = prime * result + ((reference == null) ? 0 : reference.hashCode());
+ result = prime * result + Objects.hashCode(description);
+ result = prime * result + Objects.hashCode(errorAppTag);
+ result = prime * result + Objects.hashCode(errorMessage);
+ result = prime * result + Objects.hashCode(reference);
result = prime * result + regex.hashCode();
return result;
}
return false;
}
final PatternConstraintImpl other = (PatternConstraintImpl) obj;
- if (description == null) {
- if (other.description != null) {
- return false;
- }
- } else if (!description.equals(other.description)) {
+ if (!Objects.equals(description, other.description)) {
return false;
}
- if (errorAppTag == null) {
- if (other.errorAppTag != null) {
- return false;
- }
- } else if (!errorAppTag.equals(other.errorAppTag)) {
+ if (!Objects.equals(errorAppTag, other.errorAppTag)) {
return false;
}
- if (errorMessage == null) {
- if (other.errorMessage != null) {
- return false;
- }
- } else if (!errorMessage.equals(other.errorMessage)) {
+ if (!Objects.equals(errorMessage, other.errorMessage)) {
return false;
}
- if (reference == null) {
- if (other.reference != null) {
- return false;
- }
- } else if (!reference.equals(other.reference)) {
+ if (!Objects.equals(reference, other.reference)) {
return false;
}
- if (regex == null) {
- if (other.regex != null) {
- return false;
- }
- } else if (!regex.equals(other.regex)) {
+ if (!Objects.equals(regex, other.regex)) {
return false;
}
return true;