import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
+import org.apache.commons.lang3.StringUtils;
import org.mxchange.jcontacts.model.contact.Contact;
import org.mxchange.jcontacts.model.contact.UserContact;
+import org.mxchange.jcoreee.utils.Comparables;
import org.mxchange.jcustomercore.model.customer.status.CustomerAccountStatus;
/**
)
@NamedQueries (
{
- @NamedQuery (name = "AllCustomers", query = "SELECT c FROM customer AS c ORDER BY c.customerId ASC"),
- @NamedQuery (name = "SearchCustomerByNumber", query = "SELECT c FROM customer AS c WHERE c.customerNumber = :customerNumber"),
+ @NamedQuery (name = "AllCustomers", query = "SELECT c FROM customer AS c ORDER BY c.customerId ASC")
}
)
@SuppressWarnings ("PersistenceUnitPresent")
* Constructor with account status, contact instance and customer number
* <p>
* @param customerAccountStatus Account status (Call-agents may only call
- * unlocked accounts)
- * @param customerContact Contact instance
- * @param customerNumber Customer number
+ * unlocked accounts)
+ * @param customerContact Contact instance
+ * @param customerNumber Customer number
*/
public ContactCustomer (final CustomerAccountStatus customerAccountStatus, final Contact customerContact, final String customerNumber) {
// Call other constructor
}
@Override
- public void copyAll (final Customer customer) {
- // Copy all supported fields
- this.setCustomerAccountStatus(customer.getCustomerAccountStatus());
- this.setCustomerContact(customer.getCustomerContact());
- this.setCustomerCreated(customer.getCustomerCreated());
- this.setCustomerId(customer.getCustomerId());
- this.setCustomerLastLocked(customer.getCustomerLastLocked());
- this.setCustomerLastLockedReason(customer.getCustomerLastLockedReason());
- this.setCustomerNumber(customer.getCustomerNumber());
+ public int compareTo (final Customer customer) {
+ // For performance reasons
+ if (null == customer) {
+ // Should not happen
+ throw new NullPointerException("customer is null"); //NOI18N
+ } else if (Objects.equals(this, customer)) {
+ // Same object
+ return 0;
+ }
+
+ // Init comparators
+ final int comparators[] = {
+ // First check contact instance
+ this.getCustomerContact().compareTo(customer.getCustomerContact()),
+ // ... then customer number
+ this.getCustomerNumber().compareTo(customer.getCustomerNumber()),
+ // ... last is confirmation key
+ StringUtils.compare(this.getCustomerConfirmKey(), customer.getCustomerConfirmKey())
+ };
+
+ // Check all values
+ final int comparison = Comparables.checkAll(comparators);
+
+ // Return value
+ return comparison;
}
@Override
return true;
}
- @Override
- public int hashCode () {
- int hash = 7;
-
- hash = 53 * hash + Objects.hashCode(this.getCustomerContact());
- hash = 53 * hash + Objects.hashCode(this.getCustomerId());
- hash = 53 * hash + Objects.hashCode(this.getCustomerNumber());
-
- return hash;
- }
-
@Override
public CustomerAccountStatus getCustomerAccountStatus () {
return this.customerAccountStatus;
this.customerUpdated = customerUpdated;
}
+ @Override
+ public int hashCode () {
+ int hash = 7;
+
+ hash = 53 * hash + Objects.hashCode(this.getCustomerContact());
+ hash = 53 * hash + Objects.hashCode(this.getCustomerId());
+ hash = 53 * hash + Objects.hashCode(this.getCustomerNumber());
+
+ return hash;
+ }
+
}
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-public interface Customer extends Serializable {
-
- /**
- * Copies all attributes from other customer object to this
- * <p>
- * @param customer Source instance
- */
- void copyAll (final Customer customer);
+public interface Customer extends Comparable<Customer>, Serializable {
/**
* Getter for contact instance
+++ /dev/null
-/*
- * Copyright (C) 2016 - 2018 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jcustomercore.utils;
-
-import java.security.SecureRandom;
-import java.text.MessageFormat;
-import java.util.Random;
-import org.apache.commons.lang3.StringUtils;
-
-/**
- * Customer utilities
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public class CustomerUtils {
-
- /**
- * Random number generator
- */
- private static final Random RANDOM_NUMBER_GENERATOR;
-
- /**
- * Static initializer
- */
- static {
- // Init RNG
- RANDOM_NUMBER_GENERATOR = new SecureRandom();
- }
-
- /**
- * Generates a random customer number with some dashes in it
- * <p>
- * @param totalLength Length of the number
- * @param blockSize Block size
- * @param separator Seperator
- * <p>
- * @return Generated customer number
- */
- public static String generateCustomerNumber (final int totalLength, final short blockSize, final char separator) {
- // All parameters must be set
- if (totalLength < 5) {
- // Total length is to short
- throw new IllegalArgumentException(MessageFormat.format("Total length of{0} characters is to short (5 minimum)", totalLength)); //NOI18N
- } else if (blockSize < 3) {
- // 3 charcters is minimum
- throw new IllegalArgumentException(MessageFormat.format("Block size of {0} characters is to short (3 minimum)", blockSize)); //NOI18N
- }
-
- // Init number
- StringBuilder customerNumber = new StringBuilder(totalLength);
-
- // Calculate total blockas
- long totalBlocks = Math.round(totalLength / (blockSize - 1) - 0.5) - 1;
-
- // Generate customer number
- for (int i = 0; i < totalBlocks; i++) {
- // Fill it up with leading zeros and append it + separator character
- customerNumber.append(genrateBlock(blockSize)).append(separator);
- }
-
- // Calculate remaining charcters
- long remain = totalLength - (blockSize + 1) * totalBlocks;
-
- // Generate new block and append it
- customerNumber.append(genrateBlock((short) remain));
-
- // Return finished number
- return customerNumber.toString();
- }
-
- /**
- * Generates a block of numbers with leading zeros, if the random number is
- * shorter than block size
- * <p>
- * @param blockSize Block size
- * <p>
- * @return Generated block
- */
- private static String genrateBlock (final short blockSize) {
- // Generate random number
- int num = RANDOM_NUMBER_GENERATOR.nextInt((int) Math.pow(10, blockSize));
-
- // Generate "block" and return it
- return StringUtils.leftPad(String.valueOf(num), blockSize, '0');
- }
-
- /**
- * No constructors for utiltity classes
- */
- private CustomerUtils () {
- }
-
-}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2018 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcustomercore.utils;
+
+import java.security.SecureRandom;
+import java.text.MessageFormat;
+import java.util.Random;
+import org.apache.commons.lang3.StringUtils;
+import org.mxchange.jcustomercore.model.customer.Customer;
+
+/**
+ * Customer utilities
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class Customers {
+
+ /**
+ * Random number generator
+ */
+ private static final Random RANDOM_NUMBER_GENERATOR;
+
+ /**
+ * Static initializer
+ */
+ static {
+ // Init RNG
+ RANDOM_NUMBER_GENERATOR = new SecureRandom();
+ }
+
+ /**
+ * Copies all fields from source customer to target customer instance.
+ * <p>
+ * @param targetCustomer Target customer instance 1
+ * @param sourceCustomer Source customer instance 2
+ * <p>
+ * @throws NullPointerException If one parameter is null
+ */
+ public static void copyAll (final Customer targetCustomer, final Customer sourceCustomer) {
+ // Check both parameter
+ if (null == targetCustomer) {
+ // Throw NPE
+ throw new NullPointerException("targetCustomer is null"); //NOI18N
+ } else if (null == sourceCustomer) {
+ // Throw NPE
+ throw new NullPointerException("sourceCustomer is null"); //NOI18N
+ }
+
+ // Copy all fields
+ targetCustomer.setCustomerAccountStatus(sourceCustomer.getCustomerAccountStatus());
+ targetCustomer.setCustomerContact(sourceCustomer.getCustomerContact());
+ targetCustomer.setCustomerCreated(sourceCustomer.getCustomerCreated());
+ targetCustomer.setCustomerId(sourceCustomer.getCustomerId());
+ targetCustomer.setCustomerLastLocked(sourceCustomer.getCustomerLastLocked());
+ targetCustomer.setCustomerLastLockedReason(sourceCustomer.getCustomerLastLockedReason());
+ targetCustomer.setCustomerNumber(sourceCustomer.getCustomerNumber());
+ }
+
+ /**
+ * Generates a random customer number with some dashes in it
+ * <p>
+ * @param totalLength Length of the number
+ * @param blockSize Block size
+ * @param separator Separator
+ * <p>
+ * @return Generated customer number
+ */
+ public static String generateCustomerNumber (final int totalLength, final short blockSize, final char separator) {
+ // All parameters must be set
+ if (totalLength < 5) {
+ // Total length is to short
+ throw new IllegalArgumentException(MessageFormat.format("Total length of{0} characters is to short (5 minimum)", totalLength)); //NOI18N
+ } else if (blockSize < 3) {
+ // 3 charcters is minimum
+ throw new IllegalArgumentException(MessageFormat.format("Block size of {0} characters is to short (3 minimum)", blockSize)); //NOI18N
+ }
+
+ // Init number
+ StringBuilder customerNumber = new StringBuilder(totalLength);
+
+ // Calculate total blockas
+ long totalBlocks = Math.round(totalLength / (blockSize - 1) - 0.5) - 1;
+
+ // Generate customer number
+ for (int i = 0; i < totalBlocks; i++) {
+ // Fill it up with leading zeros and append it + separator character
+ customerNumber.append(genrateBlock(blockSize)).append(separator);
+ }
+
+ // Calculate remaining charcters
+ long remain = totalLength - (blockSize + 1) * totalBlocks;
+
+ // Generate new block and append it
+ customerNumber.append(genrateBlock((short) remain));
+
+ // Return finished number
+ return customerNumber.toString();
+ }
+
+ /**
+ * Generates a block of numbers with leading zeros, if the random number is
+ * shorter than block size
+ * <p>
+ * @param blockSize Block size
+ * <p>
+ * @return Generated block
+ */
+ private static String genrateBlock (final short blockSize) {
+ // Generate random number
+ int num = RANDOM_NUMBER_GENERATOR.nextInt((int) Math.pow(10, blockSize));
+
+ // Generate "block" and return it
+ return StringUtils.leftPad(String.valueOf(num), blockSize, '0');
+ }
+
+ /**
+ * No constructors for utility classes
+ */
+ private Customers () {
+ }
+
+}