
org.beanfabrics.validation.ValidationState Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of beanfabrics-core Show documentation
Show all versions of beanfabrics-core Show documentation
Beanfabrics is a component framework for building Java desktop applications according to the Presentation Model Pattern with Swing.
/*
* Beanfabrics Framework Copyright (C) by Michael Karneim, beanfabrics.org
* Use is subject to license terms. See license.txt.
*/
package org.beanfabrics.validation;
/**
* The ValidationState
is the result of a call to
* {@link ValidationRule#validate()} and indicates that this rule has found some
* invalid state. It contains a human readable text message which usually is
* reported to the application user.
*
* @author Michael Karneim
*/
public class ValidationState {
private final String message;
/**
* Factory-method for creating a {@link ValidationState} from the specified
* message or null
if the message is null
.
*
* @param message String
* @return the ValidationState
if message
is not
* null
, otherwise returns null
*/
public static ValidationState create(String message) {
if (message == null) {
return null;
} else {
return new ValidationState(message);
}
}
/**
* Constructs a new instance with the given message.
*
* @param message the message text of this ValidationState
* @throws IllegalArgumentException when message is null
*/
public ValidationState(String message)
throws IllegalArgumentException {
if (message == null) {
throw new IllegalArgumentException("message==null");
}
this.message = message;
}
/**
* Returns the message for this instance.
*
* @return String
*/
public String getMessage() {
return message;
}
/**
* Returns true
when this instance is equal to the given
* object.
*
* @param other Object to compare this
instance to
* @return boolean true
if this instance and the given object
* are equal, else false
*/
@Override
public boolean equals(Object other) {
if (other == null) {
return false;
}
if (!other.getClass().equals(this.getClass())) {
return false;
}
ValidationState otherState = (ValidationState)other;
if (message == null && otherState.message == null) {
return true;
} else {
return (message != null && message.equals(otherState.message));
}
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + (message == null ? 0 : message.hashCode());
return hashCode;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy