KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > mdr > storagemodel > AttrUList


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.mdr.storagemodel;
20
21 import java.util.*;
22
23 import java.io.InputStream JavaDoc;
24 import java.io.IOException JavaDoc;
25
26 import javax.jmi.reflect.*;
27 import org.netbeans.mdr.persistence.MOFID;
28 import org.netbeans.mdr.persistence.StorageException;
29
30 /**
31  *
32  * @author Martin Matula
33  */

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 JavaDoc 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 JavaDoc type, String JavaDoc 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 JavaDoc obj) {
70         super.remove(obj);
71         return innerSet.remove(obj);
72     }
73     
74     public Object JavaDoc set(int param, Object JavaDoc obj) {
75         Object JavaDoc 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 JavaDoc remove(int param) {
100         Object JavaDoc retValue;
101         retValue = super.remove(param);
102         innerSet.remove(retValue);
103         return retValue;
104     }
105     
106     public void add(int param, Object JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc obj) {
144             if (!innerSet.add(obj)) {
145                 throw new DuplicateException(obj, getMetaElement());
146             }
147             super.add(obj);
148         }
149         
150         public void set(Object JavaDoc 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