]> git.mxchange.org Git - jaddressbook-share-core.git/blob - src/org/mxchange/jaddressbookshare/events/sharing/EndedAddressbookSharingEvent.java
Updated copyright year
[jaddressbook-share-core.git] / src / org / mxchange / jaddressbookshare / events / sharing / EndedAddressbookSharingEvent.java
1 /*
2  * Copyright (C) 2016 - 2024 Free Software Foundation
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jaddressbookshare.events.sharing;
18
19 import java.text.MessageFormat;
20 import org.mxchange.jaddressbookshare.events.sharing.type.SharingType;
21 import org.mxchange.jaddressbookshare.model.shared.ShareableAddressbook;
22
23 /**
24  * An event fired when a user ends sharing address books
25  * <p>
26  * @author Roland Häder<roland@mxchange.org>
27  */
28 public class EndedAddressbookSharingEvent implements ObservableAddressbookSharingEvent {
29
30         /**
31          * Serial number
32          */
33         private static final long serialVersionUID = 152_896_748_186_018_497L;
34
35         /**
36          * Shared address book entry
37          */
38         private final ShareableAddressbook shareableAddressbook;
39
40         /**
41          * Constructor with address book share entry
42          * <p>
43          * @param share Address book share entry
44          */
45         public EndedAddressbookSharingEvent (final ShareableAddressbook share) {
46                 // Check parameter
47                 if (null == share) {
48                         // Throw NPE
49                         throw new NullPointerException("Parameter 'share' is null"); //NOI18N
50                 } else if (share.getShareId() == null) {
51                         // Throw NPE again
52                         throw new NullPointerException("share.shareId is null"); //NOI18N
53                 } else if (share.getShareId() < 1) {
54                         // Throw IAE
55                         throw new IllegalArgumentException(MessageFormat.format("share.shareId={0} is invalid", share.getShareId())); //NOI18N
56                 } else if (share.getShareAddressbook() == null) {
57                         // Throw NPE again
58                         throw new NullPointerException("share.shareAddressbook is null"); //NOI18N
59                 } else if (share.getShareAddressbook().getAddressbookId() == null) {
60                         // ... and again
61                         throw new NullPointerException("share.shareAddressbook.addressbookId is null"); //NOI18N
62                 } else if (share.getShareAddressbook().getAddressbookId() < 1) {
63                         // Throw IAE
64                         throw new IllegalArgumentException(MessageFormat.format("share.shareAddressbook.addressbookId={0} is invalid", share.getShareAddressbook().getAddressbookId())); //NOI18N
65                 } else if (share.getShareUserOwner() == null) {
66                         // Throw NPE again
67                         throw new NullPointerException("share.shareUserOwner is null"); //NOI18N
68                 } else if (share.getShareUserOwner().getUserId() == null) {
69                         // ... and again
70                         throw new NullPointerException("share.shareUserOwner.userId is null"); //NOI18N
71                 } else if (share.getShareUserOwner().getUserId() < 1) {
72                         // Throw IAE
73                         throw new IllegalArgumentException(MessageFormat.format("share.shareUserOwner.userId={0} is invalid", share.getShareUserOwner().getUserId())); //NOI18N
74                 } else if (share.getShareUserSharee() == null) {
75                         // Throw NPE again
76                         throw new NullPointerException("share.shareUserSharee is null"); //NOI18N
77                 } else if (share.getShareUserSharee().getUserId() == null) {
78                         // ... and again
79                         throw new NullPointerException("share.shareUserSharee.userId is null"); //NOI18N
80                 } else if (share.getShareUserSharee().getUserId() < 1) {
81                         // Throw IAE
82                         throw new IllegalArgumentException(MessageFormat.format("share.shareUserSharee.userId={0} is invalid", share.getShareUserSharee().getUserId())); //NOI18N
83                 }
84
85                 // Set it in class
86                 this.shareableAddressbook = share;
87         }
88
89         @Override
90         public ShareableAddressbook getShareableAddressbook () {
91                 return this.shareableAddressbook;
92         }
93
94         @Override
95         public SharingType getSharingType () {
96                 // Started sharing
97                 return SharingType.ENDED;
98         }
99 }