1 /*
2 * This file is a part of CAST project.
3 * (c) Copyright 2007, AGH University of Science & Technology
4 * https://caribou.iisg.agh.edu.pl/trac/cast
5 *
6 * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 * http://www.eclipse.org/legal/epl-v10.html
10 */
11 /*
12 * File: BrokenRowInfo.java
13 * Created: 2008-03-06
14 * Author: entrop, kpietak
15 * $Id: BrokenRowInfo.java 2308 2009-01-12 22:33:45Z kpietak $
16 */
17
18 package pl.edu.agh.cast.rawdata.stat;
19
20 import java.util.LinkedList;
21 import java.util.List;
22
23 import pl.edu.agh.cast.rawdata.DataRow;
24
25 /**
26 * Contains information about error in specified DataRow object.
27 *
28 * @author AGH CAST Team
29 */
30 public class BrokenRowInfo {
31
32 private List<BrokenCellInfo> brokenCells;
33
34 private DataRow sourceRow;
35
36 private boolean canBeConverted;
37
38 /**
39 * Constructor without statistics.
40 *
41 * @param sourceRow
42 * source row attached to broken row info object
43 */
44 public BrokenRowInfo(DataRow sourceRow) {
45 this.sourceRow = sourceRow;
46 this.canBeConverted = true;
47 this.brokenCells = new LinkedList<BrokenCellInfo>();
48
49 }
50
51 /**
52 * Creates and adds a new <code>BrokenCellInfo</code> object to broken cells list.
53 *
54 * @param columnIndex
55 * cell index in source row, if error concerns whole row, columnIndex is equal to
56 * <code>BrokenCellInfo.WHOLE_ROW_BROKEN</code> constant
57 * @param error
58 * error information which occurs in specified column
59 *
60 */
61 public void addBrokenCellInfo(int columnIndex, ErrorInfo error) {
62 BrokenCellInfo brokenCellInfo = new BrokenCellInfo(this, columnIndex, error);
63 brokenCells.add(brokenCellInfo);
64 if (error.getSeverity() == ErrorSeverity.ERROR) {
65 canBeConverted = false;
66 }
67
68 }
69
70 /**
71 * Checks if row can be converted. If <code>BrokenRowInfo</code> instance doesn't have error cells returns true.
72 *
73 * @return boolean value if source row can be converted
74 */
75 public boolean canBeConverted() {
76 return canBeConverted;
77 }
78
79 /**
80 * Checks if whole row is broken.
81 *
82 * @return true if error pertains to whole row, false otherwise
83 */
84 public boolean isRowError() {
85 for (BrokenCellInfo cellInfo : brokenCells) {
86 if (cellInfo.getColumn() == BrokenCellInfo.WHOLE_ROW_BROKEN) {
87 return true;
88 }
89 }
90 return false;
91 }
92
93 public List<BrokenCellInfo> getBrokenCells() {
94 return brokenCells;
95 }
96
97 public DataRow getSourceRow() {
98 return sourceRow;
99 }
100
101 /**
102 *
103 * {@inheritDoc}
104 *
105 * @see java.lang.Object#toString()
106 */
107 @Override
108 public String toString() {
109 StringBuffer res = new StringBuffer();
110 res.append("Data row: ").append(getSourceRow().toString()).append(//$NON-NLS-1$
111 ", broken cells: ").append(getBrokenCells().toString()).append(//$NON-NLS-1$
112 "]"); //$NON-NLS-1$
113 return res.toString();
114 }
115 }