]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/diff/TableDiffPosition.java
add some private constructors with no arg, some getters & setters and some ids to...
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / main / java / org / argeo / slc / diff / TableDiffPosition.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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
17 package org.argeo.slc.diff;
18
19 import org.argeo.slc.UnsupportedException;
20
21 /**
22 * A diff position within a table structure such a CSV file or an SQL result
23 * set.
24 */
25 public class TableDiffPosition extends DiffPosition {
26 private Integer line;
27 /** Can be null */
28 private Integer column;
29 /** Can be null */
30 private String columnName;
31
32 public TableDiffPosition(RelatedFile relatedFile, Integer line,
33 Integer column, String columnName) {
34 super(relatedFile);
35 this.line = line;
36 this.column = column;
37 this.columnName = columnName;
38 }
39
40 @SuppressWarnings("unused")
41 private TableDiffPosition() {
42 }
43
44 public Integer getLine() {
45 return line;
46 }
47
48 public Integer getColumn() {
49 return column;
50 }
51
52 public String getColumnName() {
53 return columnName;
54 }
55
56 public int compareTo(DiffPosition dp) {
57 if (!(dp instanceof TableDiffPosition))
58 throw new UnsupportedException("position", dp);
59
60 TableDiffPosition o = (TableDiffPosition) dp;
61 if (relatedFile.equals(o.relatedFile)) {
62 if (line == o.line) {
63 return column.compareTo(o.column);
64 } else {
65 return line.compareTo(o.line);
66 }
67 } else {
68 return relatedFile.compareTo(o.relatedFile);
69 }
70 }
71
72 @Override
73 public String toString() {
74 StringBuffer buf = new StringBuffer("");
75 buf.append(relatedFile).append('[').append(line);
76 if (column != null) {
77 buf.append(',').append(column);
78 if (columnName != null) {
79 buf.append('-').append(columnName);
80 }
81 }
82 buf.append(']');
83 return buf.toString();
84 }
85
86 // Hibernate
87 @SuppressWarnings("unused")
88 private void setLine(Integer line) {
89 this.line = line;
90 }
91
92 @SuppressWarnings("unused")
93 private void setColumn(Integer column) {
94 this.column = column;
95 }
96
97 @SuppressWarnings("unused")
98 private void setColumnName(String columnName) {
99 this.columnName = columnName;
100 }
101
102 }