Skip to content

Package: IndexedSetting

IndexedSetting

nameinstructionbranchcomplexitylinemethod
IndexedSetting(EObject, EStructuralFeature, int)
M: 12 C: 29
71%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 3 C: 9
75%
M: 0 C: 1
100%
get(boolean)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getEObject()
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%
getEStructuralFeature()
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%
getIndex()
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%
isSet()
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
set(Object)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
unset()
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%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2018 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: * Lucas Koehler - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.core.services.segments.index;
15:
16: import org.eclipse.emf.common.util.EList;
17: import org.eclipse.emf.ecore.EObject;
18: import org.eclipse.emf.ecore.EStructuralFeature;
19: import org.eclipse.emf.ecore.EStructuralFeature.Setting;
20: import org.eclipse.emf.ecp.common.spi.asserts.Assert;
21:
22: /**
23: * An {@link IndexedSetting} is a {@link Setting} whose {@link EStructuralFeature} is a multi reference or attribute
24: * that is indexed. This means the value of the Setting is the Object at the {@link IndexedSetting IndexedSetting's}
25: * index in the list referenced by the structural feature. In a "standard" Setting, the whole list would be the settings
26: * value.
27: *
28: * @author Lucas Koehler
29: *
30: */
31: public class IndexedSetting implements Setting {
32:
33:         private final EObject eObject;
34:         private final EStructuralFeature eStructuralFeature;
35:         private final int index;
36:         private final EList<Object> list;
37:
38:         /**
39:          * Creates a new {@link IndexedSetting}.
40:          *
41:          * @param eObject The {@link EObject} holding a list
42:          * @param eStructuralFeature The specific feature holding the list
43:          * @param index The index that defines which list item is the value of this {@link Setting}
44:          */
45:         @SuppressWarnings("unchecked")
46:         public IndexedSetting(EObject eObject, EStructuralFeature eStructuralFeature, int index) {
47:                 Assert.create(eObject).notNull();
48:                 Assert.create(eStructuralFeature).notNull();
49:
50:•                if (!eStructuralFeature.isMany()) {
51:                         throw new IllegalArgumentException(
52:                                 String.format("The given EStructuralFeature does not support multiple elements. The feature was %s", //$NON-NLS-1$
53:                                         eStructuralFeature));
54:                 }
55:
56:                 this.eObject = eObject;
57:                 this.eStructuralFeature = eStructuralFeature;
58:                 this.index = index;
59:                 list = (EList<Object>) eObject.eGet(eStructuralFeature);
60:         }
61:
62:         @Override
63:         public EObject getEObject() {
64:                 return eObject;
65:         }
66:
67:         @Override
68:         public EStructuralFeature getEStructuralFeature() {
69:                 return eStructuralFeature;
70:         }
71:
72:         @Override
73:         public Object get(boolean resolve) {
74:                 // Always resolved => ignore the parameter
75:                 return list.get(index);
76:         }
77:
78:         @Override
79:         public void set(Object newValue) {
80:                 list.set(index, newValue);
81:         }
82:
83:         @Override
84:         public boolean isSet() {
85:•                return list.get(index) != null;
86:         }
87:
88:         @Override
89:         public void unset() {
90:                 throw new UnsupportedOperationException("It is not possible to unset a value in an IndexedSetting."); //$NON-NLS-1$
91:         }
92:
93:         /**
94:          * Returns the index of this {@link IndexedSetting}. The index defines the list index of this setting's value: The
95:          * list is resolved from the holding {@link EObject} and the {@link EStructuralFeature} of this
96:          * {@link IndexedSetting}.
97:          *
98:          * @return The list index
99:          */
100:         public int getIndex() {
101:                 return index;
102:         }
103: }