1 17 package org.eclipse.emf.ecore.util; 18 19 20 import java.lang.reflect.Array ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 import java.util.ListIterator ; 24 25 import org.eclipse.emf.common.notify.NotificationChain; 26 import org.eclipse.emf.common.util.BasicEList; 27 import org.eclipse.emf.common.util.BasicEMap; 28 import org.eclipse.emf.ecore.EClass; 29 import org.eclipse.emf.ecore.EObject; 30 import org.eclipse.emf.ecore.EStructuralFeature; 31 import org.eclipse.emf.ecore.InternalEObject; 32 33 34 public class EcoreEMap extends BasicEMap implements InternalEList, EStructuralFeature.Setting 35 { 36 protected EClass entryEClass; 37 protected Class entryClass; 38 39 public EcoreEMap(EClass entryEClass, Class entryClass, InternalEObject owner, int featureID) 40 { 41 this.entryClass = entryClass; 42 this.entryEClass = entryEClass; 43 delegateEList = new DelegateEObjectContainmentEList(entryClass, owner, featureID); 44 } 45 46 protected void initializeDelegateEList() 47 { 48 } 49 50 protected class DelegateEObjectContainmentEList extends EObjectContainmentEList 51 { 52 public DelegateEObjectContainmentEList(Class entryClass, InternalEObject owner, int featureID) 53 { 54 super(entryClass, owner, featureID); 55 } 56 57 protected void didAdd(int index, Object newObject) 58 { 59 doPut((Entry)newObject); 60 } 61 62 protected void didSet(int index, Object newObject, Object oldObject) 63 { 64 didRemove(index, oldObject); 65 didAdd(index, newObject); 66 } 67 68 protected void didRemove(int index, Object oldObject) 69 { 70 doRemove((Entry)oldObject); 71 } 72 73 protected void didClear(int size, Object [] oldObjects) 74 { 75 doClear(); 76 } 77 78 protected void didMove(int index, Object movedObject, int oldIndex) 79 { 80 doMove((Entry)movedObject); 81 } 82 } 83 84 protected BasicEList newList() 85 { 86 return 87 new BasicEList() 88 { 89 public Object [] newData(int listCapacity) 90 { 91 return (Object [])Array.newInstance(entryClass, listCapacity); 92 } 93 }; 94 } 95 96 protected Entry newEntry(int hash, Object key, Object value) 97 { 98 Entry entry = (Entry)entryEClass.getEPackage().getEFactoryInstance().create(entryEClass); 99 entry.setHash(hash); 100 entry.setKey(key); 101 entry.setValue(value); 102 return entry; 103 } 104 105 public Object basicGet(int index) 106 { 107 return ((InternalEList)delegateEList).basicGet(index); 108 } 109 110 public List basicList() 111 { 112 return ((InternalEList)delegateEList).basicList(); 113 } 114 115 118 public Iterator basicIterator() 119 { 120 return ((InternalEList)delegateEList).basicIterator(); 121 } 122 123 126 public ListIterator basicListIterator() 127 { 128 return ((InternalEList)delegateEList).basicListIterator(); 129 } 130 131 134 public ListIterator basicListIterator(int index) 135 { 136 return ((InternalEList)delegateEList).basicListIterator(index); 137 } 138 139 142 public NotificationChain basicRemove(Object object, NotificationChain notifications) 143 { 144 return ((InternalEList)delegateEList).basicRemove(object, notifications); 145 } 146 147 150 public NotificationChain basicAdd(Object object, NotificationChain notifications) 151 { 152 return ((InternalEList)delegateEList).basicAdd(object, notifications); 153 } 154 155 158 public void addUnique(Object object) 159 { 160 ((InternalEList)delegateEList).addUnique(object); 161 } 162 163 166 public void addUnique(int index, Object object) 167 { 168 ((InternalEList)delegateEList).addUnique(index, object); 169 } 170 171 174 public Object setUnique(int index, Object object) 175 { 176 return ((InternalEList)delegateEList).setUnique(index, object); 177 } 178 179 public EObject getEObject() 180 { 181 return ((EStructuralFeature.Setting)delegateEList).getEObject(); 182 } 183 184 public EStructuralFeature getEStructuralFeature() 185 { 186 return ((EStructuralFeature.Setting)delegateEList).getEStructuralFeature(); 187 } 188 189 public Object get(boolean resolve) 190 { 191 return ((EStructuralFeature.Setting)delegateEList).get(resolve); 192 } 193 194 public void set(Object value) 195 { 196 ((EStructuralFeature.Setting)delegateEList).set(value); 197 } 198 199 public boolean isSet() 200 { 201 return ((EStructuralFeature.Setting)delegateEList).isSet(); 202 } 203 204 public void unset() 205 { 206 ((EStructuralFeature.Setting)delegateEList).unset(); 207 } 208 } 209 | Popular Tags |