pro.verron.officestamper.preset.StampTable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of engine Show documentation
Show all versions of engine Show documentation
Office-stamper is a Java template engine for docx documents, forked from org.wickedsource.docx-stamper
package pro.verron.officestamper.preset;
import org.springframework.lang.NonNull;
import java.util.*;
import static java.util.Collections.singletonList;
/**
* Represents a table with several columns, a header line, and several lines of content
*
* @author Joseph Verron
* @version ${version}
* @since 1.6.2
*/
public class StampTable
extends AbstractSequentialList> {
private final List headers;
private final List> records;
@Override public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
StampTable lists = (StampTable) o;
return Objects.equals(headers, lists.headers) && Objects.equals(records, lists.records);
}
@Override public int hashCode() {
return Objects.hash(super.hashCode(), headers, records);
}
/**
* Instantiate an empty table
*/
public StampTable() {
this.headers = new ArrayList<>();
this.records = new ArrayList<>();
}
/**
* Instantiate a table with headers and several lines
*
* @param headers the header lines
* @param records the lines that the table should contain
*/
public StampTable(
@NonNull List headers,
@NonNull List> records
) {
this.headers = headers;
this.records = records;
}
@Override
public int size() {
return records.size();
}
@Override
@NonNull
public ListIterator> listIterator(int index) {
return records.listIterator(index);
}
/**
* empty.
*
* @return a {@link StampTable} object
*/
public static StampTable empty() {
return new StampTable(
singletonList("placeholder"),
singletonList(singletonList("placeholder"))
);
}
/**
* headers.
*
* @return a {@link List} object
*/
public List headers() {
return headers;
}
}