*/
package org.mxchange.jaddressbook.model.addressbook;
+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.apache.commons.lang3.StringUtils;
import org.mxchange.jaddressbook.model.addressbook.status.AddressbokStatus;
-import org.mxchange.jcoreutils.Comparables;
+import org.mxchange.jcoreutils.comparable.ComparableUtils;
+import org.mxchange.jcoreutils.enums.EnumUtils;
import org.mxchange.jusercore.model.user.LoginUser;
import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.utils.UserUtils;
/**
* A POJO for user address books
*/
@Basic (optional = false)
@Temporal (value = TemporalType.TIMESTAMP)
- @Column (name = "addressbook_created", updatable = false, nullable = false)
- private Date addressbookCreated;
+ @Column (name = "addressbook_entry_created", updatable = false, nullable = false)
+ private Date addressbookEntryCreated;
+
+ /**
+ * When this address book has been created
+ */
+ @Temporal (value = TemporalType.TIMESTAMP)
+ @Column (name = "addressbook_entry_updated", insertable = false, nullable = false)
+ private Date addressbookEntryUpdated;
/**
* Id number
@Column (name = "addressbook_status", nullable = false, length = 10)
private AddressbokStatus addressbookStatus;
- /**
- * When this address book has been created
- */
- @Temporal (value = TemporalType.TIMESTAMP)
- @Column (name = "addressbook_updated", insertable = false, nullable = false)
- private Date addressbookUpdated;
-
/**
* Connection to "users" table
*/
// Invoke default constructor
this();
+ // Check all parameters
+ if (null == addressbookName) {
+ // Throw NPE
+ throw new NullPointerException("Parameter 'addressbookName' is null"); //NOI18N
+ } else if (addressbookName.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("Parameter 'addressbookName' is empty"); //NOI18N
+ } else if (null == addressbookUser) {
+ // Throw NPE again
+ throw new NullPointerException("Parameter 'addressbookUser' is null"); //NOI18N
+ } else if (addressbookUser.getUserId() == null) {
+ // Throw it again
+ throw new NullPointerException("addressbookUser.userId is null"); //NOI18N
+ } else if (addressbookUser.getUserId() < 1) {
+ // Throw IAE again
+ throw new IllegalArgumentException(MessageFormat.format("addressbookUser.userId={0} is invalid", addressbookUser.getUserId())); //NOI18N
+ }
+
// Set name and user instance
this.addressbookName = addressbookName;
this.addressbookUser = addressbookUser;
// All comparators
final int comparators[] = {
// First name ...
- this.getAddressbookName().compareToIgnoreCase(addressbook.getAddressbookName()),
+ StringUtils.compare(this.getAddressbookName(), addressbook.getAddressbookName()),
// ... status
- this.getAddressbookStatus().compareTo(addressbook.getAddressbookStatus()),
+ EnumUtils.compare(this.getAddressbookStatus(), addressbook.getAddressbookStatus()),
// .. then user
- this.getAddressbookUser().compareTo(addressbook.getAddressbookUser())
+ UserUtils.compare(this.getAddressbookUser(), addressbook.getAddressbookUser())
};
// Check all values
- final int comparison = Comparables.checkAll(comparators);
+ final int comparison = ComparableUtils.checkAll(comparators);
// Return value
return comparison;
@Override
@SuppressWarnings ("ReturnOfDateField")
- public Date getAddressbookCreated () {
- return this.addressbookCreated;
+ public Date getAddressbookEntryCreated () {
+ return this.addressbookEntryCreated;
+ }
+
+ @Override
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setAddressbookEntryCreated (final Date addressbookEntryCreated) {
+ this.addressbookEntryCreated = addressbookEntryCreated;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getAddressbookEntryUpdated () {
+ return this.addressbookEntryUpdated;
}
@Override
@SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setAddressbookCreated (final Date addressbookCreated) {
- this.addressbookCreated = addressbookCreated;
+ public void setAddressbookEntryUpdated (final Date addressbookEntryUpdated) {
+ this.addressbookEntryUpdated = addressbookEntryUpdated;
}
@Override
this.addressbookStatus = addressbookStatus;
}
- @Override
- @SuppressWarnings ("ReturnOfDateField")
- public Date getAddressbookUpdated () {
- return this.addressbookUpdated;
- }
-
- @Override
- @SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setAddressbookUpdated (final Date addressbookUpdated) {
- this.addressbookUpdated = addressbookUpdated;
- }
-
@Override
public User getAddressbookUser () {
return this.addressbookUser;