Message.java
/*
* Copyright 2005-2025 the original author or authors.
*
* 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 org.openwms.values;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import java.io.Serializable;
import java.util.Objects;
/**
* A Message can be used to store useful information about errors or events.
*
* @author Heiko Scherrer
*/
@Embeddable
public class Message implements Serializable {
/** String used to separate messageNo and messageText in toString. */
public static final String SEPARATOR = " :: ";
/** Message number. */
@Column(name = "C_MESSAGE_NO")
private Integer messageNo;
/** Message description text. */
@Column(name = "C_MESSAGE_TEXT")
private String messageText;
/*~ ----------------------------- constructors ------------------- */
/**
* Dear JPA...
*/
protected Message() {
}
/**
* Create a new {@code Message}.
*
* @param messageNo The message number
* @param messageText The message text
*/
public Message(int messageNo, String messageText) {
this.messageNo = messageNo;
this.messageText = messageText;
}
/**
* Create a new {@code Message}.
*
* @param messageText The message text
*/
public Message(String messageText) {
this.messageText = messageText;
}
/*~ ----------------------------- methods ------------------- */
/**
* Return the message number.
*
* @return The message number
*/
public Integer getMessageNo() {
return messageNo;
}
/**
* Return the message text.
*
* @return The message text
*/
public String getMessageText() {
return messageText;
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Message message = (Message) o;
return Objects.equals(messageNo, message.messageNo) && Objects.equals(messageText, message.messageText);
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hash(messageNo, messageText);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return messageNo + SEPARATOR + messageText;
}
}