01: /* Copyright (C) 2003 Finalist IT Group
02: *
03: * This file is part of JAG - the Java J2EE Application Generator
04: *
05: * JAG is free software; you can redistribute it and/or modify
06: * it under the terms of the GNU General Public License as published by
07: * the Free Software Foundation; either version 2 of the License, or
08: * (at your option) any later version.
09: * JAG is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: * You should have received a copy of the GNU General Public License
14: * along with JAG; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16: */
17:
18: package com.finalist.util;
19:
20: import com.lowagie.text.html.HtmlEncoder;
21:
22: /**
23: * This class represents a line of text from a source file that conflicted during the diff process.
24: *
25: * @author Michael O'Connor - Finalist IT Group.
26: */
27: public class DiffConflictLine {
28:
29: private String line;
30: private int number;
31: private boolean firstFile;
32:
33: /** A special case of DiffConflictLine, used to represent the last line in a file. */
34: public static final DiffConflictLine EOF = new DiffConflictLine();
35:
36: /**
37: * Constructs a DiffConflictLine.
38: * @param firstFile <code>true</code> if this line comes from the 'first' file (a diff involves 2 files).
39: * @param number the line number within the original file.
40: * @param line the text of the line.
41: */
42: public DiffConflictLine(boolean firstFile, int number, String line) {
43: this .number = number;
44: this .firstFile = firstFile;
45: this .line = line;
46: }
47:
48: private DiffConflictLine() {
49: }
50:
51: /**
52: * Checks if the given line has the same text as this one (ignoring whitespace).
53: * @param line2 the other line.
54: * @return <code>true</code> if equal.
55: */
56: public boolean lineEquals(DiffConflictLine line2) {
57: return line.trim().equals(line2.getLine().trim());
58: }
59:
60: public String getLine() {
61: return line;
62: }
63:
64: public boolean isEof() {
65: return (this == EOF);
66: }
67:
68: public int getLineNumber() {
69: return number;
70: }
71:
72: public boolean isFirstFile() {
73: return firstFile;
74: }
75:
76: /**
77: * By default this renders a HTML result.
78: * @return
79: */
80: public String toString() {
81: return "<font class='file" + (firstFile ? "1" : "2")
82: + "-code'>" + (firstFile ? "<" : ">")
83: + HtmlEncoder.encode(getLine()) + "</font><br>";
84: }
85:
86: /**
87: * Checks if a given conflict line precedes this one.
88: *
89: * @param next
90: * @return
91: */
92: public boolean precedes(DiffConflictLine next) {
93: return next != null && (firstFile == next.firstFile)
94: && next.getLineNumber() == number + 1;
95: }
96:
97: }
|