Skip to content

Commit

Permalink
Refactor TableBuilderAbstract
Browse files Browse the repository at this point in the history
Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
  • Loading branch information
manoelcampos committed Nov 16, 2022
1 parent ed64c15 commit f6e1dc1
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public abstract class TableBuilderAbstract<T> {
* That data is the value for the associated column
* of the table being generated.
*/
private final Map<TableColumn, Function<T, Object>> columnsDataFunctions;
private final Map<TableColumn, Function<T, Object>> colsDataFunctions;

private Table table;

Expand All @@ -72,7 +72,7 @@ public TableBuilderAbstract(final List<? extends T> list){
public TableBuilderAbstract(final List<? extends T> list, final Table table){
setTable(table);
setObjectList(list);
columnsDataFunctions = new HashMap<>();
colsDataFunctions = new HashMap<>();
createTableColumns();
}

Expand Down Expand Up @@ -142,7 +142,7 @@ public TableBuilderAbstract<T> addColumn(final int index, final TableColumn col,

col.setTable(getTable());
getTable().addColumn(index, col);
columnsDataFunctions.put(col, dataFunction);
colsDataFunctions.put(col, dataFunction);
return this;
}

Expand Down Expand Up @@ -196,17 +196,17 @@ public void build(){
protected void addDataToRow(final T object, final List<Object> row) {
getTable()
.getColumns()
.forEach(col -> row.add(columnsDataFunctions.get(col).apply(object)));
.forEach(col -> row.add(colsDataFunctions.get(col).apply(object)));
}

/**
* Adds a data function for a given column.
* @param col column to add a data function
* @param function a function that receives an object T and returns the data to be printed from that object.
* @param dataFunction a function that receives an object T and returns the data to be printed from that object.
* @return
*/
protected TableBuilderAbstract<T> addColDataFunction(final TableColumn col, final Function<T, Object> function){
columnsDataFunctions.put(requireNonNull(col), requireNonNull(function));
protected TableBuilderAbstract<T> addColDataFunction(final TableColumn col, final Function<T, Object> dataFunction){
colsDataFunctions.put(requireNonNull(col), requireNonNull(dataFunction));
return this;
}
}

0 comments on commit f6e1dc1

Please sign in to comment.