]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/diff/TableDiffPosition.java
Fix SLC demo
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / diff / TableDiffPosition.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.slc.diff;
17
18 import org.argeo.slc.UnsupportedException;
19
20 /**
21 * A diff position within a table structure such a CSV file or an SQL result
22 * set.
23 */
24 public class TableDiffPosition extends DiffPosition {
25 private Integer line;
26 /** Can be null */
27 private Integer column;
28 /** Can be null */
29 private String columnName;
30
31 public TableDiffPosition(RelatedFile relatedFile, Integer line,
32 Integer column, String columnName) {
33 super(relatedFile);
34 this.line = line;
35 this.column = column;
36 this.columnName = columnName;
37 }
38
39 @SuppressWarnings("unused")
40 private TableDiffPosition() {
41 }
42
43 public Integer getLine() {
44 return line;
45 }
46
47 public Integer getColumn() {
48 return column;
49 }
50
51 public String getColumnName() {
52 return columnName;
53 }
54
55 public int compareTo(DiffPosition dp) {
56 if (!(dp instanceof TableDiffPosition))
57 throw new UnsupportedException("position", dp);
58
59 TableDiffPosition o = (TableDiffPosition) dp;
60 if (relatedFile.equals(o.relatedFile)) {
61 if (line == o.line) {
62 return column.compareTo(o.column);
63 } else {
64 return line.compareTo(o.line);
65 }
66 } else {
67 return relatedFile.compareTo(o.relatedFile);
68 }
69 }
70
71 @Override
72 public String toString() {
73 StringBuffer buf = new StringBuffer("");
74 buf.append(relatedFile).append('[').append(line);
75 if (column != null) {
76 buf.append(',').append(column);
77 if (columnName != null) {
78 buf.append('-').append(columnName);
79 }
80 }
81 buf.append(']');
82 return buf.toString();
83 }
84
85 // Hibernate
86 @SuppressWarnings("unused")
87 private void setLine(Integer line) {
88 this.line = line;
89 }
90
91 @SuppressWarnings("unused")
92 private void setColumn(Integer column) {
93 this.column = column;
94 }
95
96 @SuppressWarnings("unused")
97 private void setColumnName(String columnName) {
98 this.columnName = columnName;
99 }
100
101 }