+++ /dev/null
-/*
- * Copyright (C) 2017 - 2020 Free Software Foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jfinancials.model.receipt;
-
-import java.io.Serializable;
-import java.text.MessageFormat;
-import java.util.Objects;
-
-/**
- * A utilities class for receipts
- *
- * @author Roland Häder<roland@mxchange.org>
- */
-public class Receipts implements Serializable {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 2_867_938_676_165_401L;
-
- /**
- * Compares both receipt instances. This method returns -1 if second
- * instance is null.
- * <p>
- * @param receipt1 BillableReceipt instance 1
- * @param receipt2 BillableReceipt instance 2
- * <p>
- * @return Comparison value
- */
- public static int compare (final BillableReceipt receipt1, final BillableReceipt receipt2) {
- // Check euqality, then at least first must be given
- if (Objects.equals(receipt1, receipt2)) {
- // Both are same
- return 0;
- } else if (null == receipt1) {
- // First is null
- return -1;
- } else if (null == receipt2) {
- // Second is null
- return 1;
- }
-
- // Invoke compareTo() method
- return receipt1.compareTo(receipt2);
- }
-
- /**
- * Copies all fields from source receipt to target receipt.
- * <p>
- * @param sourceReceipt Source receipt instance
- * @param targetReceipt Target Receipt instance
- */
- public static void copyReceiptData (final BillableReceipt sourceReceipt, final BillableReceipt targetReceipt) {
- // Both should not be null
- if (null == sourceReceipt) {
- // Throw NPE
- throw new NullPointerException("sourceReceipt is null"); //NOI18N
- } else if (null == targetReceipt) {
- // Throw NPE
- throw new NullPointerException("targetReceipt is null"); //NOI18N
- } else if (Objects.equals(sourceReceipt, targetReceipt)) {
- // Is exactly the same!
- throw new IllegalArgumentException("sourcerReceipt and targetReceipt are the same."); //NOI18N
- }
-
- // Copy all fields
- targetReceipt.setReceiptBarCodeNumber(sourceReceipt.getReceiptBarCodeNumber());
- targetReceipt.setReceiptBonusCard(sourceReceipt.getReceiptBonusCard());
- targetReceipt.setReceiptBranchOffice(sourceReceipt.getReceiptBranchOffice());
- targetReceipt.setReceiptCreated(sourceReceipt.getReceiptCreated());
- targetReceipt.setReceiptId(sourceReceipt.getReceiptId());
- targetReceipt.setReceiptIssued(sourceReceipt.getReceiptIssued());
- targetReceipt.setReceiptNumber(sourceReceipt.getReceiptNumber());
- targetReceipt.setReceiptPaymentType(sourceReceipt.getReceiptPaymentType());
- targetReceipt.setReceiptRegisterNumber(sourceReceipt.getReceiptRegisterNumber());
- targetReceipt.setReceiptSellerEmployee(sourceReceipt.getReceiptSellerEmployee());
- targetReceipt.setReceiptSequenceNumber(sourceReceipt.getReceiptSequenceNumber());
- targetReceipt.setReceiptTransactionNumber(sourceReceipt.getReceiptTransactionNumber());
- targetReceipt.setReceiptUpdated(sourceReceipt.getReceiptUpdated());
- targetReceipt.setReceiptUser(sourceReceipt.getReceiptUser());
- }
-
- /**
- * Checks whether both receipts are the same, means not true entity equality
- * but if the receipt in general terms does already exist. A pre-check on
- * entity equality is however performed to avoid below much longer code.
- * <p>
- * @param receipt1 BillableReceipt instance 1
- * @param receipt2 BillableReceipt instance 2
- * <p>
- * @return Whether both receipts are the same (not instances)
- */
- public static boolean isSameReceipt (final BillableReceipt receipt1, final BillableReceipt receipt2) {
- // Pre-compare both as entities (same id)
- if (Objects.equals(receipt1, receipt2)) {
- // Same entity (with id number)
- return true;
- }
-
- // Validate parameter
- if (null == receipt1) {
- // Throw NPE
- throw new NullPointerException("receipt1 is null"); //NOI18N
- } else if ((receipt1.getReceiptId() instanceof Long) && (receipt1.getReceiptId() < 1)) {
- // Throw IAE
- throw new IllegalArgumentException(MessageFormat.format("receipt1.receiptId={0} is not valid.", receipt1.getReceiptId())); //NOI18N
- } else if (receipt1.getReceiptBranchOffice() == null) {
- // Throw NPE
- throw new NullPointerException("receipt1.receiptBranchOffice is null"); //NOI18N
- } else if (receipt1.getReceiptBranchOffice().getBranchId() == null) {
- // Throw NPE
- throw new NullPointerException("receipt1.receiptBranchOffice.branchId is null"); //NOI18N
- } else if (receipt1.getReceiptBranchOffice().getBranchId() < 1) {
- // Throw NPE
- throw new NullPointerException(MessageFormat.format("receipt1.receiptBranchOffice.branchId={0} is not valid", receipt1.getReceiptBranchOffice().getBranchId())); //NOI18N
- } else if ((receipt1.getReceiptNumber() != null) && (receipt1.getReceiptNumber().isEmpty())) {
- // Throw IAE
- throw new IllegalArgumentException("receipt1.receiptNumber is empty."); //NOI18N
- } else if (receipt1.getReceiptPaymentType() == null) {
- // Throw NPE
- throw new NullPointerException("receipt1.receiptPaymentType is null"); //NOI18N
- } else if (null == receipt2) {
- // Throw NPE
- throw new NullPointerException("receipt2 is null"); //NOI18N
- } else if ((receipt2.getReceiptId() instanceof Long) && (receipt2.getReceiptId() < 1)) {
- // Throw IAE
- throw new IllegalArgumentException(MessageFormat.format("receipt2.receiptId={0} is not valid.", receipt2.getReceiptId())); //NOI18N
- } else if (receipt2.getReceiptBranchOffice() == null) {
- // Throw NPE
- throw new NullPointerException("receipt2.receiptBranchOffice is null"); //NOI18N
- } else if (receipt2.getReceiptBranchOffice().getBranchId() == null) {
- // Throw NPE
- throw new NullPointerException("receipt2.receiptBranchOffice.branchId is null"); //NOI18N
- } else if (receipt2.getReceiptBranchOffice().getBranchId() < 1) {
- // Throw NPE
- throw new NullPointerException(MessageFormat.format("receipt2.receiptBranchOffice.branchId={0} is not valid", receipt2.getReceiptBranchOffice().getBranchId())); //NOI18N
- } else if ((receipt2.getReceiptNumber() != null) && (receipt2.getReceiptNumber().isEmpty())) {
- // Throw IAE
- throw new IllegalArgumentException("receipt2.receiptNumber is empty."); //NOI18N
- } else if (receipt2.getReceiptPaymentType() == null) {
- // Throw NPE
- throw new NullPointerException("receipt2.receiptPaymentType is null"); //NOI18N
- }
-
- // Now check all individually
- if (!Objects.equals(receipt1.getReceiptBranchOffice(), receipt2.getReceiptBranchOffice())) {
- // Other branch offices
- return false;
- } else if (!Objects.equals(receipt1.getReceiptNumber(), receipt2.getReceiptNumber())) {
- // Other receipt number
- return false;
- } else if (!Objects.equals(receipt1.getReceiptIssued(), receipt2.getReceiptIssued())) {
- // Other issue date
- return false;
- } else if (!Objects.equals(receipt1.getReceiptUser(), receipt2.getReceiptUser())) {
- // Other user (unlikely to happen
- return false;
- }
-
- // Maybe same receipt!
- return true;
- }
-
- /**
- * Private default constructor
- */
- private Receipts () {
- // Utilities don't have instances
- }
-
-}