1 19 package org.netbeans.mdr.storagemodel; 20 21 import java.util.*; 22 23 import org.netbeans.mdr.persistence.*; 24 import org.netbeans.mdr.util.DebugException; 25 import org.netbeans.mdr.util.Logger; 26 27 33 public class IndexImmutSet implements Collection { 34 35 36 37 38 39 protected final MdrStorage storage; 40 protected final MultivaluedIndex index; 41 protected final Object indexKey; 42 43 44 45 46 47 52 protected IndexImmutSet(MdrStorage storage, MultivaluedIndex index, Object indexKey) { 53 this.storage = storage; 54 this.index = index; 55 this.indexKey = indexKey; 56 } 57 58 59 60 61 62 protected Collection getItems() { 63 try { 64 return index.getItems(indexKey); 65 } catch (StorageException e) { 66 throw (DebugException) Logger.getDefault().annotate(new DebugException(), e); 67 } 68 } 69 70 protected Collection getObjects() { 71 try { 72 return storage.getObjectsFromIndex(index, indexKey); 73 } catch (StorageException e) { 74 throw (DebugException) Logger.getDefault().annotate(new DebugException(), e); 75 } 76 } 77 78 79 80 81 82 public int size() { 83 return getItems().size(); 84 } 85 86 public boolean contains(Object obj) { 87 return getItems().contains(obj); 88 } 89 90 public Iterator iterator() { 91 return new IndexImmutIterator(getObjects().iterator()); 92 } 93 94 public boolean isEmpty() { 95 return getItems().isEmpty(); 96 } 97 98 public boolean containsAll(Collection collection) { 99 return getItems().containsAll(collection); 100 } 101 102 public Object [] toArray(Object [] obj) { 103 return getObjects().toArray(obj); 104 } 105 106 public Object [] toArray() { 107 return getObjects().toArray(); 108 } 109 110 113 public boolean remove(Object o) { 114 throw new UnsupportedOperationException (); 115 } 116 117 120 public boolean add(Object obj) { 121 throw new UnsupportedOperationException (); 122 } 123 124 127 public boolean removeAll(Collection collection) { 128 throw new UnsupportedOperationException (); 129 } 130 131 134 public boolean addAll(Collection collection) { 135 throw new UnsupportedOperationException (); 136 } 137 138 141 public boolean retainAll(Collection collection) { 142 throw new UnsupportedOperationException (); 143 } 144 145 148 public void clear() { 149 throw new UnsupportedOperationException (); 150 } 151 152 153 154 155 156 159 protected class IndexImmutIterator implements Iterator { 160 protected Iterator innerIterator; 161 162 protected IndexImmutIterator(Iterator innerIterator) { 163 this.innerIterator = innerIterator; 164 } 165 166 public boolean hasNext() { 167 return innerIterator.hasNext(); 168 } 169 170 public Object next() { 171 return innerIterator.next(); 172 } 173 174 177 public void remove() { 178 throw new UnsupportedOperationException (); 179 } 180 } 181 } 182 | Popular Tags |