Source Code Cross Referenced for AbstractBooleanList.java in  » Development » PCJ » bak » pcj » list » 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 » Development » PCJ » bak.pcj.list 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Primitive Collections for Java.
003:         *  Copyright (C) 2002, 2003  Søren Bak
004:         *
005:         *  This library is free software; you can redistribute it and/or
006:         *  modify it under the terms of the GNU Lesser General Public
007:         *  License as published by the Free Software Foundation; either
008:         *  version 2.1 of the License, or (at your option) any later version.
009:         *
010:         *  This library is distributed in the hope that it will be useful,
011:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         *  Lesser General Public License for more details.
014:         *
015:         *  You should have received a copy of the GNU Lesser General Public
016:         *  License along with this library; if not, write to the Free Software
017:         *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         */
019:        package bak.pcj.list;
020:
021:        import bak.pcj.BooleanIterator;
022:        import bak.pcj.BooleanCollection;
023:        import bak.pcj.AbstractBooleanCollection;
024:        import bak.pcj.hash.DefaultBooleanHashFunction;
025:        import bak.pcj.util.Exceptions;
026:
027:        /**
028:         *  This class represents an abstract base for implementing
029:         *  lists of boolean values. All operations that can be implemented
030:         *  using iterators and the <tt>get()</tt> and <tt>set()</tt> methods
031:         *  are implemented as such. In most cases, this is
032:         *  hardly an efficient solution, and at least some of those
033:         *  methods should be overridden by sub-classes.
034:         *
035:         *  @author     S&oslash;ren Bak
036:         *  @version    1.2     21-08-2003 19:14
037:         *  @since      1.0
038:         */
039:        public abstract class AbstractBooleanList extends
040:                AbstractBooleanCollection implements  BooleanList {
041:
042:            /** Default constructor to be invoked by sub-classes. */
043:            protected AbstractBooleanList() {
044:            }
045:
046:            public boolean add(boolean v) {
047:                add(size(), v);
048:                return true;
049:            }
050:
051:            /**
052:             *  Throws <tt>UnsupportedOperationException</tt>.
053:             *
054:             *  @throws     UnsupportedOperationException
055:             *              unconditionally.
056:             */
057:            public void add(int index, boolean v) {
058:                Exceptions.unsupported("add");
059:            }
060:
061:            public boolean addAll(int index, BooleanCollection c) {
062:                if (index < 0 || index > size())
063:                    Exceptions.indexOutOfBounds(index, 0, size());
064:                BooleanIterator i = c.iterator();
065:                boolean result = i.hasNext();
066:                while (i.hasNext()) {
067:                    add(index, i.next());
068:                    index++;
069:                }
070:                return result;
071:            }
072:
073:            public int indexOf(boolean c) {
074:                return indexOf(0, c);
075:            }
076:
077:            /**
078:             *  @since      1.2
079:             */
080:            public int indexOf(int index, boolean c) {
081:                BooleanListIterator i = listIterator(index);
082:                while (i.hasNext())
083:                    if (i.next() == c)
084:                        return i.previousIndex();
085:                return -1;
086:            }
087:
088:            public BooleanIterator iterator() {
089:                return listIterator();
090:            }
091:
092:            public int lastIndexOf(boolean c) {
093:                BooleanListIterator i = listIterator(size());
094:                while (i.hasPrevious())
095:                    if (i.previous() == c)
096:                        return i.nextIndex();
097:                return -1;
098:            }
099:
100:            public int lastIndexOf(int index, boolean c) {
101:                BooleanListIterator i = listIterator(index);
102:                while (i.hasPrevious())
103:                    if (i.previous() == c)
104:                        return i.nextIndex();
105:                return -1;
106:            }
107:
108:            public BooleanListIterator listIterator() {
109:                return listIterator(0);
110:            }
111:
112:            public BooleanListIterator listIterator(final int index) {
113:                if (index < 0 || index > size())
114:                    Exceptions.indexOutOfBounds(index, 0, size());
115:
116:                return new BooleanListIterator() {
117:                    private int ptr = index;
118:                    private int lptr = -1;
119:
120:                    // -------------------------------------------------------
121:                    //      Implementation of Iterator
122:                    // -------------------------------------------------------
123:
124:                    public boolean hasNext() {
125:                        return ptr < size();
126:                    }
127:
128:                    public boolean next() {
129:                        if (ptr == size())
130:                            Exceptions.endOfIterator();
131:                        lptr = ptr++;
132:                        return get(lptr);
133:                    }
134:
135:                    public void remove() {
136:                        if (lptr == -1)
137:                            Exceptions.noElementToRemove();
138:                        AbstractBooleanList.this .removeElementAt(lptr);
139:                        if (lptr < ptr)
140:                            ptr--;
141:                        lptr = -1;
142:                    }
143:
144:                    // -------------------------------------------------------
145:                    //      Implementation of ListIterator
146:                    // -------------------------------------------------------
147:
148:                    public void add(boolean v) {
149:                        AbstractBooleanList.this .add(ptr++, v);
150:                        lptr = -1;
151:                    }
152:
153:                    public boolean hasPrevious() {
154:                        return ptr > 0;
155:                    }
156:
157:                    public int nextIndex() {
158:                        return ptr;
159:                    }
160:
161:                    public boolean previous() {
162:                        if (ptr == 0)
163:                            Exceptions.startOfIterator();
164:                        ptr--;
165:                        lptr = ptr;
166:                        return get(ptr);
167:                    }
168:
169:                    public int previousIndex() {
170:                        return ptr - 1;
171:                    }
172:
173:                    public void set(boolean v) {
174:                        if (lptr == -1)
175:                            Exceptions.noElementToSet();
176:                        AbstractBooleanList.this .set(lptr, v);
177:                    }
178:
179:                };
180:            }
181:
182:            /**
183:             *  Throws <tt>UnsupportedOperationException</tt>.
184:             *
185:             *  @throws     UnsupportedOperationException
186:             *              unconditionally.
187:             */
188:            public boolean removeElementAt(int index) {
189:                Exceptions.unsupported("removeElementAt");
190:                throw new RuntimeException();
191:            }
192:
193:            public boolean equals(Object obj) {
194:                if (this  == obj)
195:                    return true;
196:                if (!(obj instanceof  BooleanList))
197:                    return false;
198:                BooleanListIterator i1 = listIterator();
199:                BooleanListIterator i2 = ((BooleanList) obj).listIterator();
200:                while (i1.hasNext() && i2.hasNext())
201:                    if (i1.next() != i2.next())
202:                        return false;
203:                return !(i1.hasNext() || i2.hasNext());
204:            }
205:
206:            public int hashCode() {
207:                int h = 1;
208:                BooleanIterator i = iterator();
209:                while (i.hasNext())
210:                    h = (int) (31 * h + DefaultBooleanHashFunction.INSTANCE
211:                            .hash(i.next()));
212:                return h;
213:            }
214:
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.