34
34
*
35
35
* <p>This is how you can use it:</p>
36
36
*
37
- * new XsRow(new TextCell("txt"), new NumberCell(2))
38
- *
37
+ * new XsRow(new TextCell("txt"), new NumberCell(2))
39
38
* @author Vedran Grgo Vatavuk (123vgv@gmail.com)
40
39
* @version $Id$
41
40
* @since 0.1
42
41
*/
43
42
@ SuppressWarnings ("PMD.TooManyMethods" )
44
43
public final class XsRow implements ERow {
45
44
45
+ /**
46
+ * Row position.
47
+ */
48
+ private final int index ;
49
+
46
50
/**
47
51
* Array of cells.
48
52
*/
@@ -56,17 +60,36 @@ public XsRow(final ECell... elements) {
56
60
this (new Array <>(elements ));
57
61
}
58
62
63
+ /**
64
+ * Ctor.
65
+ * @param position Row position
66
+ * @param elements Cells
67
+ */
68
+ public XsRow (final int position , final ECell ... elements ) {
69
+ this (position , new Array <>(elements ));
70
+ }
71
+
59
72
/**
60
73
* Ctor.
61
74
* @param elements Cells
62
75
*/
63
76
public XsRow (final Iterable <ECell > elements ) {
77
+ this (-1 , new Array <>(elements ));
78
+ }
79
+
80
+ /**
81
+ * Ctor.
82
+ * @param position Row position
83
+ * @param elements Cells
84
+ */
85
+ public XsRow (final int position , final Iterable <ECell > elements ) {
86
+ this .index = position ;
64
87
this .cells = new Array <>(elements );
65
88
}
66
89
67
90
@ Override
68
91
public Row attachTo (final Sheet sheet ) {
69
- final Row row = sheet .createRow (sheet . getLastRowNum () + 1 );
92
+ final Row row = this .createRow (sheet );
70
93
for (final ECell cell : this .cells ) {
71
94
cell .attachTo (row );
72
95
}
@@ -87,11 +110,6 @@ public ERow with(final ECell... elements) {
87
110
return new XsRow (this .cells .with (new Array <>(elements )));
88
111
}
89
112
90
- @ Override
91
- public ERow with (final ECell cell ) {
92
- return new XsRow (this .cells .with (cell ));
93
- }
94
-
95
113
@ Override
96
114
public ERow with (final ECells elements ) {
97
115
return new XsRow (this .cells .with (elements .asArray ()));
@@ -103,6 +121,24 @@ public XsRow.WithProps with(final Props<Row> props) {
103
121
return new XsRow .WithProps (this , props );
104
122
}
105
123
124
+ /**
125
+ * Create new row.
126
+ * @param sheet Sheet
127
+ * @return Row Row
128
+ */
129
+ private Row createRow (final Sheet sheet ) {
130
+ Row row ;
131
+ if (this .index == -1 ) {
132
+ row = sheet .createRow (sheet .getLastRowNum () + 1 );
133
+ } else {
134
+ row = sheet .getRow (this .index );
135
+ if (row == null ) {
136
+ row = sheet .createRow (this .index );
137
+ }
138
+ }
139
+ return row ;
140
+ }
141
+
106
142
/**
107
143
* Row with additional properties.
108
144
*/
@@ -145,11 +181,6 @@ public ERow with(final ECell... cells) {
145
181
return this .origin .with (cells );
146
182
}
147
183
148
- @ Override
149
- public ERow with (final ECell cell ) {
150
- return this .origin .with (cell );
151
- }
152
-
153
184
@ Override
154
185
public ERow with (final ECells cells ) {
155
186
return this .origin .with (cells );
0 commit comments