Debian Codegraph @

plugins/org.eclipse.emf.gwt.common/src/org/eclipse/emf/common/notify/impl/NotificationChainImpl.java

raw
1 /**
2 * Copyright (c) 2002-2010 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v2.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v20.html
7 *
8 * Contributors:
9 * IBM - Initial API and implementation
10 */
11 package org.eclipse.emf.common.notify.impl;
12
13
14 import org.eclipse.emf.common.notify.Notification;
15 import org.eclipse.emf.common.notify.NotificationChain;
16 import org.eclipse.emf.common.notify.Notifier;
17 import org.eclipse.emf.common.util.BasicEList;
18
19
20 /**
21 * A list that acts as a notification chain.
22 */
23 public class NotificationChainImpl extends BasicEList<Notification> implements NotificationChain
24 {
25 private static final long serialVersionUID = 1L;
26
27 /**
28 * Creates an empty instance.
29 */
30 public NotificationChainImpl()
31 {
32 super();
33 }
34
35 /**
36 * Creates an empty instance with a given capacity.
37 * @param initialCapacity the initial capacity of the list before it must grow.
38 */
39 public NotificationChainImpl(int initialCapacity)
40 {
41 super(initialCapacity);
42 }
43
44 /**
45 * Returns new data storage of type {@link Notification}[].
46 * @return new data storage.
47 */
48 @Override
49 protected Object [] newData(int capacity)
50 {
51 return new Notification [capacity];
52 }
53
54 /**
55 * Adds or merges a new notification.
56 * @param newNotification a notification.
57 * @return <code>true</code> when the notification is added and <code>false</code> when it is merged.
58 */
59 @Override
60 public boolean add(Notification newNotification)
61 {
62 if (newNotification == null)
63 {
64 return false;
65 }
66 else
67 {
68 for (int i = 0; i < size; ++i)
69 {
70 Notification notification = (Notification)data[i];
71 if (notification.merge(newNotification))
72 {
73 return false;
74 }
75 }
76
77 return super.add(newNotification);
78 }
79 }
80
81 public void dispatch()
82 {
83 for (int i = 0; i < size; ++i)
84 {
85 Notification notification = (Notification)data[i];
86 dispatch(notification);
87 }
88 }
89
90 /**
91 * Dispatches the notification to its notifier.
92 */
93 protected void dispatch(Notification notification)
94 {
95 Object notifier = notification.getNotifier();
96 if (notifier != null && notification.getEventType() != -1)
97 {
98 ((Notifier)notifier).eNotify(notification);
99 }
100 }
101 }