Source Code Cross Referenced for CharQueue.java in  » Database-ORM » toplink » persistence » antlr » 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 » toplink » persistence.antlr 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        package persistence.antlr;
02:
03:        /* ANTLR Translator Generator
04:         * Project led by Terence Parr at http://www.jGuru.com
05:         * Software rights: http://www.antlr.org/license.html
06:         *
07:         */
08:
09:        /** A circular buffer object used by CharBuffer */
10:        public class CharQueue {
11:            /** Physical circular buffer of tokens */
12:            protected char[] buffer;
13:            /** buffer.length-1 for quick modulos */
14:            private int sizeLessOne;
15:            /** physical index of front token */
16:            private int offset;
17:            /** number of tokens in the queue */
18:            protected int nbrEntries;
19:
20:            public CharQueue(int minSize) {
21:                // Find first power of 2 >= to requested size
22:                int size;
23:                if (minSize < 0) {
24:                    init(16); // pick some value for them
25:                    return;
26:                }
27:                // check for overflow
28:                if (minSize >= (Integer.MAX_VALUE / 2)) {
29:                    init(Integer.MAX_VALUE); // wow that's big.
30:                    return;
31:                }
32:                for (size = 2; size < minSize; size *= 2) {
33:                }
34:                init(size);
35:            }
36:
37:            /** Add token to end of the queue
38:             * @param tok The token to add
39:             */
40:            public final void append(char tok) {
41:                if (nbrEntries == buffer.length) {
42:                    expand();
43:                }
44:                buffer[(offset + nbrEntries) & sizeLessOne] = tok;
45:                nbrEntries++;
46:            }
47:
48:            /** Fetch a token from the queue by index
49:             * @param idx The index of the token to fetch, where zero is the token at the front of the queue
50:             */
51:            public final char elementAt(int idx) {
52:                return buffer[(offset + idx) & sizeLessOne];
53:            }
54:
55:            /** Expand the token buffer by doubling its capacity */
56:            private final void expand() {
57:                char[] newBuffer = new char[buffer.length * 2];
58:                // Copy the contents to the new buffer
59:                // Note that this will store the first logical item in the
60:                // first physical array element.
61:                for (int i = 0; i < buffer.length; i++) {
62:                    newBuffer[i] = elementAt(i);
63:                }
64:                // Re-initialize with new contents, keep old nbrEntries
65:                buffer = newBuffer;
66:                sizeLessOne = buffer.length - 1;
67:                offset = 0;
68:            }
69:
70:            /** Initialize the queue.
71:             * @param size The initial size of the queue
72:             */
73:            public void init(int size) {
74:                // Allocate buffer
75:                buffer = new char[size];
76:                // Other initialization
77:                sizeLessOne = size - 1;
78:                offset = 0;
79:                nbrEntries = 0;
80:            }
81:
82:            /** Clear the queue. Leaving the previous buffer alone.
83:             */
84:            public final void reset() {
85:                offset = 0;
86:                nbrEntries = 0;
87:            }
88:
89:            /** Remove char from front of queue */
90:            public final void removeFirst() {
91:                offset = (offset + 1) & sizeLessOne;
92:                nbrEntries--;
93:            }
94:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.