Skip to content

Package: Feature

Feature

nameinstructionbranchcomplexitylinemethod
Feature(String, String)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
Feature(String, String, Feature.STRATEGY)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
equals(Object)
M: 0 C: 7
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getDescription()
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%
getId()
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%
getStrategy()
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%
hashCode()
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%
inherit(Collection, Predicate)
M: 2 C: 30
94%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 2 C: 6
75%
M: 0 C: 1
100%
toString()
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

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 - bugs 534829, 530314
14: ******************************************************************************/
15: package org.eclipse.emfforms.common;
16:
17: import java.util.Collection;
18: import java.util.LinkedHashSet;
19: import java.util.Set;
20: import java.util.function.Predicate;
21:
22: /**
23: * ECP feature representation.
24: *
25: * @author Mat Hansen
26: * @since 1.15
27: *
28: */
29: public final class Feature {
30:
31:         /**
32:          * Feature strategy enum.
33:          *
34:          */
35:         public enum STRATEGY {
36:                 /**
37:                  * No strategy.
38:                  */
39:                 NONE,
40:                 /**
41:                  * Inherit the feature automatically to children.
42:                  */
43:                 INHERIT,
44:         }
45:
46:         private final String id;
47:         private final String description;
48:         private final STRATEGY strategy;
49:
50:         /**
51:          * Default constructor (no feature inheritance).
52:          *
53:          * @param id the feature id
54:          * @param description the feature description
55:          */
56:         public Feature(String id, String description) {
57:                 this.id = id;
58:                 this.description = description;
59:                 strategy = STRATEGY.NONE;
60:         }
61:
62:         /**
63:          * Alternative constructor allowing to customize {@link STRATEGY}.
64:          *
65:          * @param id the feature id
66:          * @param description the feature description
67:          * @param strategy the feature {@link STRATEGY}
68:          */
69:         public Feature(String id, String description, STRATEGY strategy) {
70:                 this.id = id;
71:                 this.description = description;
72:                 this.strategy = strategy;
73:         }
74:
75:         /**
76:          * @return the id
77:          */
78:         public String getId() {
79:                 return id;
80:         }
81:
82:         /**
83:          * @return the description
84:          */
85:         public String getDescription() {
86:                 return description;
87:         }
88:
89:         /**
90:          * @return the strategy
91:          */
92:         public STRATEGY getStrategy() {
93:                 return strategy;
94:         }
95:
96:         /**
97:          * Features are like {@link Enum#equals(Object) enum}s in that they are equal by identity.
98:          */
99:         @Override
100:         public boolean equals(Object obj) {
101:•                return this == obj;
102:         }
103:
104:         @Override
105:         public int hashCode() {
106:                 return super.hashCode();
107:         }
108:
109:         @Override
110:         public String toString() {
111:                 return String.format("Feature(%s, %s)", id, strategy); //$NON-NLS-1$
112:         }
113:
114:         /**
115:          * Inherit the given {@code features} that are {@linkplain STRATEGY#INHERIT inheritable} and
116:          * are supported by the caller.
117:          *
118:          * @param features a collection of features to inherit
119:          * @param isSupported a test of whether the caller supports any particular feature
120:          * @return the supported inherited features
121:          *
122:          * @since 1.21
123:          */
124:         public static Set<Feature> inherit(Collection<Feature> features, Predicate<? super Feature> isSupported) {
125:                 final Set<Feature> result = new LinkedHashSet<>();
126:
127:•                for (final Feature feature : features) {
128:•                        if (!STRATEGY.INHERIT.equals(feature.getStrategy())) {
129:                                 continue;
130:                         }
131:•                        if (!isSupported.test(feature)) {
132:                                 continue;
133:                         }
134:                         result.add(feature);
135:                 }
136:
137:                 return result;
138:         }
139: }