DocumentStateMetaData.java

package com.tradecloud.domain.configuration;

import com.tradecloud.domain.document.DocumentState;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.Objects;

@MappedSuperclass
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "DocumentStateMetaData")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class DocumentStateMetaData extends StateMetaData<DocumentState> implements Serializable, Comparable<DocumentStateMetaData> {

    private static final long serialVersionUID = 1L;

    @Enumerated(value = EnumType.STRING)
    @XmlAttribute
    @NotNull
    private DocumentState state;

    @Override
    public DocumentState getState() {
        return state;
    }

    @Override
    public void setState(DocumentState state) {
        this.state = state;
    }

    @Override
    public int compareTo(DocumentStateMetaData o) {
        return state.compareTo(o.getState());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof DocumentStateMetaData that)) return false;
        if (!super.equals(o)) return false;
        return getState() == that.getState();
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), getState());
    }

}