PaymentReference.java

package com.tradecloud.domain.model.deal;

import org.apache.commons.lang.Validate;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import java.io.Serializable;

@Embeddable
public class PaymentReference implements Serializable {

    @Column(name = "payment_reference")
    String reference;

    /**
     * for JPA use only.
     */
    public PaymentReference() {
    }

    public static PaymentReference valueOf(String reference) {
        Validate.notEmpty(reference, "payment reference may not be null or empty.");
        return new PaymentReference(reference);
    }

    private PaymentReference(String reference) {
        this.reference = reference;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;

        PaymentReference that = (PaymentReference) o;

        if (reference != null ? !reference.equals(that.reference) : that.reference != null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        return reference != null ? reference.hashCode() : 0;
    }

    public String getReference() {
        return reference;
    }

    @Override
    public String toString() {
        return "PaymentReference{" +
                "reference='" + reference + '\'' +
                '}';
    }
}