Skip to content

Package: UniqueSetting

UniqueSetting

nameinstructionbranchcomplexitylinemethod
UniqueSetting(EObject, EStructuralFeature)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
createSetting(EObject, EStructuralFeature)
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%
createSetting(EStructuralFeature.Setting)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
equals(Object)
M: 18 C: 35
66%
M: 10 C: 8
44%
M: 8 C: 2
20%
M: 8 C: 10
56%
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%
getSetting()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
hashCode()
M: 2 C: 30
94%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 5
100%
M: 0 C: 1
100%
toString()
M: 45 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 7 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: * Edgar Mueller - initial API and implementation
13: * Christian W. Damus - bug 543190
14: ******************************************************************************/
15: package org.eclipse.emf.ecp.common.spi;
16:
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.ecore.InternalEObject;
21:
22: /**
23: * <p>
24: * Convenience class for managing settings.
25: * </p>
26: * <p>
27: * Provides an equals method that returns {@code true} if the {@link EObject} and the
28: * {@link org.eclipse.emf.ecore.EStructuralFeature} are the same.
29: * </p>
30: *
31: * @author emueller
32: * @since 1.5
33: */
34: public class UniqueSetting {
35:
36:         private final EObject eObject;
37:         private final EStructuralFeature structuralFeature;
38:
39:         /**
40:          * Convenience method for creating a setting.
41:          *
42:          * @param eObject
43:          * an {@link EObject}
44:          * @param attribute
45:          * an EAttribute of the given {@code eObject}
46:          * @return the constructed setting
47:          */
48:         public static UniqueSetting createSetting(EObject eObject, EStructuralFeature attribute) {
49:                 return new UniqueSetting(eObject, attribute);
50:         }
51:
52:         /**
53:          * Convenience method for creating a setting.
54:          *
55:          * @param setting the {@link Setting} to wrap
56:          * @return the constructed setting
57:          *
58:          */
59:         public static UniqueSetting createSetting(Setting setting) {
60:                 return new UniqueSetting(setting.getEObject(), setting.getEStructuralFeature());
61:         }
62:
63:         /**
64:          * Constructor.
65:          *
66:          * @param eObject
67:          * an {@link EObject}
68:          * @param attribute
69:          * an EAttribute of the given {@code eObject}
70:          */
71:         protected UniqueSetting(EObject eObject, EStructuralFeature attribute) {
72:                 this.eObject = eObject;
73:                 structuralFeature = attribute;
74:         }
75:
76:         /**
77:          * {@inheritDoc}
78:          *
79:          * @see java.lang.Object#hashCode()
80:          */
81:         @Override
82:         public int hashCode() {
83:                 final int prime = 31;
84:                 int result = 1;
85:•                result = prime * result + (structuralFeature == null ? 0 : structuralFeature.hashCode());
86:•                result = prime * result + (eObject == null ? 0 : eObject.hashCode());
87:                 return result;
88:         }
89:
90:         /**
91:          * {@inheritDoc}
92:          *
93:          * @see java.lang.Object#equals(java.lang.Object)
94:          */
95:         @Override
96:         public boolean equals(Object obj) {
97:•                if (this == obj) {
98:                         return true;
99:                 }
100:•                if (obj == null) {
101:                         return false;
102:                 }
103:•                if (getClass() != obj.getClass()) {
104:                         return false;
105:                 }
106:                 final UniqueSetting other = (UniqueSetting) obj;
107:•                if (structuralFeature == null) {
108:•                        if (other.structuralFeature != null) {
109:                                 return false;
110:                         }
111:•                } else if (!structuralFeature.equals(other.structuralFeature)) {
112:                         return false;
113:                 }
114:•                if (eObject == null) {
115:•                        if (other.eObject != null) {
116:                                 return false;
117:                         }
118:•                } else if (!eObject.equals(other.eObject)) {
119:                         return false;
120:                 }
121:                 return true;
122:         }
123:
124:         /**
125:          * Returns the {@link EObject}.
126:          *
127:          * @return the {@link EObject}
128:          */
129:         public EObject getEObject() {
130:                 return eObject;
131:         }
132:
133:         /**
134:          * Returns the EAttribute of the {@link EObject}.
135:          *
136:          * @return the EAttribute
137:          */
138:         public EStructuralFeature getEStructuralFeature() {
139:                 return structuralFeature;
140:         }
141:
142:         /**
143:          * Return the {@link Setting} wrapped in this {@link UniqueSetting}.
144:          *
145:          * @return the wrapped {@link Setting}
146:          */
147:         public Setting getSetting() {
148:                 return ((InternalEObject) eObject).eSetting(structuralFeature);
149:         }
150:
151:         @Override
152:         public String toString() {
153:                 final StringBuilder result = new StringBuilder(64);
154:                 result.append("UniqueSetting("); //$NON-NLS-1$
155:•                result.append(structuralFeature == null ? "<null>" : structuralFeature.getName()); //$NON-NLS-1$
156:                 result.append(" of "); //$NON-NLS-1$
157:•                result.append(eObject == null ? "<null>" : Labelizer.get(eObject).getLabel(eObject)); //$NON-NLS-1$
158:                 result.append(')');
159:                 return result.toString();
160:         }
161:
162: }