Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

# Refactoring & Improvement #121

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions src/main/java/com/github/pjfanning/xlsx/XmlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.io.InputStream;
import java.util.*;

public class XmlUtils {
public final class XmlUtils {

private static final NamespaceContext transitionalFormatNamespaceContext =
new NamespaceContextImpl("ss", "http://schemas.openxmlformats.org/spreadsheetml/2006/main");
Expand Down Expand Up @@ -48,7 +48,7 @@ public static boolean evaluateBoolean(String bool) {
return bool.equals(TRUE_AS_STRING) || bool.equalsIgnoreCase("true");
}

private static class NamespaceContextImpl implements NamespaceContext {
private static final class NamespaceContextImpl implements NamespaceContext {
private final Map<String, String> urisByPrefix = new HashMap<>();

private final Map<String, Set<String>> prefixesByURI = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;

class DateTimeUtil {
final class DateTimeUtil {

private DateTimeUtil() {}

Expand Down
28 changes: 14 additions & 14 deletions src/main/java/com/github/pjfanning/xlsx/impl/LazySupplier.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.github.pjfanning.xlsx.impl;

final class LazySupplier<T> implements Supplier {
private T content;
private final java.util.function.Supplier<T> functionalSupplier;
final class LazySupplier<O> implements Supplier {
private O content;
private final java.util.function.Supplier<O> functionalSupplier;

LazySupplier(java.util.function.Supplier<T> functionalSupplier) {
this.functionalSupplier = functionalSupplier;
}
LazySupplier(java.util.function.Supplier<O> functionalSupplier) {
this.functionalSupplier = functionalSupplier;
}

@Override
public Object getContent() {
if (content == null) {
content = functionalSupplier.get();
}
return content;
}
}
@Override
public Object getContent() {
if (content == null) {
content = functionalSupplier.get();
}
return content;
}
}
178 changes: 11 additions & 167 deletions src/main/java/com/github/pjfanning/xlsx/impl/StreamingCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@

import com.github.pjfanning.xlsx.XmlUtils;
import com.github.pjfanning.xlsx.exceptions.NotSupportedException;
import org.apache.poi.ss.formula.FormulaParseException;
import org.apache.poi.ss.usermodel.*;
import com.github.pjfanning.xlsx.impl.adapter.CellAdapter;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.ss.usermodel.FormulaError;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Date;

public class StreamingCell implements Cell {
public class StreamingCell implements CellAdapter {

private static final Supplier NULL_SUPPLIER = () -> null;

Expand Down Expand Up @@ -395,167 +399,7 @@ public Comment getCellComment() {
public Hyperlink getHyperlink() {
return (sheet == null) ? null : sheet.getHyperlink(getAddress());
}

/* Not supported */

/**
* Update operations are not supported
*/
@Override
public void setCellType(CellType cellType) {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void setBlank() { throw new NotSupportedException("update operations are not supported"); }

/**
* Update operations are not supported
*/
@Override
public void setCellValue(double value) {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void setCellValue(Date value) {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void setCellValue(Calendar value) {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void setCellValue(LocalDate value) {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void setCellValue(LocalDateTime value) {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void setCellValue(RichTextString value) {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void setCellValue(String value) {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void setCellFormula(String formula) throws FormulaParseException {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void removeFormula() throws IllegalStateException {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void setCellValue(boolean value) {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void setCellErrorValue(byte value) {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void setAsActiveCell() {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void setCellComment(Comment comment) {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void removeCellComment() {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void setHyperlink(Hyperlink link) {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void removeHyperlink() {
throw new NotSupportedException("update operations are not supported");
}

/**
* Not supported
*/
@Override
public CellRangeAddress getArrayFormulaRange() {
throw new NotSupportedException();
}

/**
* Not supported
*/
@Override
public boolean isPartOfArrayFormulaGroup() {
throw new NotSupportedException();
}


private static CellType getCellTypeFromShortHandType(final String cellType) {
switch (cellType) {
case "n":
Expand Down
104 changes: 14 additions & 90 deletions src/main/java/com/github/pjfanning/xlsx/impl/StreamingRow.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
package com.github.pjfanning.xlsx.impl;

import com.github.pjfanning.xlsx.exceptions.NotSupportedException;
import org.apache.poi.ss.usermodel.*;

import java.util.*;

public class StreamingRow implements Row {
import com.github.pjfanning.xlsx.impl.adapter.RowAdapter;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CellType;
import java.util.Map;
import java.util.TreeMap;
import java.util.Iterator;
import java.util.Spliterator;
import java.util.Spliterators;

public class StreamingRow implements RowAdapter {
private final Sheet sheet;
private final int rowIndex;
private final boolean isHidden;
private float height = -1.0f;
private TreeMap<Integer, Cell> cellMap = new TreeMap<>();
private final TreeMap<Integer, Cell> cellMap;
private StreamingSheetReader streamingSheetReader;
private CellStyle rowStyle;

public StreamingRow(Sheet sheet, int rowIndex, boolean isHidden) {
this.sheet = sheet;
this.rowIndex = rowIndex;
this.isHidden = isHidden;
cellMap = new TreeMap<>();
}

void setStreamingSheetReader(StreamingSheetReader streamingSheetReader) {
Expand Down Expand Up @@ -168,87 +175,4 @@ public void setRowStyle(CellStyle style) {
this.rowStyle = style;
}


/* Not supported */

/**
* Not supported
*/
@Override
public Cell createCell(int column) {
throw new NotSupportedException();
}

/**
* Not supported
*/
@Override
public Cell createCell(int i, CellType cellType) {
throw new NotSupportedException();
}

/**
* Update operations are not supported
*/
@Override
public void removeCell(Cell cell) {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void setRowNum(int rowNum) {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void setHeight(short height) {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void setZeroHeight(boolean zHeight) {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void setHeightInPoints(float height) {
throw new NotSupportedException("update operations are not supported");
}

/**
* Not supported
*/
@Override
public int getOutlineLevel() {
throw new NotSupportedException();
}

/**
* Update operations are not supported
*/
@Override
public void shiftCellsRight(int firstShiftColumnIndex, int lastShiftColumnIndex, int step) {
throw new NotSupportedException("update operations are not supported");
}

/**
* Update operations are not supported
*/
@Override
public void shiftCellsLeft(int firstShiftColumnIndex, int lastShiftColumnIndex, int step) {
throw new NotSupportedException("update operations are not supported");
}

}
Loading