Source Code Cross Referenced for RangeDifference.java in  » Content-Management-System » daisy » org » eclipse » compare » rangedifferencer » 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 » Content Management System » daisy » org.eclipse.compare.rangedifferencer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.compare.rangedifferencer;
011:
012:        /**
013:         * Description of a change between two or three ranges of comparable entities.
014:         * <p>
015:         * <code>RangeDifference</code> objects are the elements of a compare result returned from
016:         * the <code>RangeDifferencer</code> <code>find* </code> methods.
017:         * Clients use these objects as they are returned from the differencer.
018:         * This class is not intended to be instantiated or subclassed outside of the Compare framework.
019:         * <p>
020:         * Note: A range in the <code>RangeDifference</code> object is given as a start index
021:         * and length in terms of comparable entities. However, these entity indices and counts
022:         * are not necessarily character positions. For example, if an entity represents a line
023:         * in a document, the start index would be a line number and the count would be in lines.
024:         * </p>
025:         *
026:         * @see RangeDifferencer
027:         */
028:        public class RangeDifference {
029:
030:            /** Two-way change constant indicating no change. */
031:            public final static int NOCHANGE = 0;
032:            /** Two-way change constant indicating two-way change (same as <code>RIGHT</code>) */
033:            public final static int CHANGE = 2;
034:
035:            /** Three-way change constant indicating a change in both right and left. */
036:            public final static int CONFLICT = 1;
037:            /** Three-way change constant indicating a change in right. */
038:            public final static int RIGHT = 2;
039:            /** Three-way change constant indicating a change in left. */
040:            public final static int LEFT = 3;
041:            /**
042:             * Three-way change constant indicating the same change in both right and left,
043:             * that is only the ancestor is different.
044:             */
045:            public final static int ANCESTOR = 4;
046:
047:            /** Constant indicating an unknown change kind. */
048:            public final static int ERROR = 5;
049:
050:            /** the kind of change: NOCHANGE, CHANGE, LEFT, RIGHT, ANCESTOR, CONFLICT, ERROR */
051:            int fKind;
052:
053:            int fLeftStart;
054:            int fLeftLength;
055:            int fRightStart;
056:            int fRightLength;
057:            int lAncestorStart;
058:            int lAncestorLength;
059:
060:            /**
061:             * Creates a new range difference with the given change kind.
062:             *
063:             * @param changeKind the kind of change
064:             */
065:            /* package */RangeDifference(int changeKind) {
066:                fKind = changeKind;
067:            }
068:
069:            /**
070:             * Creates a new <code>RangeDifference</code> with the given change kind
071:             * and left and right ranges.
072:             *
073:             * @param kind the kind of change
074:             * @param rightStart start index of entity on right side
075:             * @param rightLength number of entities on right side
076:             * @param leftStart start index of entity on left side
077:             * @param leftLength number of entities on left side
078:             */
079:            public RangeDifference(int kind, int rightStart, int rightLength,
080:                    int leftStart, int leftLength) {
081:                fKind = kind;
082:                fRightStart = rightStart;
083:                fRightLength = rightLength;
084:                fLeftStart = leftStart;
085:                fLeftLength = leftLength;
086:            }
087:
088:            /**
089:             * Creates a new <code>RangeDifference</code> with the given change kind
090:             * and left, right, and ancestor ranges.
091:             *
092:             * @param kind the kind of change
093:             * @param rightStart start index of entity on right side
094:             * @param rightLength number of entities on right side
095:             * @param leftStart start index of entity on left side
096:             * @param leftLength number of entities on left side
097:             * @param ancestorStart start index of entity on ancestor side
098:             * @param ancestorLength number of entities on ancestor side
099:             */
100:            /* package */RangeDifference(int kind, int rightStart,
101:                    int rightLength, int leftStart, int leftLength,
102:                    int ancestorStart, int ancestorLength) {
103:                this (kind, rightStart, rightLength, leftStart, leftLength);
104:                lAncestorStart = ancestorStart;
105:                lAncestorLength = ancestorLength;
106:            }
107:
108:            /**
109:             * Returns the kind of difference.
110:             *
111:             * @return the kind of difference, one of
112:             * <code>NOCHANGE</code>, <code>CHANGE</code>, <code>LEFT</code>, <code>RIGHT</code>,
113:             * <code>ANCESTOR</code>, <code>CONFLICT</code>, <code>ERROR</code>
114:             */
115:            public int kind() {
116:                return fKind;
117:            }
118:
119:            /**
120:             * Returns the start index of the entity range on the ancestor side.
121:             *
122:             * @return the start index of the entity range on the ancestor side
123:             */
124:            public int ancestorStart() {
125:                return lAncestorStart;
126:            }
127:
128:            /**
129:             * Returns the number of entities on the ancestor side.
130:             *
131:             * @return the number of entities on the ancestor side
132:             */
133:            public int ancestorLength() {
134:                return lAncestorLength;
135:            }
136:
137:            /**
138:             * Returns the end index of the entity range on the ancestor side.
139:             *
140:             * @return the end index of the entity range on the ancestor side
141:             */
142:            public int ancestorEnd() {
143:                return lAncestorStart + lAncestorLength;
144:            }
145:
146:            /**
147:             * Returns the start index of the entity range on the right side.
148:             *
149:             * @return the start index of the entity range on the right side
150:             */
151:            public int rightStart() {
152:                return fRightStart;
153:            }
154:
155:            /**
156:             * Returns the number of entities on the right side.
157:             *
158:             * @return the number of entities on the right side
159:             */
160:            public int rightLength() {
161:                return fRightLength;
162:            }
163:
164:            /**
165:             * Returns the end index of the entity range on the right side.
166:             *
167:             * @return the end index of the entity range on the right side
168:             */
169:            public int rightEnd() {
170:                return fRightStart + fRightLength;
171:            }
172:
173:            /**
174:             * Returns the start index of the entity range on the left side.
175:             *
176:             * @return the start index of the entity range on the left side
177:             */
178:            public int leftStart() {
179:                return fLeftStart;
180:            }
181:
182:            /**
183:             * Returns the number of entities on the left side.
184:             *
185:             * @return the number of entities on the left side
186:             */
187:            public int leftLength() {
188:                return fLeftLength;
189:            }
190:
191:            /**
192:             * Returns the end index of the entity range on the left side.
193:             *
194:             * @return the end index of the entity range on the left side
195:             */
196:            public int leftEnd() {
197:                return fLeftStart + fLeftLength;
198:            }
199:
200:            /**
201:             * Returns the maximum number of entities in the left, right, and ancestor sides of this range.
202:             *
203:             * @return the maximum number of entities in the left, right, and ancestor sides of this range
204:             */
205:            public int maxLength() {
206:                return Math.max(fRightLength, Math.max(fLeftLength,
207:                        lAncestorLength));
208:            }
209:
210:            public boolean equals(Object obj) {
211:                if (obj instanceof  RangeDifference) {
212:                    RangeDifference other = (RangeDifference) obj;
213:                    return fKind == other.fKind
214:                            && fLeftStart == other.fLeftStart
215:                            && fLeftLength == other.fLeftLength
216:                            && fRightStart == other.fRightStart
217:                            && fRightLength == other.fRightLength
218:                            && lAncestorStart == other.lAncestorStart
219:                            && lAncestorLength == other.lAncestorLength;
220:                }
221:                return super .equals(obj);
222:            }
223:
224:            public String toString() {
225:                String string = "Left: " + toRangeString(fLeftStart, fLeftLength) + " Right: " + toRangeString(fRightStart, fRightLength); //$NON-NLS-1$ //$NON-NLS-2$
226:                if (lAncestorLength > 0 || lAncestorStart > 0)
227:                    string += " Ancestor: " + toRangeString(lAncestorStart, lAncestorLength); //$NON-NLS-1$
228:                return string;
229:            }
230:
231:            private String toRangeString(int start, int length) {
232:                return "(" + start + ", " + length + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
233:            }
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.