Source Code Cross Referenced for CharArrayIterator.java in  » 6.0-JDK-Core » AWT » java » awt » font » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
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
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » AWT » java.awt.font 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 1999 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025
026        package java.awt.font;
027
028        import java.text.CharacterIterator;
029
030        class CharArrayIterator implements  CharacterIterator {
031
032            private char[] chars;
033            private int pos;
034            private int begin;
035
036            CharArrayIterator(char[] chars) {
037
038                reset(chars, 0);
039            }
040
041            CharArrayIterator(char[] chars, int begin) {
042
043                reset(chars, begin);
044            }
045
046            /**
047             * Sets the position to getBeginIndex() and returns the character at that
048             * position.
049             * @return the first character in the text, or DONE if the text is empty
050             * @see getBeginIndex
051             */
052            public char first() {
053
054                pos = 0;
055                return current();
056            }
057
058            /**
059             * Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty)
060             * and returns the character at that position.
061             * @return the last character in the text, or DONE if the text is empty
062             * @see getEndIndex
063             */
064            public char last() {
065
066                if (chars.length > 0) {
067                    pos = chars.length - 1;
068                } else {
069                    pos = 0;
070                }
071                return current();
072            }
073
074            /**
075             * Gets the character at the current position (as returned by getIndex()).
076             * @return the character at the current position or DONE if the current
077             * position is off the end of the text.
078             * @see getIndex
079             */
080            public char current() {
081
082                if (pos >= 0 && pos < chars.length) {
083                    return chars[pos];
084                } else {
085                    return DONE;
086                }
087            }
088
089            /**
090             * Increments the iterator's index by one and returns the character
091             * at the new index.  If the resulting index is greater or equal
092             * to getEndIndex(), the current index is reset to getEndIndex() and
093             * a value of DONE is returned.
094             * @return the character at the new position or DONE if the new
095             * position is off the end of the text range.
096             */
097            public char next() {
098
099                if (pos < chars.length - 1) {
100                    pos++;
101                    return chars[pos];
102                } else {
103                    pos = chars.length;
104                    return DONE;
105                }
106            }
107
108            /**
109             * Decrements the iterator's index by one and returns the character
110             * at the new index. If the current index is getBeginIndex(), the index
111             * remains at getBeginIndex() and a value of DONE is returned.
112             * @return the character at the new position or DONE if the current
113             * position is equal to getBeginIndex().
114             */
115            public char previous() {
116
117                if (pos > 0) {
118                    pos--;
119                    return chars[pos];
120                } else {
121                    pos = 0;
122                    return DONE;
123                }
124            }
125
126            /**
127             * Sets the position to the specified position in the text and returns that
128             * character.
129             * @param position the position within the text.  Valid values range from
130             * getBeginIndex() to getEndIndex().  An IllegalArgumentException is thrown
131             * if an invalid value is supplied.
132             * @return the character at the specified position or DONE if the specified position is equal to getEndIndex()
133             */
134            public char setIndex(int position) {
135
136                position -= begin;
137                if (position < 0 || position > chars.length) {
138                    throw new IllegalArgumentException("Invalid index");
139                }
140                pos = position;
141                return current();
142            }
143
144            /**
145             * Returns the start index of the text.
146             * @return the index at which the text begins.
147             */
148            public int getBeginIndex() {
149                return begin;
150            }
151
152            /**
153             * Returns the end index of the text.  This index is the index of the first
154             * character following the end of the text.
155             * @return the index after the last character in the text
156             */
157            public int getEndIndex() {
158                return begin + chars.length;
159            }
160
161            /**
162             * Returns the current index.
163             * @return the current index.
164             */
165            public int getIndex() {
166                return begin + pos;
167            }
168
169            /**
170             * Create a copy of this iterator
171             * @return A copy of this
172             */
173            public Object clone() {
174                CharArrayIterator c = new CharArrayIterator(chars, begin);
175                c.pos = this .pos;
176                return c;
177            }
178
179            void reset(char[] chars) {
180                reset(chars, 0);
181            }
182
183            void reset(char[] chars, int begin) {
184
185                this .chars = chars;
186                this .begin = begin;
187                pos = 0;
188            }
189        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.