de.kaiserpfalzEdv.infopir.backend.db.dynamic.Accused.java Source code

Java tutorial

Introduction

Here is the source code for de.kaiserpfalzEdv.infopir.backend.db.dynamic.Accused.java

Source

/*
 * Copyright 2015 Kaiserpfalz EDV-Service, Roland T. Lichti
 *
 * 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 de.kaiserpfalzEdv.infopir.backend.db.dynamic;

import de.kaiserpfalzEdv.infopir.backend.HasCommonName;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Transient;
import javax.validation.constraints.Min;
import javax.validation.constraints.Size;
import java.io.Serializable;

/**
 * @author klenkes
 * @version 2015Q1
 * @since 06.09.15 23:00
 */
@Embeddable
public class Accused implements HasCommonName, Serializable {
    private static final long serialVersionUID = -8515620200200659766L;

    private Long memberNumber;
    private String surName = "";
    private String givenName = "";

    @Override
    @Transient
    public String getCommonName() {
        return surName + ", " + givenName;
    }

    @Column(name = "membernumber_", nullable = false, unique = true)
    @Min(0)
    public Long getMemberNumber() {
        return memberNumber;
    }

    public void setMemberNumber(final Long memberNumber) {
        this.memberNumber = memberNumber;
    }

    @Column(name = "surname_", length = 100, nullable = false)
    @Size(min = 1, max = 100)
    public String getSurName() {
        return surName;
    }

    public void setSurName(String surName) {
        this.surName = surName;
    }

    @Column(name = "givenname_", length = 100, nullable = false)
    @Size(min = 1, max = 100)
    public String getGivenName() {
        return givenName;
    }

    public void setGivenName(String givenName) {
        this.givenName = givenName;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        if (obj.getClass() != getClass()) {
            return false;
        }
        Accused rhs = (Accused) obj;
        return new EqualsBuilder().appendSuper(super.equals(obj)).append(this.memberNumber, rhs.getMemberNumber())
                .append(this.surName, rhs.getSurName()).append(this.givenName, rhs.getGivenName()).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().appendSuper(super.hashCode()).append(memberNumber).append(surName)
                .append(givenName).toHashCode();
    }
}