Source Code Cross Referenced for PaginatedArrayList.java in  » Database-ORM » iBATIS » com » ibatis » common » 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 » Database ORM » iBATIS » com.ibatis.common.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright 2004 Clinton Begin
003:         *
004:         *  Licensed under the Apache License, Version 2.0 (the "License");
005:         *  you may not use this file except in compliance with the License.
006:         *  You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         *  Unless required by applicable law or agreed to in writing, software
011:         *  distributed under the License is distributed on an "AS IS" BASIS,
012:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         *  See the License for the specific language governing permissions and
014:         *  limitations under the License.
015:         */
016:        package com.ibatis.common.util;
017:
018:        import java.util.*;
019:
020:        /**
021:         * Implementation of PaginatedList backed by an ArrayList
022:         * @deprecated All paginated list features have been deprecated
023:         */
024:        public class PaginatedArrayList implements  PaginatedList {
025:
026:            private static final ArrayList EMPTY_LIST = new ArrayList(0);
027:
028:            private List list;
029:            private List page;
030:            private int pageSize;
031:            private int index;
032:
033:            /**
034:             * @param pageSize
035:             */
036:            public PaginatedArrayList(int pageSize) {
037:                this .pageSize = pageSize;
038:                this .index = 0;
039:                this .list = new ArrayList();
040:                repaginate();
041:            }
042:
043:            /**
044:             * Constructor to set the initial size and the page size
045:             * @param initialCapacity - the initial size
046:             * @param pageSize - the page size
047:             */
048:            public PaginatedArrayList(int initialCapacity, int pageSize) {
049:                this .pageSize = pageSize;
050:                this .index = 0;
051:                this .list = new ArrayList(initialCapacity);
052:                repaginate();
053:            }
054:
055:            /**
056:             * Constructor to create an instance using an existing collection
057:             * @param c - the collection to build the instance with
058:             * @param pageSize - the page size
059:             */
060:            public PaginatedArrayList(Collection c, int pageSize) {
061:                this .pageSize = pageSize;
062:                this .index = 0;
063:                this .list = new ArrayList(c);
064:                repaginate();
065:            }
066:
067:            private void repaginate() {
068:                if (list.isEmpty()) {
069:                    page = EMPTY_LIST;
070:                } else {
071:                    int start = index * pageSize;
072:                    int end = start + pageSize - 1;
073:                    if (end >= list.size()) {
074:                        end = list.size() - 1;
075:                    }
076:                    if (start >= list.size()) {
077:                        index = 0;
078:                        repaginate();
079:                    } else if (start < 0) {
080:                        index = list.size() / pageSize;
081:                        if (list.size() % pageSize == 0) {
082:                            index--;
083:                        }
084:                        repaginate();
085:                    } else {
086:                        page = list.subList(start, end + 1);
087:                    }
088:                }
089:            }
090:
091:            /* List accessors (uses page) */
092:
093:            public int size() {
094:                return page.size();
095:            }
096:
097:            public boolean isEmpty() {
098:                return page.isEmpty();
099:            }
100:
101:            public boolean contains(Object o) {
102:                return page.contains(o);
103:            }
104:
105:            public Iterator iterator() {
106:                return page.iterator();
107:            }
108:
109:            public Object[] toArray() {
110:                return page.toArray();
111:            }
112:
113:            public Object[] toArray(Object a[]) {
114:                return page.toArray(a);
115:            }
116:
117:            public boolean containsAll(Collection c) {
118:                return page.containsAll(c);
119:            }
120:
121:            public Object get(int index) {
122:                return page.get(index);
123:            }
124:
125:            public int indexOf(Object o) {
126:                return page.indexOf(o);
127:            }
128:
129:            public int lastIndexOf(Object o) {
130:                return page.lastIndexOf(o);
131:            }
132:
133:            public ListIterator listIterator() {
134:                return page.listIterator();
135:            }
136:
137:            public ListIterator listIterator(int index) {
138:                return page.listIterator(index);
139:            }
140:
141:            public List subList(int fromIndex, int toIndex) {
142:                return page.subList(fromIndex, toIndex);
143:            }
144:
145:            /* List mutators (uses master list) */
146:
147:            public boolean add(Object o) {
148:                boolean b = list.add(o);
149:                repaginate();
150:                return b;
151:            }
152:
153:            public boolean remove(Object o) {
154:                boolean b = list.remove(o);
155:                repaginate();
156:                return b;
157:            }
158:
159:            public boolean addAll(Collection c) {
160:                boolean b = list.addAll(c);
161:                repaginate();
162:                return b;
163:            }
164:
165:            public boolean addAll(int index, Collection c) {
166:                boolean b = list.addAll(index, c);
167:                repaginate();
168:                return b;
169:            }
170:
171:            public boolean removeAll(Collection c) {
172:                boolean b = list.removeAll(c);
173:                repaginate();
174:                return b;
175:            }
176:
177:            public boolean retainAll(Collection c) {
178:                boolean b = list.retainAll(c);
179:                repaginate();
180:                return b;
181:            }
182:
183:            public void clear() {
184:                list.clear();
185:                repaginate();
186:            }
187:
188:            public Object set(int index, Object element) {
189:                Object o = list.set(index, element);
190:                repaginate();
191:                return o;
192:            }
193:
194:            public void add(int index, Object element) {
195:                list.add(index, element);
196:                repaginate();
197:            }
198:
199:            public Object remove(int index) {
200:                Object o = list.remove(index);
201:                repaginate();
202:                return o;
203:            }
204:
205:            /* Paginated List methods */
206:
207:            public int getPageSize() {
208:                return pageSize;
209:            }
210:
211:            public boolean isFirstPage() {
212:                return index == 0;
213:            }
214:
215:            public boolean isMiddlePage() {
216:                return !(isFirstPage() || isLastPage());
217:            }
218:
219:            public boolean isLastPage() {
220:                return list.size() - ((index + 1) * pageSize) < 1;
221:            }
222:
223:            public boolean isNextPageAvailable() {
224:                return !isLastPage();
225:            }
226:
227:            public boolean isPreviousPageAvailable() {
228:                return !isFirstPage();
229:            }
230:
231:            public boolean nextPage() {
232:                if (isNextPageAvailable()) {
233:                    index++;
234:                    repaginate();
235:                    return true;
236:                } else {
237:                    return false;
238:                }
239:            }
240:
241:            public boolean previousPage() {
242:                if (isPreviousPageAvailable()) {
243:                    index--;
244:                    repaginate();
245:                    return true;
246:                } else {
247:                    return false;
248:                }
249:            }
250:
251:            public void gotoPage(int pageNumber) {
252:                index = pageNumber;
253:                repaginate();
254:            }
255:
256:            public int getPageIndex() {
257:                return index;
258:            }
259:
260:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.