com.baziaking.blackjack.domain.model.Transaction.java Source code

Java tutorial

Introduction

Here is the source code for com.baziaking.blackjack.domain.model.Transaction.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.baziaking.blackjack.domain.model;

import com.baziaking.blackjack.domain.enumeration.TransactionType;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
import java.util.Objects;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author arahis
 */
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Transaction {

    private long transactionId;
    private long accountId;
    private TransactionType type;
    private long cashTransfered = 0;

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd,HH:00", timezone = "CET")
    private Date date = new Date();

    @XmlTransient
    private Account account;

    public Transaction() {
    }

    public long getTransactionId() {
        return transactionId;
    }

    public Account getAccount() {
        return account;
    }

    public void setTransactionId(long transactionId) {
        this.transactionId = transactionId;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public long getAccountId() {
        return accountId;
    }

    public void setAccountId(long accountId) {
        this.accountId = accountId;
    }

    public void setAccount(Account account) {
        this.account = account;
    }

    public TransactionType getType() {
        return type;
    }

    public void setType(TransactionType type) {
        this.type = type;
    }

    public Date getDate() {
        return date;
    }

    public void setCashTransfered(long cashTransfered) {
        this.cashTransfered = cashTransfered;
    }

    public long getCashTransfered() {
        return cashTransfered;
    }

    @Override
    public String toString() {
        return "Transaction{" + "transactionId=" + transactionId + ", accountId=" + accountId + ", cashTransfered="
                + cashTransfered + ", type=" + type + ", date=" + date + ", account=" + account + '}';
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 17 * hash + (int) (this.transactionId ^ (this.transactionId >>> 32));
        hash = 17 * hash + (int) (this.accountId ^ (this.accountId >>> 32));
        hash = 17 * hash + (int) (this.cashTransfered ^ (this.cashTransfered >>> 32));
        hash = 17 * hash + Objects.hashCode(this.type);
        hash = 17 * hash + Objects.hashCode(this.date);
        hash = 17 * hash + Objects.hashCode(this.account);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Transaction other = (Transaction) obj;
        if (this.transactionId != other.transactionId) {
            return false;
        }
        if (this.accountId != other.accountId) {
            return false;
        }
        if (this.cashTransfered != other.cashTransfered) {
            return false;
        }
        if (this.type != other.type) {
            return false;
        }
        if (!Objects.equals(this.date, other.date)) {
            return false;
        }
        if (!Objects.equals(this.account, other.account)) {
            return false;
        }
        return true;
    }

}