Made public instance fields for ITestDataProvider singletons.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@893900 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a74769efcd
commit
e493c8dd01
@ -17,47 +17,43 @@
|
||||
|
||||
package org.apache.poi.xssf;
|
||||
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
import org.apache.poi.ss.SpreadsheetVersion;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||
import org.apache.poi.POIDataSamples;
|
||||
|
||||
/**
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public final class XSSFITestDataProvider implements ITestDataProvider {
|
||||
|
||||
public XSSFWorkbook openSampleWorkbook(String sampleFileName) {
|
||||
return XSSFTestDataSamples.openSampleWorkbook(sampleFileName);
|
||||
}
|
||||
|
||||
public XSSFWorkbook writeOutAndReadBack(Workbook original) {
|
||||
if(!(original instanceof XSSFWorkbook)) {
|
||||
throw new IllegalArgumentException("Expected an instance of XSSFWorkbook");
|
||||
}
|
||||
|
||||
return XSSFTestDataSamples.writeOutAndReadBack((XSSFWorkbook)original);
|
||||
}
|
||||
|
||||
public XSSFWorkbook createWorkbook(){
|
||||
return new XSSFWorkbook();
|
||||
}
|
||||
|
||||
public byte[] getTestDataFileContent(String fileName) {
|
||||
return POIDataSamples.getSpreadSheetInstance().readFile(fileName);
|
||||
}
|
||||
|
||||
public SpreadsheetVersion getSpreadsheetVersion(){
|
||||
return SpreadsheetVersion.EXCEL2007;
|
||||
}
|
||||
public static final XSSFITestDataProvider instance = new XSSFITestDataProvider();
|
||||
|
||||
private XSSFITestDataProvider() {
|
||||
// enforce singleton
|
||||
}
|
||||
private static XSSFITestDataProvider inst = new XSSFITestDataProvider();
|
||||
public static XSSFITestDataProvider getInstance(){
|
||||
return inst;
|
||||
return instance;
|
||||
}
|
||||
public XSSFWorkbook openSampleWorkbook(String sampleFileName) {
|
||||
return XSSFTestDataSamples.openSampleWorkbook(sampleFileName);
|
||||
}
|
||||
public XSSFWorkbook writeOutAndReadBack(Workbook original) {
|
||||
if(!(original instanceof XSSFWorkbook)) {
|
||||
throw new IllegalArgumentException("Expected an instance of XSSFWorkbook");
|
||||
}
|
||||
return XSSFTestDataSamples.writeOutAndReadBack((XSSFWorkbook)original);
|
||||
}
|
||||
public XSSFWorkbook createWorkbook(){
|
||||
return new XSSFWorkbook();
|
||||
}
|
||||
public byte[] getTestDataFileContent(String fileName) {
|
||||
return POIDataSamples.getSpreadSheetInstance().readFile(fileName);
|
||||
}
|
||||
public SpreadsheetVersion getSpreadsheetVersion(){
|
||||
return SpreadsheetVersion.EXCEL2007;
|
||||
}
|
||||
public String getStandardFileNameExtension() {
|
||||
return "xlsx";
|
||||
}
|
||||
}
|
||||
|
@ -17,44 +17,43 @@
|
||||
|
||||
package org.apache.poi.hssf;
|
||||
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.ITestDataProvider;
|
||||
import org.apache.poi.ss.SpreadsheetVersion;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.POIDataSamples;
|
||||
|
||||
/**
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public final class HSSFITestDataProvider implements ITestDataProvider {
|
||||
public static final HSSFITestDataProvider instance = new HSSFITestDataProvider();
|
||||
|
||||
private HSSFITestDataProvider(){
|
||||
// enforce singleton
|
||||
}
|
||||
public static HSSFITestDataProvider getInstance(){
|
||||
return instance;
|
||||
}
|
||||
public HSSFWorkbook openSampleWorkbook(String sampleFileName) {
|
||||
return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
|
||||
}
|
||||
|
||||
public HSSFWorkbook writeOutAndReadBack(Workbook original) {
|
||||
return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
|
||||
}
|
||||
public HSSFWorkbook writeOutAndReadBack(Workbook original) {
|
||||
if(!(original instanceof HSSFWorkbook)) {
|
||||
throw new IllegalArgumentException("Expected an instance of HSSFWorkbook");
|
||||
}
|
||||
|
||||
return HSSFTestDataSamples.writeOutAndReadBack((HSSFWorkbook)original);
|
||||
}
|
||||
|
||||
}
|
||||
public HSSFWorkbook createWorkbook(){
|
||||
return new HSSFWorkbook();
|
||||
}
|
||||
|
||||
public byte[] getTestDataFileContent(String fileName) {
|
||||
return POIDataSamples.getSpreadSheetInstance().readFile(fileName);
|
||||
}
|
||||
|
||||
public SpreadsheetVersion getSpreadsheetVersion(){
|
||||
return SpreadsheetVersion.EXCEL97;
|
||||
}
|
||||
|
||||
private HSSFITestDataProvider(){}
|
||||
private static HSSFITestDataProvider inst = new HSSFITestDataProvider();
|
||||
public static HSSFITestDataProvider getInstance(){
|
||||
return inst;
|
||||
public String getStandardFileNameExtension() {
|
||||
return "xls";
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import org.apache.poi.ss.usermodel.Workbook;
|
||||
*/
|
||||
public interface ITestDataProvider {
|
||||
/**
|
||||
* Override to provide HSSF / XSSF specific way for re-serialising a workbook
|
||||
* Provides HSSF / XSSF specific way for re-serialising a workbook
|
||||
*
|
||||
* @param wb the workbook to re-serialize
|
||||
* @return the re-serialized workbook
|
||||
@ -32,7 +32,7 @@ public interface ITestDataProvider {
|
||||
Workbook writeOutAndReadBack(Workbook wb);
|
||||
|
||||
/**
|
||||
* Override to provide way of loading HSSF / XSSF sample workbooks
|
||||
* Provides way of loading HSSF / XSSF sample workbooks
|
||||
*
|
||||
* @param sampleFileName the file name to load
|
||||
* @return an instance of Workbook loaded from the supplied file name
|
||||
@ -40,7 +40,7 @@ public interface ITestDataProvider {
|
||||
Workbook openSampleWorkbook(String sampleFileName);
|
||||
|
||||
/**
|
||||
* Override to provide way of creating HSSF / XSSF workbooks
|
||||
* Provides way of creating HSSF / XSSF workbooks
|
||||
* @return an instance of Workbook
|
||||
*/
|
||||
Workbook createWorkbook();
|
||||
@ -53,4 +53,9 @@ public interface ITestDataProvider {
|
||||
byte[] getTestDataFileContent(String fileName);
|
||||
|
||||
SpreadsheetVersion getSpreadsheetVersion();
|
||||
|
||||
/**
|
||||
* @return "xls" or "xlsx"
|
||||
*/
|
||||
String getStandardFileNameExtension();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user