/*
- * Copyright (C) 2016 - 2018 Free Software Foundation
+ * Copyright (C) 2016 - 2022 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.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.jcoreee.utils.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", nullable = false, updatable = 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
* @param addressbookUser User instance
*/
public UserAddressbook (final String addressbookName, final User addressbookUser) {
- // Call default constructor
+ // 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;
@Override
public int compareTo (final Addressbook addressbook) {
- // Checkparameter and return 0 if equal
+ // Check parameter and return 0 if equal
if (null == addressbook) {
// Should not happen
throw new NullPointerException("addressbook is null"); //NOI18N
- } else if (Objects.equals(this, addressbook)) {
- // Same object
+ } else if (addressbook.equals(this)) {
+ // Same object, below "expensive" code can be safely skipped
return 0;
}
// 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;
return false;
}
- final Addressbook other = (Addressbook) object;
+ final Addressbook addressbook = (Addressbook) object;
- if (!Objects.equals(this.getAddressbookName(), other.getAddressbookName())) {
+ if (!Objects.equals(this.getAddressbookId(), addressbook.getAddressbookId())) {
+ return false;
+ } else if (!Objects.equals(this.getAddressbookLastLocked(), addressbook.getAddressbookLastLocked())) {
+ return false;
+ } else if (!Objects.equals(this.getAddressbookLastLockedReason(), addressbook.getAddressbookLastLockedReason())) {
+ return false;
+ } else if (!Objects.equals(this.getAddressbookName(), addressbook.getAddressbookName())) {
return false;
- } else if (!Objects.equals(this.getAddressbookUser(), other.getAddressbookUser())) {
+ } else if (!Objects.equals(this.getAddressbookStatus(), addressbook.getAddressbookStatus())) {
+ return false;
+ } else if (!Objects.equals(this.getAddressbookUser(), addressbook.getAddressbookUser())) {
return false;
}
@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
public int hashCode () {
int hash = 7;
+ hash = 59 * hash + Objects.hashCode(this.getAddressbookId());
+ hash = 59 * hash + Objects.hashCode(this.getAddressbookLastLocked());
+ hash = 59 * hash + Objects.hashCode(this.getAddressbookLastLockedReason());
hash = 59 * hash + Objects.hashCode(this.getAddressbookName());
+ hash = 59 * hash + Objects.hashCode(this.getAddressbookStatus());
hash = 59 * hash + Objects.hashCode(this.getAddressbookUser());
return hash;