1 /* 2 * Copyright 2013 Olivier Godineau 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy of 6 * the License at http://www.apache.org/licenses/LICENSE-2.0 7 * 8 * Unless required by applicable law or agreed to in writing, software 9 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 10 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 11 * License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 package olg.csv.base; 15 16 /** 17 * Settings Class for spreadsheet document reader and writer class. 18 * 19 * @param <T> 20 * the concret settings type. 21 * 22 * 23 */ 24 public abstract class AbstractSheetSettings<T extends AbstractSheetSettings<T>> { 25 /** 26 * Default with headers value. 27 */ 28 public static final boolean DEFAULT_WITHHEADERS = true; 29 /** 30 * Default sheet num on which read/write. 31 */ 32 public static final int DEFAULT_SHEETNUM = 0; 33 /** 34 * sheet num. 35 */ 36 protected int sheetNum = DEFAULT_SHEETNUM; 37 /** 38 * 39 */ 40 protected boolean withHeaders = DEFAULT_WITHHEADERS; 41 /** 42 * the row from which begin the reading/writing. first row is 1. 43 */ 44 protected Integer beginAtRow = 1; 45 /** 46 * The row to which ends the reading/writing. Could be <code>null</code>. 47 */ 48 protected Integer endAtRow = null; 49 /** 50 * the index column from which begin row reading/writing. 51 */ 52 protected String beginAtColumn = null; 53 /** 54 * The index column to which end the row reading/writing. 55 */ 56 protected String endAtColumn = null; 57 /** 58 * The sheet name on which read. 59 */ 60 protected String sheetName = null; 61 62 /** 63 * Purpose default settings. 64 * <ul> 65 * <li>sheetNum = 0 : take the first sheet of the document</li> 66 * <li>withHeaders = true : skip first read line</li> 67 * <li>beginAtRow = 1 : begin reading or writing at the first line</li> 68 * <li>endAtRow = null : the reading ends at the end of the document</li> 69 * <li>beginAtColumn = null : the reading or writing begins at the first 70 * column on each line</li> 71 * <li>endAtColumn = null: the reading</li> 72 * </ul> 73 */ 74 public AbstractSheetSettings() { 75 super(); 76 } 77 78 /** 79 * 80 * @param sheetNum 81 * if sheetName parameter is <code>null</code>,try to load sheet 82 * with this index in the sheet list. 83 * @param withHeaders 84 * Only for Reading. If true skip the first read line, considered 85 * as headers line. 86 * @param beginAtRow 87 * specify which line of the file, starts the reading or writing, 88 * If <code>null</code>, start at the first line 89 * @param endAtRow 90 * specify which line of the file ends the reading. If 91 * <code>null</code>, end at the last line. Only on reading 92 * process 93 * @param beginAtColumn 94 * specify which column of each line starts the reading or 95 * writing. Sheet cell number format('A', 'B', 'C',..., 'AA', 96 * ...) or integer Format.May be <code>null</code>, in this case 97 * start at the first column of each line. 98 * @param endAtColumn 99 * Specify which column of each line end reading. Sheet cell 100 * number format('A', 'B', 'C',..., 'AA', ...) or integer Format. 101 * May be <code>null</code> 102 * @param sheetName 103 * if specified, try to load sheet with this name (sheetNum 104 * parameter is ignored then redefined) 105 */ 106 public AbstractSheetSettings(int sheetNum, boolean withHeaders, Integer beginAtRow, Integer endAtRow, 107 String beginAtColumn, String endAtColumn, String sheetName) { 108 super(); 109 this.sheetNum = sheetNum; 110 this.withHeaders = withHeaders; 111 this.beginAtRow = beginAtRow; 112 this.endAtRow = endAtRow; 113 this.beginAtColumn = beginAtColumn; 114 this.endAtColumn = endAtColumn; 115 this.sheetName = sheetName; 116 } 117 118 /** 119 * 120 * @return sheet index in the sheets list of the document 121 */ 122 public int getSheetNum() { 123 return sheetNum; 124 } 125 /** 126 * Sets the sheet index in the sheets list of the document. 127 * 128 * @param sheetNum 129 * the sheet index in the document. 130 * @return the current instance 131 */ 132 @SuppressWarnings("unchecked") 133 public T setSheetNum(int sheetNum) { 134 this.sheetNum = sheetNum; 135 return (T) this; 136 } 137 138 /** 139 * indicate if the first row must be skipped on reading or if an headers 140 * line must be written on writing. 141 * 142 * @return with headers or not. 143 */ 144 public boolean isWithHeaders() { 145 return withHeaders; 146 } 147 148 /** 149 * Allows to skip headers line on reading or allows to write headers on 150 * writing. 151 * 152 * @param withHeaders 153 * indicate if the document has an header. 154 * @return the current instance 155 */ 156 @SuppressWarnings("unchecked") 157 public T setWithHeaders(boolean withHeaders) { 158 this.withHeaders = withHeaders; 159 return (T) this; 160 } 161 162 /** 163 * 164 * @return the row number where to begin reading or writing. 165 */ 166 public Integer getBeginAtRow() { 167 return beginAtRow; 168 } 169 /** 170 * Sets the row number where to begin reading or writing. 171 * 172 * @param beginAtRow 173 * May be <code>null</code>(the reading or writing begins at the 174 * first line of the document) 175 * @return the current instance 176 */ 177 @SuppressWarnings("unchecked") 178 public T setBeginAtRow(Integer beginAtRow) { 179 this.beginAtRow = beginAtRow; 180 return (T) this; 181 } 182 183 /** 184 * Returns the last row to read if defined. Only for reading. 185 * 186 * @return the last row to read. 187 */ 188 public Integer getEndAtRow() { 189 return endAtRow; 190 } 191 192 /** 193 * Set at which line end reading.Only for reading. 194 * 195 * @param endAtRow 196 * May be <code>null</code>(the reading ends at the last line of 197 * the document) 198 * @return the current instance 199 */ 200 @SuppressWarnings("unchecked") 201 public T setEndAtRow(Integer endAtRow) { 202 this.endAtRow = endAtRow; 203 return (T) this; 204 } 205 206 /** 207 * 208 * @return the num of the first column to read/write. 209 */ 210 public String getBeginAtColumn() { 211 return beginAtColumn; 212 } 213 214 /** 215 * Set from which column begin to read/write each line. 216 * 217 * @param beginAtColumn 218 * May be <code>null</code>(each read or written line start at 219 * the first column) 220 * @return the current instance 221 */ 222 @SuppressWarnings("unchecked") 223 public T setBeginAtColumn(String beginAtColumn) { 224 this.beginAtColumn = beginAtColumn; 225 return (T) this; 226 } 227 228 /** 229 * Returns the num of the last column to read if defined. Only for reading. 230 * 231 * @return the num of the last column to read. 232 */ 233 public String getEndAtColumn() { 234 return endAtColumn; 235 } 236 237 /** 238 * Set to which column end reading each line.Only for reading. 239 * 240 * @param endAtColumn 241 * May be <code>null</code> 242 * @return the current instance 243 */ 244 @SuppressWarnings("unchecked") 245 public T setEndAtColumn(String endAtColumn) { 246 this.endAtColumn = endAtColumn; 247 return (T) this; 248 } 249 250 /** 251 * Returns the sheet name. 252 * 253 * @return the sheet name. 254 */ 255 public String getSheetName() { 256 return sheetName; 257 } 258 259 /** 260 * The desire sheet name. 261 * 262 * @param sheetName 263 * the name of the sheet in the spreadsheet document. 264 * @return the current instance 265 */ 266 @SuppressWarnings("unchecked") 267 public T setSheetName(String sheetName) { 268 this.sheetName = sheetName; 269 return (T) this; 270 } 271 272 }