Skip to content

Package: AbstractNotificationProvider

AbstractNotificationProvider

nameinstructionbranchcomplexitylinemethod
AbstractNotificationProvider()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
addReceiver(NotificationReceiver)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
notifyAllReceivers(Notification)
M: 0 C: 16
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
notifyCanDelete(EObject)
M: 23 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
notifyPostDelete(EObject)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
notifyPreDelete(EObject)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
removeReceiver(NotificationReceiver)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2015 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * jfaltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.changebroker.spi;
15:
16: import java.util.Set;
17: import java.util.concurrent.CopyOnWriteArraySet;
18:
19: import org.eclipse.emf.common.notify.Notification;
20: import org.eclipse.emf.ecore.EObject;
21:
22: /**
23: * Abstract implementation of a {@link NotificationProvider}.
24: *
25: * @author jfaltermeier
26: *
27: */
28: public abstract class AbstractNotificationProvider implements NotificationProvider {
29:
30:         private final Set<NotificationReceiver> receivers = new CopyOnWriteArraySet<NotificationReceiver>();
31:
32:         /**
33:          *
34:          * {@inheritDoc}
35:          *
36:          * @see org.eclipse.emf.ecp.changebroker.spi.NotificationProvider#addReceiver(org.eclipse.emf.ecp.changebroker.spi.NotificationReceiver)
37:          */
38:         @Override
39:         public void addReceiver(NotificationReceiver receiver) {
40:                 receivers.add(receiver);
41:         }
42:
43:         /**
44:          *
45:          * {@inheritDoc}
46:          *
47:          * @see org.eclipse.emf.ecp.changebroker.spi.NotificationProvider#removeReceiver(org.eclipse.emf.ecp.changebroker.spi.NotificationReceiver)
48:          */
49:         @Override
50:         public void removeReceiver(NotificationReceiver receiver) {
51:                 receivers.remove(receiver);
52:         }
53:
54:         /**
55:          * Notifies all registered {@link org.eclipse.emf.ecp.changebroker.spi.ChangeObserver receivers}.
56:          *
57:          * @param notification the notification
58:          */
59:         protected void notifyAllReceivers(Notification notification) {
60:•                for (final NotificationReceiver receiver : receivers) {
61:                         receiver.notify(notification);
62:                 }
63:         }
64:
65:         /**
66:          *
67:          * @param toBeDeleted The deleted {@link EObject}
68:          *
69:          * @since 1.7
70:          */
71:         protected void notifyPreDelete(EObject toBeDeleted) {
72:•                for (final NotificationReceiver receiver : receivers) {
73:                         receiver.notifyPreDelete(toBeDeleted);
74:                 }
75:         }
76:
77:         /**
78:          *
79:          * @param toBeDeleted The deleted {@link EObject}
80:          *
81:          * @since 1.7
82:          */
83:         protected void notifyPostDelete(EObject toBeDeleted) {
84:•                for (final NotificationReceiver receiver : receivers) {
85:                         receiver.notifyPostDelete(toBeDeleted);
86:                 }
87:         }
88:
89:         /**
90:          * @param toBeDeleted The deleted {@link EObject}
91:          * @return if the object can be deleted
92:          * @since 1.7
93:          */
94:         protected boolean notifyCanDelete(EObject toBeDeleted) {
95:                 boolean canDelete = true;
96:•                for (final NotificationReceiver receiver : receivers) {
97:                         canDelete = receiver.canDelete(toBeDeleted);
98:•                        if (!canDelete) {
99:                                 break;
100:                         }
101:                 }
102:                 return canDelete;
103:         }
104:
105: }