Source Code Cross Referenced for SortedViewSetWrapper.java in  » Net » Terracotta » com » tcclient » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Terracotta » com.tcclient.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice.  All rights reserved.
003:         */
004:        package com.tcclient.util;
005:
006:        import com.tc.object.SerializationUtil;
007:        import com.tc.object.bytecode.ManagerUtil;
008:        import com.tc.util.SetIteratorWrapper;
009:
010:        import java.lang.reflect.Array;
011:        import java.util.Collection;
012:        import java.util.Comparator;
013:        import java.util.Iterator;
014:        import java.util.SortedSet;
015:
016:        /**
017:         * A wrapper for TreeSet.subSet(), TreeSet.headSet(), and TreeSet.tailSet() that keeps DSO informed of changes.
018:         */
019:        public final class SortedViewSetWrapper implements  SortedSet {
020:            public final static String CLASS_SLASH = "com/tcclient/util/SortedViewSetWrapper";
021:
022:            // viewSet is transient and is re-constructed from oringalSet,
023:            private transient SortedSet viewSet;
024:            // fromKey, toKey, and head.
025:            private SortedSet originalSet;
026:
027:            private Object fromKey;
028:            private Object toKey;
029:            private boolean head;
030:
031:            public SortedViewSetWrapper(SortedSet originalSet,
032:                    SortedSet viewSet, Object fromKey, Object toKey) {
033:                this .originalSet = originalSet;
034:                this .viewSet = viewSet;
035:                this .fromKey = fromKey;
036:                this .toKey = toKey;
037:            }
038:
039:            public SortedViewSetWrapper(SortedSet originalSet,
040:                    SortedSet viewSet, Object key, boolean head) {
041:                this .originalSet = originalSet;
042:                this .viewSet = viewSet;
043:                this .head = head;
044:                if (head) {
045:                    this .toKey = key;
046:                } else {
047:                    this .fromKey = key;
048:                }
049:            }
050:
051:            private SortedSet getViewSet() {
052:                if (viewSet == null) {
053:                    if (head) {
054:                        viewSet = ((SortedViewSetWrapper) originalSet
055:                                .headSet(toKey)).viewSet;
056:                    } else if (toKey == null) {
057:                        viewSet = ((SortedViewSetWrapper) originalSet
058:                                .tailSet(fromKey)).viewSet;
059:                    } else {
060:                        viewSet = ((SortedViewSetWrapper) originalSet.subSet(
061:                                fromKey, toKey)).viewSet;
062:                    }
063:                }
064:                return viewSet;
065:            }
066:
067:            public final boolean add(Object o) {
068:                ManagerUtil.checkWriteAccess(originalSet);
069:                boolean flag = getViewSet().add(o);
070:                if (flag) {
071:                    ManagerUtil
072:                            .logicalInvoke(originalSet,
073:                                    SerializationUtil.ADD_SIGNATURE,
074:                                    new Object[] { o });
075:                }
076:
077:                return flag;
078:            }
079:
080:            public final boolean addAll(Collection c) {
081:                ManagerUtil.checkWriteAccess(originalSet);
082:                boolean flag = getViewSet().addAll(c);
083:                if (flag) {
084:                    ManagerUtil.logicalInvoke(originalSet,
085:                            SerializationUtil.ADD_ALL_SIGNATURE,
086:                            new Object[] { c });
087:                }
088:
089:                return flag;
090:            }
091:
092:            public final void clear() {
093:                ManagerUtil.checkWriteAccess(originalSet);
094:                Object[] clearSet = getViewSet().toArray();
095:                getViewSet().clear();
096:                ManagerUtil.logicalInvoke(originalSet,
097:                        SerializationUtil.REMOVE_ALL_SIGNATURE, clearSet);
098:            }
099:
100:            public final boolean contains(Object o) {
101:                return getViewSet().contains(o);
102:            }
103:
104:            public final boolean containsAll(Collection c) {
105:                return getViewSet().containsAll(c);
106:            }
107:
108:            public final boolean equals(Object o) {
109:                return getViewSet().equals(o);
110:            }
111:
112:            public final int hashCode() {
113:                return getViewSet().hashCode();
114:            }
115:
116:            public final boolean isEmpty() {
117:                return getViewSet().isEmpty();
118:            }
119:
120:            public final Iterator iterator() {
121:                return new SetIteratorWrapper(getViewSet().iterator(),
122:                        originalSet);
123:            }
124:
125:            public final boolean remove(Object o) {
126:                ManagerUtil.checkWriteAccess(originalSet);
127:                boolean removed = getViewSet().remove(o);
128:                if (removed) {
129:                    ManagerUtil.logicalInvoke(originalSet,
130:                            SerializationUtil.REMOVE_SIGNATURE,
131:                            new Object[] { o });
132:                }
133:                return removed;
134:            }
135:
136:            public final boolean removeAll(Collection c) {
137:                boolean modified = false;
138:
139:                if (size() > c.size()) {
140:                    for (Iterator i = c.iterator(); i.hasNext();)
141:                        modified |= remove(i.next());
142:                } else {
143:                    for (Iterator i = iterator(); i.hasNext();) {
144:                        if (c.contains(i.next())) {
145:                            i.remove();
146:                            modified = true;
147:                        }
148:                    }
149:                }
150:                return modified;
151:            }
152:
153:            public final boolean retainAll(Collection c) {
154:                boolean modified = false;
155:                Iterator i = iterator();
156:                while (i.hasNext()) {
157:                    if (!c.contains(i.next())) {
158:                        i.remove();
159:                        modified = true;
160:                    }
161:                }
162:                return modified;
163:
164:            }
165:
166:            public final int size() {
167:                return getViewSet().size();
168:            }
169:
170:            public final Object[] toArray() {
171:                return getViewSet().toArray();
172:            }
173:
174:            public final Object[] toArray(Object[] a) {
175:                int size = size();
176:                if (a.length < size)
177:                    a = (Object[]) Array.newInstance(((Object) (a)).getClass()
178:                            .getComponentType(), size);
179:
180:                int index = 0;
181:                for (Iterator iterator = iterator(); iterator.hasNext();) {
182:                    ManagerUtil.objectArrayChanged(a, index++, iterator.next());
183:                }
184:
185:                if (a.length > size) {
186:                    a[size] = null;
187:                }
188:                return a;
189:            }
190:
191:            public final Comparator comparator() {
192:                return getViewSet().comparator();
193:            }
194:
195:            public final SortedSet subSet(Object fromElement, Object toElement) {
196:                return new SortedViewSetWrapper(originalSet,
197:                        ((SortedViewSetWrapper) viewSet.subSet(fromElement,
198:                                toElement)).viewSet, fromElement, toElement);
199:            }
200:
201:            public final SortedSet headSet(Object toElement) {
202:                return new SortedViewSetWrapper(
203:                        originalSet,
204:                        ((SortedViewSetWrapper) viewSet.headSet(toElement)).viewSet,
205:                        toElement, true);
206:            }
207:
208:            public final SortedSet tailSet(Object fromElement) {
209:                return new SortedViewSetWrapper(
210:                        originalSet,
211:                        ((SortedViewSetWrapper) viewSet.tailSet(fromElement)).viewSet,
212:                        fromElement, false);
213:            }
214:
215:            public final Object first() {
216:                return getViewSet().first();
217:            }
218:
219:            public final Object last() {
220:                return getViewSet().last();
221:            }
222:
223:            public String toString() {
224:                return viewSet.toString();
225:            }
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.