-
-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Redesign Table and TableBuilder classes - Adds new AbstractTableColumn construtor that receives title, subtitle and format to make it easier to create columns. Accordingly add such a constructor to subclasses. - Enables changing format for time, length, ID and PE columns in CloudletsTableBuilder. This way, the dev can define his/her own default formats upfront. - Remove the public addColumn methods from Table interface and make then protected. Add newColumn methods that just create a column, instead of directly adding them to the table. - When new columns are created, they are added to a temporary list before being inserted into the actual table. Columns are added to the table just after calling build. This way, we can add columns any time and define the format for such columns without worring about the order of these method calls (as it's expected for a builder class). * Add setter and getter methods to define formats for CloudletsTableBuilder * Update CloudletsTableBuilder default precision for time display * Remove rounding function * Move createTableColumns() into build method so that columns are just created with the defined format when calling build(). This solves the issue that the variables are not initialized when createTableColumns() is executed. * Introduces TableBuilderAbstract.addColumn methods for simplicity * Introduce Table.colCount() for simplicity * Makes AbstractTableColumn.setTitle to use empty string when null is given. * Set AbstractTableColumn subtitle default as empty string * Sets AbstractTableColumn format default as empty string * Link the column with its table inset the AbstractTable.addColumn() * Access table attribute directly inside TableBuilderAbstract * Reinstantiates colsMappings in TableBuilderAbstract instead of clearing to reduce computational complexity and avoid concurrency issues. If column definitions are changed and the build method is called again, the list of colsMappings should be cleared before, to add columns again with new configurations. * Removed unused methods on TableBuilderAbstract Signed-off-by: Manoel Campos <manoelcampos@gmail.com> Co-authored-by: Manoel Campos <manoelcampos@gmail.com>
- Loading branch information
1 parent
8aecd9c
commit 9232e8e
Showing
16 changed files
with
300 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/org/cloudsimplus/builders/tables/ColumnMapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.cloudsimplus.builders.tables; | ||
|
||
import java.util.function.Function; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* A record that creates a mapping for adding a column into a table latter on. | ||
* That is used by {@link TableBuilderAbstract} objects. | ||
* | ||
* @param <T> the type of objects printed into the table | ||
* @param col the column to add | ||
* @param dataFunction a function that receives an object T and returns the data to be printed from that object | ||
* @param index the index of the column in the table | ||
* @author Manoel Campos da Silva Filho | ||
* @since CloudSim Plus 7.3.1 | ||
*/ | ||
record ColumnMapping<T>(TableColumn col, Function<T, Object> dataFunction, int index) { | ||
ColumnMapping(TableColumn col, Function<T, Object> dataFunction) { | ||
this(col, dataFunction, Integer.MAX_VALUE); | ||
} | ||
|
||
ColumnMapping { | ||
requireNonNull(col); | ||
requireNonNull(dataFunction); | ||
} | ||
|
||
public Object getColData(T object){ | ||
return dataFunction.apply(object); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.