1 17 package org.eclipse.emf.ecore.change.impl; 18 19 20 import java.util.Collection ; 21 22 import org.eclipse.emf.common.notify.Notification; 23 import org.eclipse.emf.common.notify.NotificationChain; 24 import org.eclipse.emf.common.util.BasicEMap; 25 import org.eclipse.emf.common.util.EList; 26 import org.eclipse.emf.common.util.EMap; 27 import org.eclipse.emf.ecore.EClass; 28 import org.eclipse.emf.ecore.EObject; 29 import org.eclipse.emf.ecore.EStructuralFeature; 30 import org.eclipse.emf.ecore.InternalEObject; 31 import org.eclipse.emf.ecore.change.ChangePackage; 32 import org.eclipse.emf.ecore.change.FeatureChange; 33 import org.eclipse.emf.ecore.impl.ENotificationImpl; 34 import org.eclipse.emf.ecore.impl.EObjectImpl; 35 import org.eclipse.emf.ecore.util.EObjectContainmentEList; 36 import org.eclipse.emf.ecore.util.InternalEList; 37 38 39 53 public class EObjectToChangesMapEntryImpl extends EObjectImpl implements BasicEMap.Entry 54 { 55 58 protected static final int EPROXY_KEY = ELAST_EOBJECT_FLAG << 1; 59 60 68 protected EObject key = null; 69 70 78 protected EList value = null; 79 80 85 protected EObjectToChangesMapEntryImpl() 86 { 87 super(); 88 } 89 90 95 protected EClass eStaticClass() 96 { 97 return ChangePackage.eINSTANCE.getEObjectToChangesMapEntry(); 98 } 99 100 105 public EObject getTypedKeyGen() 106 { 107 if (key != null && key.eIsProxy()) 108 { 109 EObject oldKey = key; 110 key = (EObject)eResolveProxy((InternalEObject)key); 111 if (key != oldKey) 112 { 113 if (eNotificationRequired()) 114 eNotify(new ENotificationImpl(this, Notification.RESOLVE, ChangePackage.EOBJECT_TO_CHANGES_MAP_ENTRY__KEY, oldKey, key)); 115 } 116 } 117 return key; 118 } 119 120 125 public EObject getTypedKey() 126 { 127 if ((eFlags & EPROXY_KEY) != 0) 128 { 129 EObject newKey = getTypedKeyGen(); 130 if (!newKey.eIsProxy()) 131 { 132 eFlags &= ~EPROXY_KEY; 133 } 134 } 135 return key; 136 } 137 138 143 public EObject basicGetTypedKey() 144 { 145 return key; 146 } 147 148 153 public void setTypedKeyGen(EObject newKey) 154 { 155 EObject oldKey = key; 156 key = newKey; 157 if (eNotificationRequired()) 158 eNotify(new ENotificationImpl(this, Notification.SET, ChangePackage.EOBJECT_TO_CHANGES_MAP_ENTRY__KEY, oldKey, key)); 159 } 160 161 166 public void setTypedKey(EObject newKey) 167 { 168 setTypedKeyGen(newKey); 169 if (key != null) 170 { 171 eFlags |= EPROXY_KEY; 172 } 173 else 174 { 175 eFlags &= ~EPROXY_KEY; 176 } 177 } 178 179 184 public EList getTypedValue() 185 { 186 if (value == null) 187 { 188 value = new EObjectContainmentEList(FeatureChange.class, this, ChangePackage.EOBJECT_TO_CHANGES_MAP_ENTRY__VALUE); 189 } 190 return value; 191 } 192 193 198 public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) 199 { 200 if (featureID >= 0) 201 { 202 switch (eDerivedStructuralFeatureID(featureID, baseClass)) 203 { 204 case ChangePackage.EOBJECT_TO_CHANGES_MAP_ENTRY__VALUE: 205 return ((InternalEList)getTypedValue()).basicRemove(otherEnd, msgs); 206 default: 207 return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs); 208 } 209 } 210 return eBasicSetContainer(null, featureID, msgs); 211 } 212 213 218 public Object eGet(EStructuralFeature eFeature, boolean resolve) 219 { 220 switch (eDerivedStructuralFeatureID(eFeature)) 221 { 222 case ChangePackage.EOBJECT_TO_CHANGES_MAP_ENTRY__KEY: 223 if (resolve) return getTypedKey(); 224 return basicGetTypedKey(); 225 case ChangePackage.EOBJECT_TO_CHANGES_MAP_ENTRY__VALUE: 226 return getTypedValue(); 227 } 228 return eDynamicGet(eFeature, resolve); 229 } 230 231 236 public void eSet(EStructuralFeature eFeature, Object newValue) 237 { 238 switch (eDerivedStructuralFeatureID(eFeature)) 239 { 240 case ChangePackage.EOBJECT_TO_CHANGES_MAP_ENTRY__KEY: 241 setTypedKey((EObject)newValue); 242 return; 243 case ChangePackage.EOBJECT_TO_CHANGES_MAP_ENTRY__VALUE: 244 getTypedValue().clear(); 245 getTypedValue().addAll((Collection )newValue); 246 return; 247 } 248 eDynamicSet(eFeature, newValue); 249 } 250 251 256 public void eUnset(EStructuralFeature eFeature) 257 { 258 switch (eDerivedStructuralFeatureID(eFeature)) 259 { 260 case ChangePackage.EOBJECT_TO_CHANGES_MAP_ENTRY__KEY: 261 setTypedKey((EObject)null); 262 return; 263 case ChangePackage.EOBJECT_TO_CHANGES_MAP_ENTRY__VALUE: 264 getTypedValue().clear(); 265 return; 266 } 267 eDynamicUnset(eFeature); 268 } 269 270 275 public boolean eIsSet(EStructuralFeature eFeature) 276 { 277 switch (eDerivedStructuralFeatureID(eFeature)) 278 { 279 case ChangePackage.EOBJECT_TO_CHANGES_MAP_ENTRY__KEY: 280 return key != null; 281 case ChangePackage.EOBJECT_TO_CHANGES_MAP_ENTRY__VALUE: 282 return value != null && !value.isEmpty(); 283 } 284 return eDynamicIsSet(eFeature); 285 } 286 287 292 protected int hash = -1; 293 294 299 public int getHash() 300 { 301 if (hash == -1) 302 { 303 Object theKey = getKey(); 304 hash = (theKey == null ? 0 : theKey.hashCode()); 305 } 306 return hash; 307 } 308 309 314 public void setHash(int hash) 315 { 316 this.hash = hash; 317 } 318 319 324 public Object getKey() 325 { 326 return getTypedKey(); 327 } 328 329 334 public void setKey(Object key) 335 { 336 setTypedKey((EObject)key); 337 } 338 339 344 public Object getValue() 345 { 346 return getTypedValue(); 347 } 348 349 354 public Object setValue(Object value) 355 { 356 Object oldValue = getValue(); 357 getTypedValue().clear(); 358 getTypedValue().addAll((Collection )value); 359 return oldValue; 360 } 361 362 367 public EMap getEMap() 368 { 369 EObject container = eContainer(); 370 return container == null ? null : (EMap)container.eGet(eContainmentFeature()); 371 } 372 373 } | Popular Tags |