View Javadoc

1   /*
2    * Copyright (c) 2007 Creative Sphere Limited.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *
10   *   Creative Sphere - initial API and implementation
11   *
12   */
13  package org.abstracthorizon.aequo.text;
14  
15  import org.abstracthorizon.aequo.CompareEntry;
16  import org.abstracthorizon.aequo.DefaultCompareEntry;
17  import org.abstracthorizon.aequo.util.StringUtils;
18  
19  /**
20   * Text compare entry adds line number to an entry. 
21   * 
22   *
23   * @author Daniel Sendula
24   */
25  public class TextCompareEntry extends DefaultCompareEntry<String> {
26      
27      /** File sizes */
28      protected int[] lineNumbers;
29      
30      /**
31       * Constructor
32       * @param lines lines
33       */
34      public TextCompareEntry(String[] lines, int[] lineNumbers) {
35          super(lines);
36          this.lineNumbers = lineNumbers;
37      }
38  
39      /**
40       * Returns line number of asked column
41       * @param column column
42       * @return line number of asked column
43       */
44      public int getLineNumber(int column) {
45          return lineNumbers[column];
46      }
47  
48      /**
49       * Returns array of line numbers 
50       * @return array of line numbers
51       */
52      public int[] getLineNumbers() {
53          return lineNumbers;
54      }
55      
56      /**
57       * Sets line number for asked column
58       * @param column column
59       * @param lineNumber line number
60       */
61      public void setLineNumber(int column, int lineNumber) {
62          lineNumbers[column] = lineNumber;
63      }
64  
65      public void updateEntryStatus() {
66          String left = getData(0);
67          String right = getData(1);
68          if (left == right) {
69              status[0] = EQUAL;
70          } else if ((left != null) && (right != null)) {
71              if (left.equals(right)) {
72                  status[0] = EQUAL;
73                  status[1] = EQUAL;
74              } else {
75                  left = StringUtils.collapseWhitespace(left);
76                  right = StringUtils.collapseWhitespace(right);
77                  if (left.equals(right)) {
78                      status[0] = TextCompareEntry.SIMILAR;
79                      status[1] = TextCompareEntry.SIMILAR;
80                  } else {
81                      status[0] = DIFFERENT;
82                      status[1] = DIFFERENT;
83                  }
84              }
85          } else {
86              if (left == null) {
87                  status[0] = CompareEntry.EMPTY;
88                  status[1] = DIFFERENT;
89              } else {
90                  status[0] = DIFFERENT;
91                  status[1] = CompareEntry.EMPTY;
92              }
93          }
94      }
95  }