Skip to content

Package: SelectedEnumeratorMapping

SelectedEnumeratorMapping

nameinstructionbranchcomplexitylinemethod
SelectedEnumeratorMapping(Enumerator, boolean)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
createFromList(List)
M: 31 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
deselectAll(SelectedEnumeratorMapping[])
M: 20 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
findLiteral(SelectedEnumeratorMapping[], String)
M: 27 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
findSelected(SelectedEnumeratorMapping[])
M: 25 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getEnumerator()
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%
isSelected()
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%
select(SelectedEnumeratorMapping[], Enumerator)
M: 25 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
setSelected(boolean)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017 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: * Edgar Mueller - initial API and implementation
13: *******************************************************************************/
14: package org.eclipse.emf.ecp.view.spi.table.swt;
15:
16: import java.util.List;
17:
18: import org.eclipse.emf.common.util.Enumerator;
19: import org.eclipse.emf.ecore.EEnumLiteral;
20: import org.eclipse.emfforms.common.Optional;
21:
22: /**
23: * Utility class that determines whether
24: * a given {@link Enumerator} and has been selected.
25: *
26: * @since 1.13
27: */
28: public class SelectedEnumeratorMapping {
29:
30:         private boolean selected;
31:         private final Enumerator enumerator;
32:
33:         /**
34:          * Search the array of {@link SelectedEnumeratorMapping}s for the given literal.
35:          *
36:          * @param mapping the array of mappings to be searched
37:          * @param literal the literal to be searched for as a string
38:          * @return an {@link Optional} containing the matched literal
39:          */
40:         public static Optional<SelectedEnumeratorMapping> findLiteral(SelectedEnumeratorMapping[] mapping,
41:                 String literal) {
42:
43:•                for (final SelectedEnumeratorMapping m : mapping) {
44:•                        if (m.getEnumerator().getLiteral().equals(literal)) {
45:                                 return Optional.of(m);
46:                         }
47:                 }
48:
49:                 return Optional.empty();
50:         }
51:
52:         /**
53:          * Find the first selected enumerator.
54:          *
55:          * @param mapping an array of {@link SelectedEnumeratorMapping}s
56:          * @return an {@link Optional} containing the selected {@link Enumerator}
57:          */
58:         public static Optional<Enumerator> findSelected(SelectedEnumeratorMapping[] mapping) {
59:
60:•                for (final SelectedEnumeratorMapping current : mapping) {
61:•                        if (current.isSelected()) {
62:                                 return Optional.of(current.getEnumerator());
63:                         }
64:                 }
65:
66:                 return Optional.empty();
67:         }
68:
69:         /**
70:          * Given a list of {@link EEnumLiteral}s creates an array of {@link SelectedEnumeratorMapping}s.
71:          *
72:          * @param literals a list of {@link EEnumLiteral}s
73:          * @return an array of {@link SelectedEnumeratorMapping}
74:          */
75:         public static SelectedEnumeratorMapping[] createFromList(List<EEnumLiteral> literals) {
76:                 final SelectedEnumeratorMapping[] mapping = new SelectedEnumeratorMapping[literals.size()];
77:                 int i = 0;
78:•                for (final EEnumLiteral literal : literals) {
79:                         final SelectedEnumeratorMapping current = new SelectedEnumeratorMapping(literal.getInstance(),
80:                                 false);
81:                         mapping[i++] = current;
82:                 }
83:                 return mapping;
84:         }
85:
86:         /**
87:          * Select the given {@link Enumerator} in the list of given {@link SelectedEnumeratorMapping}s.
88:          *
89:          * @param mappings an array of {@link SelectedEnumeratorMapping}s,
90:          * @param enumerator the {@link Enumerator} to be selected
91:          */
92:         public static void select(SelectedEnumeratorMapping[] mappings, Enumerator enumerator) {
93:•                for (final SelectedEnumeratorMapping selectedEnumeratorMapping : mappings) {
94:•                        if (enumerator.equals(selectedEnumeratorMapping.getEnumerator())) {
95:                                 selectedEnumeratorMapping.setSelected(true);
96:                         }
97:                 }
98:         }
99:
100:         /**
101:          * De-select all enumerators in the given array of {@link SelectedEnumeratorMapping}s.
102:          *
103:          * @param mappings an array of {@link SelectedEnumeratorMapping}s
104:          */
105:         public static void deselectAll(final SelectedEnumeratorMapping[] mappings) {
106:•                for (final SelectedEnumeratorMapping selectedMapping : mappings) {
107:                         selectedMapping.setSelected(false);
108:                 }
109:         }
110:
111:         /**
112:          * Constructor.
113:          *
114:          * @param enumerator the {@link Enumerator} entry
115:          * @param selected whether the given enumerator is selected
116:          */
117:         public SelectedEnumeratorMapping(Enumerator enumerator, boolean selected) {
118:                 this.enumerator = enumerator;
119:                 setSelected(selected);
120:         }
121:
122:         /**
123:          * Returns whether whether the enumerator is selected.
124:          *
125:          * @return {@code true}, if the enumerator is selected
126:          */
127:         public boolean isSelected() {
128:                 return selected;
129:         }
130:
131:         /**
132:          * Returns whether whether the enumerator is selected.
133:          *
134:          * @param selected the selected state
135:          */
136:         public void setSelected(boolean selected) {
137:                 this.selected = selected;
138:         }
139:
140:         /**
141:          * Returns the enumerator.
142:          *
143:          * @return the enumerator
144:          */
145:         public Enumerator getEnumerator() {
146:                 return enumerator;
147:         }
148: }