Skip to content

Package: ConditionEvaluationUtil

ConditionEvaluationUtil

nameinstructionbranchcomplexitylinemethod
isLeafConditionForSetting(LeafCondition, EObject, Map)
M: 0 C: 48
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 11
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 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.view.spi.rule.model.util;
15:
16: import java.util.LinkedHashSet;
17: import java.util.Map;
18: import java.util.Set;
19:
20: import org.eclipse.emf.ecore.EObject;
21: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
22: import org.eclipse.emf.ecp.common.spi.UniqueSetting;
23: import org.eclipse.emf.ecp.view.spi.rule.model.LeafCondition;
24: import org.eclipse.emf.ecp.view.spi.rule.model.impl.LeafConditionSettingIterator;
25:
26: /**
27: * Util class for evaluating conditions.
28: *
29: * @author jfaltermeier
30: * @since 1.5
31: *
32: */
33: public final class ConditionEvaluationUtil {
34:
35:         private ConditionEvaluationUtil() {
36:                 // util
37:         }
38:
39:         /**
40:          * Whether the leaf condition evaluates objects of the given possible new values.
41:          *
42:          * @param condition the condition
43:          * @param domainModel The root domain object of the given {@link LeafCondition}
44:          * @param possibleNewValues the new value map
45:          * @return <code>true</code> if setting part of condition, <code>false</code> otherwise
46:          * @since 1.9
47:          */
48:         public static boolean isLeafConditionForSetting(LeafCondition condition, EObject domainModel,
49:                 Map<Setting, Object> possibleNewValues) {
50:                 final Set<UniqueSetting> newValueSettings = new LinkedHashSet<UniqueSetting>();
51:•                for (final Setting setting : possibleNewValues.keySet()) {
52:                         newValueSettings.add(UniqueSetting.createSetting(setting));
53:                 }
54:                 final LeafConditionSettingIterator iterator = new LeafConditionSettingIterator(condition, domainModel, true);
55:•                while (iterator.hasNext()) {
56:                         final UniqueSetting next = UniqueSetting.createSetting(iterator.next());
57:•                        if (newValueSettings.contains(next)) {
58:                                 iterator.dispose();
59:                                 return true;
60:                         }
61:                 }
62:                 iterator.dispose();
63:                 return false;
64:         }
65:
66: }