1 19 package org.netbeans.mdr.storagemodel; 20 21 import java.util.*; 22 23 import java.io.InputStream ; 24 import java.io.IOException ; 25 26 import javax.jmi.reflect.*; 27 import org.netbeans.mdr.persistence.MOFID; 28 import org.netbeans.mdr.persistence.StorageException; 29 30 34 public class AttrUList extends AttrList { 35 private Set innerSet = null; 36 37 public AttrUList() { 38 super(); 39 } 40 41 AttrUList(StorableFeatured mdrObject, StorableClass.AttributeDescriptor desc) throws StorageException { 42 this(mdrObject, desc, null); 43 } 44 45 public AttrUList(StorableFeatured mdrObject, StorableClass.AttributeDescriptor desc, List values) throws StorageException { 46 super(mdrObject, desc, values); 47 48 innerSet = new HashSet(); 49 for (Iterator it = inner.iterator(); it.hasNext();) { 50 Object value = it.next(); 51 if (!innerSet.add(value)) { 52 throw new DuplicateException(value, getMetaElement()); 53 } 54 } 55 } 56 57 protected AttrUList(StorableFeatured mdrObject, List values, int maxSize, Class type, String attrName, boolean isRefObject, MOFID metaMofId, Set innerSet) { 58 super(mdrObject, values, maxSize, type, attrName, isRefObject, metaMofId); 59 this.innerSet = innerSet; 60 } 61 62 protected void checkUnwrap() { 63 if (innerSet == null) { 64 super.checkUnwrap(); 65 innerSet = new HashSet(inner); 66 } 67 } 68 69 public boolean remove(Object obj) { 70 super.remove(obj); 71 return innerSet.remove(obj); 72 } 73 74 public Object set(int param, Object obj) { 75 Object retValue; 76 retValue = super.set(param, obj); 77 innerSet.remove(retValue); 78 if (!innerSet.add(obj)) { 79 throw new DuplicateException(obj, getMetaElement()); 80 } 81 return retValue; 82 } 83 84 public ListIterator listIterator(int param) { 85 checkUnwrap(); 86 return new AttrUListIterator(innerList.listIterator(param)); 87 } 88 89 public Iterator iterator() { 90 checkUnwrap(); 91 return new AttrUListIterator(innerList.listIterator()); 92 } 93 94 public ListIterator listIterator() { 95 checkUnwrap(); 96 return new AttrUListIterator(innerList.listIterator()); 97 } 98 99 public Object remove(int param) { 100 Object retValue; 101 retValue = super.remove(param); 102 innerSet.remove(retValue); 103 return retValue; 104 } 105 106 public void add(int param, Object obj) { 107 super.add(param, obj); 108 if (!innerSet.add(obj)) { 109 throw new DuplicateException(obj, getMetaElement()); 110 } 111 } 112 113 public boolean add(Object obj) { 114 super.add(obj); 115 return innerSet.add(obj); 116 } 117 118 public List subList(int param, int param1) { 119 checkUnwrap(); 120 return new AttrUList(mdrObject, innerList.subList(param, param1), maxSize, type, attrName, isRefObject, metaMofId, innerSet); 121 } 122 123 public boolean contains(Object obj) { 124 checkUnwrap(); 125 return innerSet.contains(obj); 126 } 127 128 public boolean containsAll(Collection collection) { 129 checkUnwrap(); 130 return innerSet.containsAll(collection); 131 } 132 133 protected class AttrUListIterator extends AttrListIterator { 134 protected AttrUListIterator(ListIterator iterator) { 135 super(iterator); 136 } 137 138 public void remove() { 139 super.remove(); 140 innerSet.remove(lastRead); 141 } 142 143 public void add(Object obj) { 144 if (!innerSet.add(obj)) { 145 throw new DuplicateException(obj, getMetaElement()); 146 } 147 super.add(obj); 148 } 149 150 public void set(Object obj) { 151 super.set(obj); 152 innerSet.remove(lastRead); 153 if (!innerSet.add(obj)) { 154 throw new DuplicateException(obj, getMetaElement()); 155 } 156 } 157 } 158 } 159 | Popular Tags |