/*
- * Copyright (C) 2017 - 2020 Free Software Foundation
+ * Copyright (C) 2017 - 2024 Free Software Foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
package org.mxchange.jfinancials.model.income;
import java.math.BigDecimal;
+import java.text.MessageFormat;
import java.util.Date;
import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
-import org.mxchange.jcoreutils.Comparables;
+import org.mxchange.jcoreutils.comparable.ComparableUtils;
import org.mxchange.jfinancials.model.income.interval.FinancialInterval;
import org.mxchange.jusercore.model.user.LoginUser;
import org.mxchange.jusercore.model.user.User;
@Transient
private static final long serialVersionUID = 173_587_690_625_524L;
+ /**
+ * Income enabled (default) or disabled (no longer receiving income but need
+ * to keep it for statistics).
+ */
+ @Basic (optional = false)
+ @Column (name = "income_enabled", nullable = false)
+ private Boolean incomeEnabled;
+
/**
* Income created timestamp
*/
@Basic (optional = false)
@Temporal (TemporalType.TIMESTAMP)
- @Column (name = "income_created", nullable = false, updatable = false)
- private Date incomeCreated;
+ @Column (name = "income_entry_created", nullable = false, updatable = false)
+ private Date incomeEntryCreated;
/**
- * Income enabled (default) or disabled (no longer receiving income but need
- * to keep it for statistics).
+ * Income updated timestamp
*/
- @Basic (optional = false)
- @Column (name = "income_enabled", nullable = false)
- private Boolean incomeEnabled;
+ @Temporal (TemporalType.TIMESTAMP)
+ @Column (name = "income_entry_updated", insertable = false)
+ private Date incomeEntryUpdated;
/**
* Income id (primary key)
@Column (name = "income_title", nullable = false)
private String incomeTitle;
- /**
- * Income updated timestamp
- */
- @Temporal (TemporalType.TIMESTAMP)
- @Column (name = "income_updated", insertable = false)
- private Date incomeUpdated;
-
/**
* Connected user account
*/
* @param incomeSingleAmount Single amount
* @param incomeInterval Interval
* @param incomeUser Connected user
+ * @param incomeEnabled Whether this income is enabled
*/
- public FinancialIncome (final String incomeTitle, final BigDecimal incomeSingleAmount, final FinancialInterval incomeInterval, final User incomeUser) {
- // Call default constructor
+ public FinancialIncome (final String incomeTitle, final BigDecimal incomeSingleAmount, final FinancialInterval incomeInterval, final User incomeUser, final Boolean incomeEnabled) {
+ // Invoke default constructor
this();
+ // Validate all parameter
+ if (null == incomeEnabled) {
+ // Throw NPE
+ throw new NullPointerException("incomeEnabled is null"); //NOI18N
+ } else if (null == incomeInterval) {
+ // Throw NPE again
+ throw new NullPointerException("incomeInterval is null"); //NOI18N
+ } else if (null == incomeSingleAmount) {
+ // Throw NPE again
+ throw new NullPointerException("incomeSingleAmount is null"); //NOI18N
+ } else if (incomeSingleAmount.floatValue() < 0.0f) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("incomeSingleAmount={0} is not valid.", incomeSingleAmount)); //NOI18N
+ } else if (null == incomeTitle) {
+ // Throw NPE
+ throw new NullPointerException("incomeTitle is null"); //NOI18N
+ } else if (incomeTitle.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("incomeTitle is empty"); //NOI18N
+ } else if (null == incomeUser) {
+ // Throw NPE
+ throw new NullPointerException("incomeUser is null"); //NOI18N
+ } else if (incomeUser.getUserId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("incomeUser.userId is null"); //NOI18N
+ } else if (incomeUser.getUserId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("incomeUser.userId={0} is not valid.", incomeUser.getUserId())); //NOI18N
+ }
+
// Set all fields
this.incomeTitle = incomeTitle;
this.incomeSingleAmount = incomeSingleAmount;
this.incomeInterval = incomeInterval;
this.incomeUser = incomeUser;
-
- // Enable this income by default
- this.incomeEnabled = Boolean.TRUE;
+ this.incomeEnabled = incomeEnabled;
}
@Override
};
// Check all values
- final int comparison = Comparables.checkAll(comparators);
+ final int comparison = ComparableUtils.checkAll(comparators);
// Return value
return comparison;
return false;
}
- final BillableIncome other = (BillableIncome) object;
+ final BillableIncome income = (BillableIncome) object;
- if (!Objects.equals(this.getIncomeTitle(), other.getIncomeTitle())) {
+ if (!Objects.equals(this.getIncomeEnabled(), income.getIncomeEnabled())) {
+ return false;
+ } else if (!Objects.equals(this.getIncomeId(), income.getIncomeId())) {
+ return false;
+ } else if (!Objects.equals(this.getIncomeInterval(), income.getIncomeInterval())) {
return false;
- } else if (!Objects.equals(this.getIncomeId(), other.getIncomeId())) {
+ } else if (!Objects.equals(this.getIncomeSingleAmount(), income.getIncomeSingleAmount())) {
return false;
- } else if (!Objects.equals(this.getIncomeUser(), other.getIncomeUser())) {
+ } else if (!Objects.equals(this.getIncomeTitle(), income.getIncomeTitle())) {
+ return false;
+ } else if (!Objects.equals(this.getIncomeUser(), income.getIncomeUser())) {
return false;
}
+
return true;
}
+ @Override
+ public Boolean getIncomeEnabled () {
+ return this.incomeEnabled;
+ }
+
+ @Override
+ public void setIncomeEnabled (Boolean incomeEnabled) {
+ this.incomeEnabled = incomeEnabled;
+ }
+
@Override
@SuppressWarnings ("ReturnOfDateField")
- public Date getIncomeCreated () {
- return this.incomeCreated;
+ public Date getIncomeEntryCreated () {
+ return this.incomeEntryCreated;
}
@Override
@SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setIncomeCreated (Date incomeCreated) {
- this.incomeCreated = incomeCreated;
+ public void setIncomeEntryCreated (Date incomeEntryCreated) {
+ this.incomeEntryCreated = incomeEntryCreated;
}
@Override
- public Boolean getIncomeEnabled () {
- return this.incomeEnabled;
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getIncomeEntryUpdated () {
+ return this.incomeEntryUpdated;
}
@Override
- public void setIncomeEnabled (Boolean incomeEnabled) {
- this.incomeEnabled = incomeEnabled;
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setIncomeEntryUpdated (Date incomeEntryUpdated) {
+ this.incomeEntryUpdated = incomeEntryUpdated;
}
@Override
this.incomeTitle = incomeTitle;
}
- @Override
- @SuppressWarnings ("ReturnOfDateField")
- public Date getIncomeUpdated () {
- return this.incomeUpdated;
- }
-
- @Override
- @SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setIncomeUpdated (Date incomeUpdated) {
- this.incomeUpdated = incomeUpdated;
- }
-
@Override
public User getIncomeUser () {
return this.incomeUser;
public int hashCode () {
int hash = 3;
+ hash = 29 * hash + Objects.hashCode(this.getIncomeEnabled());
hash = 29 * hash + Objects.hashCode(this.getIncomeId());
+ hash = 29 * hash + Objects.hashCode(this.getIncomeInterval());
+ hash = 29 * hash + Objects.hashCode(this.getIncomeSingleAmount());
hash = 29 * hash + Objects.hashCode(this.getIncomeTitle());
hash = 29 * hash + Objects.hashCode(this.getIncomeUser());