Skip to content

Commit

Permalink
#1: Fixed all qulice issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dgroup committed Dec 14, 2019
1 parent 7e7e6f8 commit 34a0294
Show file tree
Hide file tree
Showing 16 changed files with 395 additions and 87 deletions.
43 changes: 43 additions & 0 deletions .gitstrap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
gitstrap:
version: v1
github:
repo:
# github repository name (optional, current directory name if empty)
name: xlsx-matchers
# github repository description
description: "Elegant object-oriented hamcrest matchers for Apache POI"
# true if private (optional, default false)
private: false
# github webhooks
hooks:
# webhook url
- url: "http://p.rehttp.net/http://www.0pdd.com/hook/github"
# webhook type: form or json
type: form
# events to send (see github docs)
events:
- push
# false to create webhook in inactive state (optional, default true)
active: true
# github logins to add as collaborators
collaborators:
- "rultor"
- "0pdd"
# (optional) templates to apply, see Templates README section
templates:
# file name in repository
- name: "readme.md"
# template url
url: "https://raw.githubusercontent.com/g4s8/gitstrap/master/templates/README.md"
- name: "license"
url: "https://raw.githubusercontent.com/dgroup/gitstrap-templates/master/license"
# (optional) these params can be accessed from template, just a key-value pairs
params:
rultor: true
travis: true
readmeContrib: |
Fork repository, clone it, make changes,
push to new branch and submit a pull request.
pdd: true
license: MIT
package: io.github.dgroup
12 changes: 0 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,6 @@
<scope>provided</scope>
</dependency>
<!-- @todo #/DEV Upgrade the hamcrest-all library to the latest release of hamcrest-java -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>${hamcrest-all.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.llorllale</groupId>
<artifactId>cactoos-matchers</artifactId>
Expand All @@ -134,12 +128,6 @@
<version>${poi.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId>
<version>${ooxml-schemas.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/github/dgroup/poi/cell/Cell.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
* @param <T> The type of excel cell.
* @see CellOf
*
* @since 3.4.0
* @since 0.1.0
*/
public interface Cell<T> extends Scalar<T> {

/**
* The cell column id (starts from 0).
* @return The column id.
*/
int id();
int index();

/**
* The cell value.
Expand Down
76 changes: 53 additions & 23 deletions src/main/java/io/github/dgroup/poi/cell/CellOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,36 @@
/**
* Excel cell.
*
* @since 3.4.0
* @param <T> The type of cell value.
* @since 0.1.0
*/
public class CellOf<T> implements MutableCell<T> {

/**
* The Apache POI index of excel cell.
* By default the cell index starts from 0.
*/
private final Unchecked<Integer> cid;

/**
* The value of Apache POI cell.
*/
private final Unchecked<T> val;

/**
* The function to detect the cell's format from particular {@link XSSFSheet}.
*/
private final UncheckedFunc<XSSFSheet, XSSFCellStyle> style;

/**
* The function to evaluate the cell description.
*/
private final Unchecked<String> tostr;

/**
* Ctor.
* @param cid The number of excel cell.
* @param val The excel cell value
* @param val The excel cell value.
*/
public CellOf(final int cid, final T val) {
this(cid, () -> val);
Expand All @@ -62,7 +80,7 @@ public CellOf(final int cid, final T val) {
/**
* Ctor.
* @param cid The number of excel cell.
* @param val The excel cell value
* @param val The excel cell value.
*/
public CellOf(final int cid, final Scalar<T> val) {
this(() -> cid, val);
Expand All @@ -71,7 +89,7 @@ public CellOf(final int cid, final Scalar<T> val) {
/**
* Ctor.
* @param cid The name of excel cell.
* @param val The excel cell value
* @param val The excel cell value.
*/
public CellOf(final String cid, final T val) {
this(cid, () -> val);
Expand All @@ -80,7 +98,7 @@ public CellOf(final String cid, final T val) {
/**
* Ctor.
* @param cid The name of excel cell.
* @param val The excel cell value
* @param val The excel cell value.
*/
public CellOf(final String cid, final Scalar<T> val) {
this(new Sticky<>(new IndexOf(cid)), val);
Expand All @@ -89,7 +107,7 @@ public CellOf(final String cid, final Scalar<T> val) {
/**
* Ctor.
* @param cid The number of excel cell.
* @param val The excel cell value
* @param val The excel cell value.
*/
public CellOf(final Scalar<Integer> cid, final Scalar<T> val) {
this(cid, val, sheet -> sheet.getWorkbook().createCellStyle());
Expand All @@ -102,16 +120,20 @@ public CellOf(final Scalar<Integer> cid, final Scalar<T> val) {
* @param style The excel cell formatting style.
*/
protected CellOf(
final Scalar<Integer> cid, final Scalar<T> val,
final Func<XSSFSheet, XSSFCellStyle> style
final Scalar<Integer> cid, final Scalar<T> val, final Func<XSSFSheet, XSSFCellStyle> style
) {
this.cid = new Unchecked<>(new Sticky<>(cid));
this.val = new Unchecked<>(new Sticky<>(val));
this.style = new UncheckedFunc<>(style);
this.tostr = new Unchecked<>(
new Sticky<>(
() -> String.format("Cell %s, %s.", this.cid, this.val.value())
)
);
}

@Override
public final int id() {
public final int index() {
return this.cid.value();
}

Expand All @@ -122,7 +144,7 @@ public final T value() {

@Override
public final String toString() {
return String.format("Cell %s, %s.", this.cid, this.val.value());
return this.tostr.value();
}

@Override
Expand All @@ -134,7 +156,7 @@ public final boolean equals(final Object obj) {
equal = false;
} else {
final Cell<?> that = (Cell<?>) obj;
equal = Objects.equals(this.id(), that.id())
equal = Objects.equals(this.index(), that.index())
&& Objects.equals(this.value(), that.value());
}
return equal;
Expand All @@ -148,35 +170,43 @@ public final int hashCode() {
@Override
public final void change(final XSSFRow row) {
if (row != null) {
XSSFCell cell = row.getCell(this.id());
XSSFCell cell = row.getCell(this.index());
if (cell == null) {
cell = row.createCell(this.id());
cell = row.createCell(this.index());
cell.setCellStyle(this.style.apply(row.getSheet()));
}
final T value = this.value();
if (value instanceof Double) {
cell.setCellValue(Math.round((double) value));
cell.setCellValue(
Math.round(
(Double) value
)
);
}
if (value instanceof Integer) {
cell.setCellValue((int) value);
cell.setCellValue((Integer) value);
}
if (value instanceof Long) {
cell.setCellValue((long) value);
cell.setCellValue((Long) value);
}
if (value instanceof String) {
cell.setCellValue((String) value);
}
if (value instanceof LocalDateTime) {
final Date date = Date.from(((LocalDateTime) value)
.atZone(ZoneId.systemDefault())
.toInstant());
final Date date = Date.from(
((LocalDateTime) value)
.atZone(ZoneId.systemDefault())
.toInstant()
);
cell.setCellValue(date);
}
if (value instanceof LocalDate) {
final Date date = Date.from(((LocalDate) value)
.atStartOfDay()
.atZone(ZoneId.systemDefault())
.toInstant());
final Date date = Date.from(
((LocalDate) value)
.atStartOfDay()
.atZone(ZoneId.systemDefault())
.toInstant()
);
cell.setCellValue(date);
}
}
Expand Down
41 changes: 37 additions & 4 deletions src/main/java/io/github/dgroup/poi/cell/DateOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@
import java.time.ZoneId;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFCreationHelper;
import org.cactoos.Scalar;
import org.cactoos.scalar.Sticky;

/**
* The excel cell with date.
*
* @since 3.14.9
* @since 0.1.0
*/
public final class DateOf extends CellOf<LocalDate> {

/**
* Ctor.
* @param cell The Apache POI cell.
*/
public DateOf(final XSSFCell cell) {
this(
cell::getColumnIndex,
Expand All @@ -49,27 +52,57 @@ public DateOf(final XSSFCell cell) {
);
}

/**
* Ctor.
* @param cid The number of excel cell.
* @param val The excel cell value.
*/
public DateOf(final int cid, final LocalDate val) {
this(() -> cid, () -> val);
}

/**
* Ctor.
* @param cid The number of excel cell.
* @param val The excel cell value.
*/
public DateOf(final String cid, final LocalDate val) {
this(cid, () -> val);
}

/**
* Ctor.
* @param cid The number of excel cell.
* @param val The excel cell value.
*/
public DateOf(final String cid, final Scalar<LocalDate> val) {
this(new Sticky<>(new IndexOf(cid)), val);
}

/**
* Ctor.
* @param cid The number of excel cell.
* @param val The excel cell value.
*/
public DateOf(final Scalar<Integer> cid, final Scalar<LocalDate> val) {
this(cid, val, "yyyy-mm-dd");
}

/**
* Ctor.
* @param cid The number of excel cell.
* @param val The excel cell value.
* @param pattern The format of the date for target {@link XSSFCell}.
*/
public DateOf(final Scalar<Integer> cid, final Scalar<LocalDate> val, final String pattern) {
super(cid, val, sheet -> {
final XSSFCreationHelper creationHelper = sheet.getWorkbook().getCreationHelper();
final XSSFCellStyle date = sheet.getWorkbook().createCellStyle();
date.setDataFormat(creationHelper.createDataFormat().getFormat(pattern));
date.setDataFormat(
sheet.getWorkbook()
.getCreationHelper()
.createDataFormat()
.getFormat(pattern)
);
return date;
});
}
Expand Down
Loading

0 comments on commit 34a0294

Please sign in to comment.