Skip to content

Package: Disposable

Disposable

nameinstructionbranchcomplexitylinemethod
Disposable(ECPDisposable)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
addDisposeListener(ECPDisposable.DisposeListener)
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%
dispose()
M: 4 C: 46
92%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 1 C: 12
92%
M: 0 C: 1
100%
doDispose()
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isDisposed()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
removeDisposeListener(ECPDisposable.DisposeListener)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /********************************************************************************
2: * Copyright (c) 2011 Eike Stepper (Berlin, Germany) 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: * Eike Stepper - initial API and implementation
13: ********************************************************************************/
14: package org.eclipse.emf.ecp.internal.core.util;
15:
16: import java.util.ArrayList;
17: import java.util.List;
18:
19: import org.eclipse.emf.ecp.internal.core.Activator;
20: import org.eclipse.emf.ecp.spi.core.util.DisposeException;
21: import org.eclipse.emf.ecp.spi.core.util.ECPDisposable;
22:
23: /**
24: * @author Eike Stepper
25: */
26: public class Disposable implements ECPDisposable {
27:         private final List<DisposeListener> listeners = new ArrayList<DisposeListener>();
28:
29:         private final ECPDisposable delegate;
30:
31:         private boolean disposed;
32:
33:         /**
34:          * Constructor of an disposable object.
35:          *
36:          * @param delegate the delegate to call
37:          */
38:         public Disposable(ECPDisposable delegate) {
39:                 this.delegate = delegate;
40:         }
41:
42:         /** {@inheritDoc} */
43:         @Override
44:         public final synchronized boolean isDisposed() {
45:                 return disposed;
46:         }
47:
48:         /** {@inheritDoc} */
49:         @Override
50:         public final void dispose() {
51:                 DisposeListener[] array = null;
52:
53:                 synchronized (this) {
54:•                        if (!disposed) {
55:                                 doDispose();
56:                                 disposed = true;
57:                                 array = listeners.toArray(new DisposeListener[listeners.size()]);
58:                         }
59:                 }
60:
61:•                if (array != null) {
62:•                        for (int i = 0; i < array.length; i++) {
63:                                 final DisposeListener listener = array[i];
64:
65:                                 try {
66:                                         listener.disposed(delegate);
67:                                 } catch (final DisposeException ex) {
68:                                         Activator.log(ex);
69:                                 }
70:                         }
71:                 }
72:         }
73:
74:         /** {@inheritDoc} */
75:         @Override
76:         public final synchronized void addDisposeListener(DisposeListener listener) {
77:                 listeners.add(listener);
78:         }
79:
80:         /** {@inheritDoc} */
81:         @Override
82:         public final synchronized void removeDisposeListener(DisposeListener listener) {
83:                 listeners.remove(listener);
84:         }
85:
86:         /**
87:          * this method is called so that each implementation can execute specific dispose methods.
88:          */
89:         protected void doDispose() {
90:         }
91: }