com.creditdatamw.zerocell.Reader Maven / Gradle / Ivy
package com.creditdatamw.zerocell;
import com.creditdatamw.zerocell.column.ColumnInfo;
import com.creditdatamw.zerocell.column.ColumnMapping;
import com.creditdatamw.zerocell.column.RowNumberInfo;
import com.creditdatamw.zerocell.handler.EntityHandler;
import java.io.File;
import java.util.List;
import java.util.Objects;
/**
* Main API for ZeroCell
*/
public class Reader {
public static String[] columnsOf(Class clazz) {
return ColumnInfo.columnsOf(clazz);
}
public static ReaderBuilder of(Class clazz) {
return new ReaderBuilder<>(clazz);
}
public static final class ReaderBuilder {
private final Class clazz;
private File file;
private String sheetName;
private ColumnMapping columnMapping;
public ReaderBuilder(Class clazz) {
this.clazz = clazz;
}
public ReaderBuilder from(File file) {
Objects.requireNonNull(file);
this.file = file;
return this;
}
public ReaderBuilder using(RowNumberInfo rowNumberInfo, ColumnInfo... columns) {
this.columnMapping = new ColumnMapping(rowNumberInfo, columns);
return this;
}
public ReaderBuilder using(ColumnInfo... columns) {
this.columnMapping = new ColumnMapping(null, columns);
return this;
}
public ReaderBuilder sheet(String sheetName) {
Objects.requireNonNull(sheetName);
this.sheetName = sheetName;
return this;
}
public List list() {
EntityHandler entityHandler;
if (!Objects.isNull(sheetName) && !Objects.isNull(columnMapping)) {
entityHandler = new EntityHandler(clazz, sheetName, columnMapping);
} else if (Objects.isNull(sheetName) && !Objects.isNull(columnMapping)) {
entityHandler = new EntityHandler(clazz, columnMapping);
} else if (!Objects.isNull(sheetName) && Objects.isNull(columnMapping)) {
entityHandler = new EntityHandler(clazz, sheetName);
} else {
entityHandler = new EntityHandler(clazz);
}
entityHandler.process(file);
return entityHandler.readAsList();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy