Source Code Cross Referenced for RowColumnVector.java in  » HTML-Parser » jericho-html » au » id » jericho » lib » html » 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 » HTML Parser » jericho html » au.id.jericho.lib.html 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Jericho HTML Parser - Java based library for analysing and manipulating HTML
002:        // Version 2.5
003:        // Copyright (C) 2007 Martin Jericho
004:        // http://jerichohtml.sourceforge.net/
005:        //
006:        // This library is free software; you can redistribute it and/or
007:        // modify it under the terms of either one of the following licences:
008:        //
009:        // 1. The Eclipse Public License (EPL) version 1.0,
010:        // included in this distribution in the file licence-epl-1.0.html
011:        // or available at http://www.eclipse.org/legal/epl-v10.html
012:        //
013:        // 2. The GNU Lesser General Public License (LGPL) version 2.1 or later,
014:        // included in this distribution in the file licence-lgpl-2.1.txt
015:        // or available at http://www.gnu.org/licenses/lgpl.txt
016:        //
017:        // This library is distributed on an "AS IS" basis,
018:        // WITHOUT WARRANTY OF ANY KIND, either express or implied.
019:        // See the individual licence texts for more details.
020:
021:        package au.id.jericho.lib.html;
022:
023:        import java.util.*;
024:
025:        /**
026:         * Represents the row and column number of a character position in the source document.
027:         * <p>
028:         * Obtained using the {@link Source#getRowColumnVector(int pos)} method.
029:         */
030:        public final class RowColumnVector {
031:            private int row;
032:            private int column;
033:            private int pos;
034:
035:            private static final RowColumnVector FIRST = new RowColumnVector(1,
036:                    1, 0);
037:
038:            private RowColumnVector(final int row, final int column,
039:                    final int pos) {
040:                this .row = row;
041:                this .column = column;
042:                this .pos = pos;
043:            }
044:
045:            /**
046:             * Returns the row number of this character position in the source document.
047:             * @return the row number of this character position in the source document.
048:             */
049:            public int getRow() {
050:                return row;
051:            }
052:
053:            /**
054:             * Returns the column number of this character position in the source document.
055:             * @return the column number of this character position in the source document.
056:             */
057:            public int getColumn() {
058:                return column;
059:            }
060:
061:            /**
062:             * Returns the character position in the source document.
063:             * @return the character position in the source document.
064:             */
065:            public int getPos() {
066:                return pos;
067:            }
068:
069:            /**
070:             * Returns a string representation of this character position.
071:             * <p>
072:             * The returned string has the format "<code>(</code><i>row</i><code>,</code><i>column</i><code>:</code><i>pos</i><code>)</code>".
073:             *
074:             * @return a string representation of this character position.
075:             */
076:            public String toString() {
077:                return appendTo(new StringBuffer(20)).toString();
078:            }
079:
080:            StringBuffer appendTo(final StringBuffer sb) {
081:                return sb.append("(r").append(row).append(",c").append(column)
082:                        .append(",p").append(pos).append(')');
083:            }
084:
085:            static RowColumnVector[] getCacheArray(final Source source) {
086:                final int lastSourcePos = source.end - 1;
087:                final ArrayList list = new ArrayList();
088:                int pos = 0;
089:                list.add(FIRST);
090:                int row = 1;
091:                while (pos <= lastSourcePos) {
092:                    final char ch = source.charAt(pos);
093:                    if (ch == '\n'
094:                            || (ch == '\r' && (pos == lastSourcePos || source
095:                                    .charAt(pos + 1) != '\n')))
096:                        list.add(new RowColumnVector(++row, 1, pos + 1));
097:                    pos++;
098:                }
099:                return (RowColumnVector[]) list
100:                        .toArray(new RowColumnVector[list.size()]);
101:            }
102:
103:            static RowColumnVector get(final RowColumnVector[] cacheArray,
104:                    final int pos) {
105:                int low = 0;
106:                int high = cacheArray.length - 1;
107:                while (true) {
108:                    int mid = (low + high) >> 1;
109:                    final RowColumnVector rowColumnVector = cacheArray[mid];
110:                    if (rowColumnVector.pos < pos) {
111:                        if (mid == high)
112:                            return new RowColumnVector(rowColumnVector.row, pos
113:                                    - rowColumnVector.pos + 1, pos);
114:                        low = mid + 1;
115:                    } else if (rowColumnVector.pos > pos) {
116:                        high = mid - 1;
117:                    } else {
118:                        return rowColumnVector;
119:                    }
120:                }
121:            }
122:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.