Skip to content

Package: ConditionServiceManagerImpl

ConditionServiceManagerImpl

nameinstructionbranchcomplexitylinemethod
ConditionServiceManagerImpl()
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%
addConditionService(ConditionService)
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%
evaluate(Condition, EObject)
M: 2 C: 12
86%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 2
67%
M: 0 C: 1
100%
evaluateChangedValues(Condition, EObject, Map)
M: 2 C: 13
87%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 3
75%
M: 0 C: 1
100%
getConditionSettings(Condition, EObject)
M: 0 C: 14
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getDomainModelReferences(Condition)
M: 0 C: 13
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
removeConditionService(ConditionService)
M: 0 C: 7
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-2016 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: * Eugen Neufeld - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.internal.rule;
15:
16: import java.util.Collections;
17: import java.util.LinkedHashMap;
18: import java.util.Map;
19: import java.util.Set;
20:
21: import org.eclipse.emf.ecore.EClass;
22: import org.eclipse.emf.ecore.EObject;
23: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
24: import org.eclipse.emf.ecp.common.spi.UniqueSetting;
25: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
26: import org.eclipse.emf.ecp.view.spi.rule.ConditionService;
27: import org.eclipse.emf.ecp.view.spi.rule.model.Condition;
28: import org.osgi.service.component.annotations.Component;
29: import org.osgi.service.component.annotations.Reference;
30: import org.osgi.service.component.annotations.ReferenceCardinality;
31: import org.osgi.service.component.annotations.ReferencePolicy;
32:
33: /**
34: * The internal component implementation of the ConditionServiceManager.
35: *
36: * @author Eugen Neufeld
37: *
38: */
39: @Component
40: public class ConditionServiceManagerImpl implements ConditionServiceManager {
41:
42:         private final Map<EClass, ConditionService<Condition>> conditionServices = new LinkedHashMap<EClass, ConditionService<Condition>>();
43:
44:         /**
45:          * Called by the framework to add a ConditionService.
46:          *
47:          * @param <T> The type of the added ConditionService
48:          * @param conditionService The ConditionService to add
49:          */
50:         @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, unbind = "removeConditionService")
51:         protected <T extends Condition> void addConditionService(ConditionService<Condition> conditionService) {
52:                 conditionServices.put(conditionService.getConditionType(), conditionService);
53:         }
54:
55:         /**
56:          * Called by the framework to remove a ConditionService.
57:          *
58:          * @param conditionService The ConditionService to remove
59:          */
60:         protected void removeConditionService(ConditionService<Condition> conditionService) {
61:                 conditionServices.remove(conditionService.getConditionType());
62:         }
63:
64:         /**
65:          * {@inheritDoc}
66:          *
67:          * @see org.eclipse.emf.ecp.view.internal.rule.ConditionServiceManager#getConditionSettings(org.eclipse.emf.ecp.view.spi.rule.model.Condition,
68:          * org.eclipse.emf.ecore.EObject)
69:          */
70:         @Override
71:         public Set<UniqueSetting> getConditionSettings(Condition condition, EObject domainModel) {
72:•                if (condition == null) {
73:                         return Collections.emptySet();
74:                 }
75:                 return conditionServices.get(condition.eClass()).getConditionSettings(condition, domainModel);
76:         }
77:
78:         /**
79:          * {@inheritDoc}
80:          *
81:          * @see org.eclipse.emf.ecp.view.internal.rule.ConditionServiceManager#evaluate(org.eclipse.emf.ecp.view.spi.rule.model.Condition,
82:          * org.eclipse.emf.ecore.EObject)
83:          */
84:         @Override
85:         public boolean evaluate(Condition condition, EObject domainModel) {
86:•                if (condition == null) {
87:                         return false;
88:                 }
89:                 return conditionServices.get(condition.eClass()).evaluate(condition, domainModel);
90:         }
91:
92:         /**
93:          * {@inheritDoc}
94:          *
95:          * @see org.eclipse.emf.ecp.view.internal.rule.ConditionServiceManager#evaluateChangedValues(org.eclipse.emf.ecp.view.spi.rule.model.Condition,
96:          * org.eclipse.emf.ecore.EObject, java.util.Map)
97:          */
98:         @Override
99:         public boolean evaluateChangedValues(Condition condition, EObject domainModel,
100:                 Map<Setting, Object> possibleNewValues) {
101:•                if (condition == null) {
102:                         return false;
103:                 }
104:                 return conditionServices.get(condition.eClass()).evaluateChangedValues(condition, domainModel,
105:                         possibleNewValues);
106:         }
107:
108:         /**
109:          * {@inheritDoc}
110:          *
111:          * @see org.eclipse.emf.ecp.view.internal.rule.ConditionServiceManager#getDomainModelReferences(org.eclipse.emf.ecp.view.spi.rule.model.Condition)
112:          */
113:         @Override
114:         public Set<VDomainModelReference> getDomainModelReferences(Condition condition) {
115:•                if (condition == null) {
116:                         return Collections.emptySet();
117:                 }
118:                 return conditionServices.get(condition.eClass()).getDomainModelReferences(condition);
119:         }
120:
121: }