From cfea5c35700bae96a73bb5c271a8779e6741c1fb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 20 Sep 2017 22:15:55 +0200 Subject: [PATCH] Continued: - added event which is being fired when a new receipt has been added MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../added/ObservableReceiptAddedEvent.java | 36 ++++++++++ .../receipt/added/ReceiptAddedEvent.java | 66 +++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 src/org/mxchange/jfinancials/events/receipt/added/ObservableReceiptAddedEvent.java create mode 100644 src/org/mxchange/jfinancials/events/receipt/added/ReceiptAddedEvent.java diff --git a/src/org/mxchange/jfinancials/events/receipt/added/ObservableReceiptAddedEvent.java b/src/org/mxchange/jfinancials/events/receipt/added/ObservableReceiptAddedEvent.java new file mode 100644 index 0000000..18a6e78 --- /dev/null +++ b/src/org/mxchange/jfinancials/events/receipt/added/ObservableReceiptAddedEvent.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2017 Roland Häder + * + * 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 . + */ +package org.mxchange.jfinancials.events.receipt.added; + +import java.io.Serializable; +import org.mxchange.jfinancials.model.receipt.BillableReceipt; + +/** + * An interface for events being fired when a receipt instance has been added. + *

+ * @author Roland Häder + */ +public interface ObservableReceiptAddedEvent extends Serializable { + + /** + * Getter for receipt instance + *

+ * @return Receipt instance + */ + BillableReceipt getReceipt (); + +} diff --git a/src/org/mxchange/jfinancials/events/receipt/added/ReceiptAddedEvent.java b/src/org/mxchange/jfinancials/events/receipt/added/ReceiptAddedEvent.java new file mode 100644 index 0000000..5696c04 --- /dev/null +++ b/src/org/mxchange/jfinancials/events/receipt/added/ReceiptAddedEvent.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2017 Roland Haeder + * + * 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 . + */ +package org.mxchange.jfinancials.events.receipt.added; + +import java.text.MessageFormat; +import org.mxchange.jfinancials.model.receipt.BillableReceipt; + +/** + * An event being fired when a new receipt has been added + *

+ * @author Roland Haeder + */ +public class ReceiptAddedEvent implements ObservableReceiptAddedEvent { + + /** + * Serial number + */ + private static final long serialVersionUID = 157_582_667_163_547L; + + /** + * New receipt instance being added + */ + private final BillableReceipt receipt; + + /** + * Constructor with receipt instance + *

+ * @param receipt Receipt instance + */ + public ReceiptAddedEvent (final BillableReceipt receipt) { + // Validate parameter + if (null == receipt) { + // Throw NPE + throw new NullPointerException("receipt is null"); + } else if (receipt.getReceiptId() == null) { + // Throw NPE again + throw new NullPointerException("receipt.receiptId is null"); + } else if (receipt.getReceiptId() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("receipt.receiptId={0} is not valid", receipt.getReceiptId())); + } + + // Set it here + this.receipt = receipt; + } + + @Override + public BillableReceipt getReceipt () { + return this.receipt; + } + +} -- 2.39.5