Skip to content

Package: Properties$Property

Properties$Property

nameinstructionbranchcomplexitylinemethod
Properties.Property(String, String)
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%
getKey()
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%
getValue()
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%
setValue(String)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toString()
M: 13 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 Eike Stepper (Berlin, Germany) 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: * Eike Stepper - initial API and implementation
13: ********************************************************************************/
14: package org.eclipse.emf.ecp.internal.core.util;
15:
16: import java.io.IOException;
17: import java.io.ObjectInput;
18: import java.io.ObjectOutput;
19: import java.util.Collection;
20: import java.util.Collections;
21: import java.util.Map;
22: import java.util.Map.Entry;
23: import java.util.Set;
24:
25: import org.eclipse.emf.ecp.core.util.ECPProperties;
26: import org.eclipse.emf.ecp.core.util.ECPUtil;
27: import org.eclipse.emf.ecp.core.util.observer.ECPPropertiesObserver;
28:
29: /**
30: * @author Eike Stepper
31: */
32: public class Properties extends Registry<Map.Entry<String, String>, ECPPropertiesObserver> implements ECPProperties {
33:         /**
34:          * Default constructor.
35:          */
36:         public Properties() {
37:                 activate();
38:         }
39:
40:         public Properties(ObjectInput in) throws IOException {
41:                 activate();
42:                 final int count = in.readInt();
43:                 for (int i = 0; i < count; i++) {
44:                         final String key = in.readUTF();
45:                         final String value = in.readUTF();
46:                         addProperty(key, value);
47:                 }
48:
49:         }
50:
51:         public void write(ObjectOutput out) throws IOException {
52:                 final Collection<Entry<String, String>> entries = getElementsToWrite();
53:                 out.writeInt(entries.size());
54:                 for (final Entry<String, String> entry : entries) {
55:                         out.writeUTF(entry.getKey());
56:                         out.writeUTF(entry.getValue());
57:                 }
58:         }
59:
60:         /** {@inheritDoc} */
61:         @Override
62:         public void addProperty(String key, String value) {
63:                 final Map.Entry<String, String> property = new Property(key, value);
64:                 doChangeElements(null, Collections.singleton(property));
65:         }
66:
67:         /** {@inheritDoc} */
68:         @Override
69:         public void removeProperty(String key) {
70:                 doChangeElements(Collections.singleton(key), null);
71:         }
72:
73:         /** {@inheritDoc} */
74:         @Override
75:         public String getValue(String name) {
76:                 final Entry<String, String> element = getElement(name);
77:                 return element == null ? null : element.getValue();
78:         }
79:
80:         /** {@inheritDoc} */
81:         @Override
82:         public Set<String> getKeys() {
83:                 return getElementNames();
84:         }
85:
86:         /** {@inheritDoc} */
87:         @Override
88:         public Collection<Map.Entry<String, String>> getProperties() {
89:                 return getElements();
90:         }
91:
92:         /** {@inheritDoc} */
93:         @Override
94:         public boolean hasProperties() {
95:                 return hasElements();
96:         }
97:
98:         /** {@inheritDoc} */
99:         @Override
100:         public ECPProperties copy() {
101:                 final ECPProperties copy = ECPUtil.createProperties();
102:                 for (final Entry<String, String> property : getElements()) {
103:                         copy.addProperty(property.getKey(), property.getValue());
104:                 }
105:
106:                 return copy;
107:         }
108:
109:         @Override
110:         protected String getElementName(Map.Entry<String, String> element) {
111:                 return element.getKey();
112:         }
113:
114:         protected Collection<Entry<String, String>> getElementsToWrite() {
115:                 return getElements();
116:         }
117:
118:         /*
119:          * (non-Javadoc)
120:          * @see
121:          * org.eclipse.emf.ecp.internal.core.util.Registry#notifyObservers(org.eclipse.emf.ecp.core.util.observer.
122:          * ECPObserver
123:          * , ELEMENT[], ELEMENT[])
124:          */
125:         @Override
126:         protected void notifyObservers(Collection<Map.Entry<String, String>> oldProperties,
127:                 Collection<Map.Entry<String, String>> newProperties) throws Exception {
128:                 ECPUtil.getECPObserverBus().notify(ECPPropertiesObserver.class)
129:                         .propertiesChanged(this, oldProperties, newProperties);
130:         }
131:
132:         // @Override
133:         // @SuppressWarnings("unchecked")
134:         // protected Map.Entry<String, String>[] createElementArray(int size) {
135:         // return new Map.Entry[size];
136:         // }
137:
138:         /**
139:          * @author Eike Stepper
140:          */
141:         public static final class Property implements Map.Entry<String, String> {
142:                 private final String key;
143:
144:                 private final String value;
145:
146:                 /**
147:                  * Default constructor.
148:                  *
149:                  * @param key the key of the property
150:                  * @param value the value of the property
151:                  */
152:                 public Property(String key, String value) {
153:                         this.key = key;
154:                         this.value = value;
155:                 }
156:
157:                 /** {@inheritDoc} */
158:                 @Override
159:                 public String getKey() {
160:                         return key;
161:                 }
162:
163:                 /** {@inheritDoc} */
164:                 @Override
165:                 public String getValue() {
166:                         return value;
167:                 }
168:
169:                 /** {@inheritDoc} */
170:                 @Override
171:                 public String setValue(String value) {
172:                         throw new UnsupportedOperationException();
173:                 }
174:
175:                 @Override
176:                 public String toString() {
177:                         return key + " --> " + value; //$NON-NLS-1$
178:                 }
179:         }
180:
181: }