Skip to content

Package: AbstractFeatureAwareBuilder

AbstractFeatureAwareBuilder

nameinstructionbranchcomplexitylinemethod
AbstractFeatureAwareBuilder()
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%
disableFeature(Feature)
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%
enableFeature(Feature)
M: 5 C: 12
71%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 3
75%
M: 0 C: 1
100%
getBuilder()
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
inheritFeatures(Collection)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
isFeatureEnabled(Feature)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isFeatureSupported(Feature)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2019 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: * Mat Hansen - initial API and implementation
13: * Christian W. Damus - bug 530314
14: ******************************************************************************/
15: package org.eclipse.emfforms.spi.swt.table;
16:
17: import java.util.Collection;
18: import java.util.Set;
19:
20: import org.eclipse.emfforms.common.Feature;
21:
22: /**
23: * Abstract helper class for feature support.
24: *
25: * @author Mat Hansen <mhansen@eclipsesource.com>
26: * @since 1.14
27: *
28: * @param <B> the builder type
29: *
30: * @deprecated as of 1.21, {@link Feature}s are used only to communicate configuration data
31: * to the UI controls that interrogate the configurations. The builder API for
32: * users is a fluent API, not abstracted in terms of features
33: */
34: @Deprecated
35: public abstract class AbstractFeatureAwareBuilder<B> {
36:
37:         /**
38:          * Returns the list of supported features.
39:          *
40:          * @return array of supported features
41:          */
42:         protected abstract Set<Feature> getSupportedFeatures();
43:
44:         /**
45:          * Return the list of enabled features.
46:          *
47:          * @return list of enabled features
48:          */
49:         protected abstract Set<Feature> getEnabledFeatures();
50:
51:         /**
52:          * Enable a feature.
53:          *
54:          * @param featureToEnable the feature to enable
55:          * @return self
56:          */
57:         public B enableFeature(Feature featureToEnable) {
58:•                if (!isFeatureSupported(featureToEnable)) {
59:                         throw new IllegalArgumentException("Unsupported feature"); //$NON-NLS-1$
60:                 }
61:                 getEnabledFeatures().add(featureToEnable);
62:                 return getBuilder();
63:         }
64:
65:         /**
66:          * Disable a feature.
67:          *
68:          * @param featureToDisable the feature to disable
69:          * @return self
70:          */
71:         public B disableFeature(Feature featureToDisable) {
72:                 getEnabledFeatures().remove(featureToDisable);
73:                 return getBuilder();
74:         }
75:
76:         /**
77:          * Check whether the given feature is enabled.
78:          *
79:          * @param feature the feature to check
80:          * @return true if enabled
81:          */
82:         public boolean isFeatureEnabled(Feature feature) {
83:                 return getEnabledFeatures().contains(feature);
84:         }
85:
86:         /**
87:          * Check whether the given feature is supported.
88:          *
89:          * @param feature the feature to check
90:          * @return true if supported
91:          */
92:         public boolean isFeatureSupported(Feature feature) {
93:                 return getSupportedFeatures().contains(feature);
94:         }
95:
96:         /**
97:          * Inherit the features as long as they are supported.
98:          *
99:          * @param features list of features to inherit.
100:          * @return self
101:          */
102:         public B inheritFeatures(Collection<Feature> features) {
103:                 getEnabledFeatures().addAll(Feature.inherit(features, this::isFeatureSupported));
104:                 return getBuilder();
105:         }
106:
107:         /**
108:          * Returns the builder instance.
109:          *
110:          * @return self
111:          */
112:         @SuppressWarnings("unchecked")
113:         protected B getBuilder() {
114:                 return (B) this;
115:         }
116:
117: }