Source Code Cross Referenced for Indenter.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » rmi » compiler » 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 » Apache Harmony Java SE » org package » org.apache.harmony.rmi.compiler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */
018:
019:        /**
020:         * @author  Vasily Zakharov
021:         * @version $Revision: 1.1.2.1 $
022:         */package org.apache.harmony.rmi.compiler;
023:
024:        import org.apache.harmony.rmi.internal.nls.Messages;
025:
026:        /**
027:         * Provides dynamic 4-space indents usable for source code generation.
028:         * All indents are measured in 4-space units.
029:         *
030:         * This class' methods are designed to be called right from the output stream
031:         * composition, i. e. <code>String output =
032:         * ("first line" + indenter.increase() + "second line");</code>
033:         *
034:         * @author  Vasily Zakharov
035:         * @version $Revision: 1.1.2.1 $
036:         */
037:        final class Indenter {
038:
039:            /**
040:             * String used for indentation.
041:             */
042:            private final String stepString = "    "; //$NON-NLS-1$
043:
044:            /**
045:             * Length of {@linkplain #stepString indentation string}.
046:             */
047:            private final int STEP_LENGTH = stepString.length();
048:
049:            /**
050:             * Indent string.
051:             */
052:            private String currentIndent;
053:
054:            /**
055:             * Create instance with zero starting indent.
056:             */
057:            Indenter() {
058:                currentIndent = new String();
059:            }
060:
061:            /**
062:             * Create instance with specified starting indent.
063:             *
064:             * @param   indent
065:             *          Starting indent.
066:             */
067:            Indenter(int indent) {
068:                this ();
069:
070:                if (indent > 0) {
071:                    increase(indent);
072:                }
073:            }
074:
075:            /**
076:             * Returns current indent string.
077:             *
078:             * @return  Current indent string.
079:             */
080:            String indent() {
081:                return currentIndent;
082:            }
083:
084:            /**
085:             * Increase current indent one step right.
086:             *
087:             * @return  Current (increased) indent string.
088:             */
089:            String increase() {
090:                return increase(1);
091:            }
092:
093:            /**
094:             * Increase current indent the specified number of steps right.
095:             *
096:             * @param   steps
097:             *          Number of steps to increase current indent.
098:             *
099:             * @return  Current (increased) indent string.
100:             */
101:            String increase(int steps) {
102:                return currentIndent = tIncrease(steps);
103:            }
104:
105:            /**
106:             * Decrease current indent one step left.
107:             *
108:             * @return  Current (decreased) indent string.
109:             *
110:             * @throws  IndexOutOfBoundsException
111:             *          If current indent is empty and thus cannot be decreased.
112:             */
113:            String decrease() throws IndexOutOfBoundsException {
114:                return decrease(1);
115:            }
116:
117:            /**
118:             * Decrease current indent the specified number of steps left.
119:             *
120:             * @param   steps
121:             *          Number of steps to decrease current indent.
122:             *
123:             * @return  Current (decreased) indent string.
124:             *
125:             * @throws  IndexOutOfBoundsException
126:             *          If current indent is empty and thus cannot be decreased.
127:             */
128:            String decrease(int steps) throws IndexOutOfBoundsException {
129:                return currentIndent = tDecrease(steps);
130:            }
131:
132:            /**
133:             * Increases current indent one step right, but returns empty string.
134:             *
135:             * @return  Empty string.
136:             */
137:            String hIncrease() {
138:                return hIncrease(1);
139:            }
140:
141:            /**
142:             * Increases current indent the specified number of steps right,
143:             * but returns empty string.
144:             *
145:             * @param   steps
146:             *          Number of steps to increase current indent.
147:             *
148:             * @return  Empty string.
149:             */
150:            String hIncrease(int steps) {
151:                increase(steps);
152:                return ""; //$NON-NLS-1$
153:            }
154:
155:            /**
156:             * Decreases current indent one step left, but returns empty string.
157:             *
158:             * @return  Empty string.
159:             *
160:             * @throws  IndexOutOfBoundsException
161:             *          If current indent is empty and thus cannot be decreased.
162:             */
163:            String hDecrease() throws IndexOutOfBoundsException {
164:                return hDecrease(1);
165:            }
166:
167:            /**
168:             * Decreases current indent the specified number of steps left,
169:             * but returns empty string.
170:             *
171:             * @param   steps
172:             *          Number of steps to decrease indent.
173:             *
174:             * @return  Empty string.
175:             *
176:             * @throws  IndexOutOfBoundsException
177:             *          If current indent is empty and thus cannot be decreased.
178:             */
179:            String hDecrease(int steps) throws IndexOutOfBoundsException {
180:                decrease(steps);
181:                return ""; //$NON-NLS-1$
182:            }
183:
184:            /**
185:             * Returns current indent temporary increased one step right.
186:             * The stored indent is not changed.
187:             *
188:             * @return  Increased indent string.
189:             */
190:            String tIncrease() {
191:                return tIncrease(1);
192:            }
193:
194:            /**
195:             * Returns current indent temporary increased the specified number of steps
196:             * right. The stored indent is not changed.
197:             *
198:             * @param   steps
199:             *          Number of steps to increase current indent.
200:             *
201:             * @return  Increased indent string.
202:             */
203:            String tIncrease(int steps) {
204:                StringBuffer buffer = new StringBuffer(currentIndent);
205:
206:                for (int i = 0; i < steps; i++) {
207:                    buffer.append(stepString);
208:                }
209:
210:                return buffer.toString();
211:            }
212:
213:            /**
214:             * Returns current indent temporary decreased one step left.
215:             * The stored indent is not changed.
216:             *
217:             * @return  Decreased indent string.
218:             *
219:             * @throws  IndexOutOfBoundsException
220:             *          If current indent is empty and thus cannot be decreased.
221:             */
222:            String tDecrease() throws IndexOutOfBoundsException {
223:                return tDecrease(1);
224:            }
225:
226:            /**
227:             * Returns current indent temporary decreased the specified number of steps
228:             * left. The stored indent is not changed.
229:             *
230:             * @param   steps
231:             *          Number of steps to decrease indent.
232:             *
233:             * @return  Decreased indent string.
234:             *
235:             * @throws  IndexOutOfBoundsException
236:             *          If current indent is empty and thus cannot be decreased.
237:             */
238:            String tDecrease(int steps) throws IndexOutOfBoundsException {
239:                return currentIndent.substring(0,
240:                        (currentIndent.length() - (steps * STEP_LENGTH)));
241:            }
242:
243:            /**
244:             * Return empty string if current indent is empty.
245:             * Throws {@link IllegalStateException} otherwise.
246:             *
247:             * @return  Empty string.
248:             *
249:             * @throws  IllegalStateException
250:             *          If current indent is not empty.
251:             */
252:            String assertEmpty() throws IllegalStateException {
253:                if (currentIndent.length() != 0) {
254:                    // rmi.56=Indenter assertion failed: current indent is not empty
255:                    throw new IllegalStateException(Messages
256:                            .getString("rmi.56")); //$NON-NLS-1$
257:                }
258:                return ""; //$NON-NLS-1$
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.