
com.github.nomou.spreadsheet.AbstractSpreadsheetParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spreadsheet-api Show documentation
Show all versions of spreadsheet-api Show documentation
a simple streaming spreadsheet api
The newest version!
package com.github.nomou.spreadsheet;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
/**
* Abstract spreadsheet parser.
*
* @author vacoor
* @since 1.0
*/
public abstract class AbstractSpreadsheetParser implements SpreadsheetParser {
/**
* The current parsing event type.
*/
protected int eventType;
/**
* The current worksheet index.
*/
protected int worksheetIndex = -1;
/**
* The current worksheet name.
*/
protected String worksheetName;
/**
* {@inheritDoc}
*/
@Override
public int getEventType() {
return this.eventType;
}
/**
* {@inheritDoc}
*/
@Override
public int getWorksheetIndex() {
final int st = this.eventType;
if (START_WORKBOOK == st || END_WORKBOOK == st) {
throw new IllegalStateException("getWorksheetIndex() called in illegal state");
}
return this.worksheetIndex;
}
/**
* {@inheritDoc}
*/
@Override
public String getWorksheetName() {
final int st = this.eventType;
if (START_WORKBOOK == st || END_WORKBOOK == st) {
throw new IllegalStateException("getWorksheetName() called in illegal state");
}
return this.worksheetName;
}
/**
* {@inheritDoc}
*/
@Override
public boolean hasNext() {
// returns -1 when it detects a broken stream
return EOF != this.eventType && END_WORKBOOK != this.eventType;
}
/**
* {@inheritDoc}
*/
@Override
public int next() throws SpreadsheetException {
final int t = this.eventType;
if (!hasNext()) {
if (EOF != t) {
throw new NoSuchElementException("END_WORKBOOK reached: no more elements on the stream.");
} else {
throw new IllegalStateException("Error processing input source. The input stream is not complete.");
}
}
return this.eventType = doNext();
}
/**
* {@inheritDoc}
*/
@Override
public Object[] nextRecord(final boolean ignoreEmptyRecord) throws SpreadsheetException {
final SpreadsheetParser parser = this;
final List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy