2 * Copyright (C) 2017, 2020 Free Software Foundation
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jfinancials.model.income;
19 import java.math.BigDecimal;
20 import java.util.Date;
21 import java.util.Objects;
22 import javax.persistence.Basic;
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.EnumType;
27 import javax.persistence.Enumerated;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.GenerationType;
30 import javax.persistence.Id;
31 import javax.persistence.JoinColumn;
32 import javax.persistence.OneToOne;
33 import javax.persistence.Table;
34 import javax.persistence.Temporal;
35 import javax.persistence.TemporalType;
36 import javax.persistence.Transient;
37 import org.mxchange.jcoreutils.Comparables;
38 import org.mxchange.jfinancials.model.income.interval.FinancialInterval;
39 import org.mxchange.jusercore.model.user.LoginUser;
40 import org.mxchange.jusercore.model.user.User;
43 * An entity for income data
45 * @author Roland Häder<roland@mxchange.org>
47 @Entity (name = "income")
48 @Table (name = "income")
49 @SuppressWarnings ("PersistenceUnitPresent")
50 public class FinancialIncome implements BillableIncome {
56 private static final long serialVersionUID = 173_587_690_625_524L;
59 * Income created timestamp
61 @Basic (optional = false)
62 @Temporal (TemporalType.TIMESTAMP)
63 @Column (name = "income_created", nullable = false, updatable = false)
64 private Date incomeCreated;
67 * Income enabled (default) or disabled (no longer receiving income but need
68 * to keep it for statistics).
70 @Basic (optional = false)
71 @Column (name = "income_enabled", nullable = false)
72 private Boolean incomeEnabled;
75 * Income id (primary key)
78 @GeneratedValue (strategy = GenerationType.IDENTITY)
79 @Column (name = "income_id", nullable = false, updatable = false)
80 private Long incomeId;
85 @Basic (optional = false)
86 @Column (name = "income_interval", nullable = false)
87 @Enumerated (EnumType.STRING)
88 private FinancialInterval incomeInterval;
91 * Income single amount
93 @Basic (optional = false)
94 @Column (name = "income_single_amount", nullable = false)
95 private BigDecimal incomeSingleAmount;
100 @Basic (optional = false)
101 @Column (name = "income_title", nullable = false)
102 private String incomeTitle;
105 * Income updated timestamp
107 @Temporal (TemporalType.TIMESTAMP)
108 @Column (name = "income_updated", insertable = false)
109 private Date incomeUpdated;
112 * Connected user account
114 @JoinColumn (name = "income_user_id", referencedColumnName = "user_id", nullable = false, updatable = false)
115 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
116 private User incomeUser;
119 * Default constructor
121 public FinancialIncome () {
125 * Constructor with all fields, except timestamps. These have to be set at a
128 * @param incomeTitle Income (type) title
129 * @param incomeSingleAmount Single amount
130 * @param incomeInterval Interval
131 * @param incomeUser Connected user
133 public FinancialIncome (final String incomeTitle, final BigDecimal incomeSingleAmount, final FinancialInterval incomeInterval, final User incomeUser) {
134 // Call default constructor
138 this.incomeTitle = incomeTitle;
139 this.incomeSingleAmount = incomeSingleAmount;
140 this.incomeInterval = incomeInterval;
141 this.incomeUser = incomeUser;
143 // Enable this income by default
144 this.incomeEnabled = Boolean.TRUE;
148 public int compareTo (final BillableIncome billableIncome) {
149 // Check parameter on null-reference and equality to this
150 if (null == billableIncome) {
152 throw new NullPointerException("billableIncome is null"); //NOI18N
153 } else if (billableIncome.equals(this)) {
159 final int comparators[] = {
160 // First compare title
161 this.getIncomeTitle().compareToIgnoreCase(billableIncome.getIncomeTitle()),
162 // ... then compare interval
163 this.getIncomeInterval().compareTo(billableIncome.getIncomeInterval()),
165 this.getIncomeSingleAmount().compareTo(billableIncome.getIncomeSingleAmount()),
167 this.getIncomeUser().compareTo(billableIncome.getIncomeUser())
171 final int comparison = Comparables.checkAll(comparators);
178 public boolean equals (final Object object) {
179 if (this == object) {
181 } else if (null == object) {
183 } else if (this.getClass() != object.getClass()) {
187 final BillableIncome other = (BillableIncome) object;
189 if (!Objects.equals(this.getIncomeTitle(), other.getIncomeTitle())) {
191 } else if (!Objects.equals(this.getIncomeId(), other.getIncomeId())) {
193 } else if (!Objects.equals(this.getIncomeUser(), other.getIncomeUser())) {
200 @SuppressWarnings ("ReturnOfDateField")
201 public Date getIncomeCreated () {
202 return this.incomeCreated;
206 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
207 public void setIncomeCreated (Date incomeCreated) {
208 this.incomeCreated = incomeCreated;
212 public Boolean getIncomeEnabled () {
213 return this.incomeEnabled;
217 public void setIncomeEnabled (Boolean incomeEnabled) {
218 this.incomeEnabled = incomeEnabled;
222 public Long getIncomeId () {
223 return this.incomeId;
227 public void setIncomeId (final Long incomeId) {
228 this.incomeId = incomeId;
232 public FinancialInterval getIncomeInterval () {
233 return this.incomeInterval;
237 public void setIncomeInterval (final FinancialInterval incomeInterval) {
238 this.incomeInterval = incomeInterval;
242 public BigDecimal getIncomeSingleAmount () {
243 return this.incomeSingleAmount;
247 public void setIncomeSingleAmount (final BigDecimal incomeSingleAmount) {
248 this.incomeSingleAmount = incomeSingleAmount;
252 public String getIncomeTitle () {
253 return this.incomeTitle;
257 public void setIncomeTitle (String incomeTitle) {
258 this.incomeTitle = incomeTitle;
262 @SuppressWarnings ("ReturnOfDateField")
263 public Date getIncomeUpdated () {
264 return this.incomeUpdated;
268 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
269 public void setIncomeUpdated (Date incomeUpdated) {
270 this.incomeUpdated = incomeUpdated;
274 public User getIncomeUser () {
275 return this.incomeUser;
279 public void setIncomeUser (User incomeUser) {
280 this.incomeUser = incomeUser;
284 public int hashCode () {
287 hash = 29 * hash + Objects.hashCode(this.getIncomeId());
288 hash = 29 * hash + Objects.hashCode(this.getIncomeTitle());
289 hash = 29 * hash + Objects.hashCode(this.getIncomeUser());