Skip to content

Package: ECPObserverCall$Result

ECPObserverCall$Result

nameinstructionbranchcomplexitylinemethod
ECPObserverCall.Result(ECPObserver, Method, Object)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
ECPObserverCall.Result(ECPObserver, Throwable, Method)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
exceptionOccurred()
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getDefaultValue(Method)
M: 0 C: 12
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getException()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getObserver()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getResult()
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%
getResultOrDefaultValue()
M: 0 C: 11
100%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 4
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 57
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2012 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: * wesendon - initial API and implementation
13: *
14: *******************************************************************************/
15:
16: package org.eclipse.emf.ecp.internal.core.util.observer;
17:
18: import java.lang.reflect.Method;
19: import java.util.HashMap;
20: import java.util.List;
21: import java.util.Map;
22:
23: import org.eclipse.emf.ecp.core.util.observer.ECPObserver;
24:
25: /**
26: * ProxyObserver, returned by the {@link ECPObserverBusImpl} when calling {@link ECPObserverBusImpl#notify(Class)},
27: * normally it
28: * has
29: * the type of the class extending IObserver in order to call the observer interface with type safety.
30: * However, the same proxies can be casted into {@link ECPObserverCall} in order to access the results by all registered
31: * observers.
32: *
33: * @author wesendon
34: *
35: */
36: public interface ECPObserverCall {
37:
38:         /**
39:          * Returns the results of each notified observer. This method will always return the returns from the last call
40:          * executed on the proxy.
41:          *
42:          * @return list of results
43:          */
44:         List<Result> getObserverCallResults();
45:
46:         /**
47:          * This class represents an result from an observer call. It contains the observer, the called method and the result
48:          * or an exception, if occured.
49:          *
50:          *
51:          * @author wesendon
52:          *
53:          */
54:         class Result {
55:
56:                 private final ECPObserver observer;
57:                 private final Method method;
58:                 private final Object result;
59:                 private final Throwable exception;
60:
61:                 /**
62:                  * This constructor is used if <b>NO</b> exception occurred.
63:                  *
64:                  * @param observer observer
65:                  * @param method method
66:                  * @param result result
67:                  */
68:                 public Result(ECPObserver observer, Method method, Object result) {
69:                         this.observer = observer;
70:                         this.method = method;
71:                         this.result = result;
72:                         exception = null;
73:                 }
74:
75:                 /**
76:                  * This constructor is used if an exception <b>HAS</b> occurred.
77:                  *
78:                  * @param observer observer
79:                  * @param e exception
80:                  * @param method method
81:                  */
82:                 public Result(ECPObserver observer, Throwable e, Method method) {
83:                         this.observer = observer;
84:                         exception = e;
85:                         this.method = method;
86:                         result = null;
87:                 }
88:
89:                 /**
90:                  * Specifies whether this Result contains an exception.
91:                  *
92:                  * @return boolean
93:                  */
94:                 public boolean exceptionOccurred() {
95:•                        return exception != null;
96:                 }
97:
98:                 /**
99:                  * .
100:                  *
101:                  * @return exception or null
102:                  */
103:                 public Throwable getException() {
104:                         return exception;
105:                 }
106:
107:                 /**
108:                  * The observer.
109:                  *
110:                  * @return this can't be null
111:                  */
112:                 public ECPObserver getObserver() {
113:                         return observer;
114:                 }
115:
116:                 /**
117:                  * The result.
118:                  *
119:                  * @return the result or null
120:                  */
121:                 public Object getResult() {
122:                         return result;
123:                 }
124:
125:                 /**
126:                  * Returns the result or the default value for primitive types.
127:                  *
128:                  * @return result, null or in case of primitive type, the default value.
129:                  */
130:                 public Object getResultOrDefaultValue() {
131:                         Object result = getResult();
132:•                        if (result == null) {
133:                                 result = getDefaultValue(method);
134:                         }
135:                         return result;
136:                 }
137:
138:                 /**
139:                  * Returns the default value for a given method. Which is null or the default primitive value.
140:                  *
141:                  * @param m method
142:                  * @return null or default primitive value
143:                  */
144:                 public static Object getDefaultValue(Method m) {
145:•                        if (m.getReturnType().isPrimitive()) {
146:                                 return DEFAULTPRIMITIVEVALUES.get(m.getReturnType().getSimpleName());
147:                         }
148:                         return null;
149:                 }
150:
151:                 private static final Map<String, Object> DEFAULTPRIMITIVEVALUES = new HashMap<String, Object>();
152:
153:                 static {
154:                         DEFAULTPRIMITIVEVALUES.put("int", new Integer(0)); //$NON-NLS-1$
155:                         DEFAULTPRIMITIVEVALUES.put("boolean", new Boolean(false)); //$NON-NLS-1$
156:                         DEFAULTPRIMITIVEVALUES.put("long", new Long(0)); //$NON-NLS-1$
157:                         DEFAULTPRIMITIVEVALUES.put("float", new Float(0)); //$NON-NLS-1$
158:                         DEFAULTPRIMITIVEVALUES.put("double", new Double(0)); //$NON-NLS-1$
159:                         DEFAULTPRIMITIVEVALUES.put("byte", Byte.MIN_VALUE); //$NON-NLS-1$
160:                         DEFAULTPRIMITIVEVALUES.put("short", Short.MIN_VALUE); //$NON-NLS-1$
161:                 }
162:         }
163: }