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

Add new formatting methods to the TableBuilder and fix printing issues #405

Merged
merged 64 commits into from
Nov 24, 2022

Conversation

struffel
Copy link
Contributor

@struffel struffel commented Nov 19, 2022

Fix #404

This PR introduces new methods for controlling the formatting in tables built using the TableBuilderAbstract class, such as CloudletsTableBuilder. It also changes the default formatting behavior of CloudletsTableBuilder to deliver more precision by default and make potential rounding errors rarer and easier to spot.

In CloudletsTableBuilder.java it removes a rounding method that is no longer needed and refactors the code in the createTableColumns() method.

In TableBuilderAbstract.java it introduces new methods that allow users to adjust the formatting of one or multiple columns using various selectors with methods that can be chained, following the example of setTitle().

I have already prepared a new example scenario for this feature which will go in this separate PR to the cloudsimplus-example repo: cloudsimplus/cloudsimplus-examples#8

The 4 lists keep track of which column needs which formatting. The setter and getter methods will need to get expanded to reiterate through the list to update the actual formatting for every column.
This solves the issue that the variables are not initialized when createTableColumns() is executed but it does not account for additional columns being added using addColumn(). More work is required here.
No longer uses separate lists to keep track of the formatting choices and insteads allows formatting to be changed by addressing individual column indices.
(the table title makes it clear which column we are adding)

Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
Fix small docs issues.

Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
since they are actually adding the column to the table

Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
to avoid confunsion with the addColumn methods
and better semantics

Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
- 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).

Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
@manoelcampos
Copy link
Collaborator

manoelcampos commented Nov 21, 2022

Hey @StruffelProductions

Check my last commit 0998eab.
I've made a major redesign to enable devs to change the format as they wish.
It required some work but I think it's better this way.
And now the order of method calls doesn't matter, since the table is just created when calling the build method, as a builder is supposed to do.

Could you please try it?

@manoelcampos
Copy link
Collaborator

manoelcampos commented Nov 21, 2022

Are you really using these setFormatBy... methods? I don't think they are required with this new design and may just bloat the API.

Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
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.

Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
of clearing to reduce computational complexity
and avoid concurrency issues.

Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
@manoelcampos manoelcampos changed the title Add new methods for formatting to the TableBuilder / Fixes Fix #404 :: Add new methods for formatting to the TableBuilder / Fixes Nov 21, 2022
@manoelcampos manoelcampos changed the title Fix #404 :: Add new methods for formatting to the TableBuilder / Fixes Add new formatting methods to the TableBuilder and fix printing issues Nov 21, 2022
@struffel
Copy link
Contributor Author

Are you really using these setFormatBy... methods? I don't think they are required with this new design and may just bloat the API.

Hi, these setFormatBy... methods are not strictly necessary, we can remove them. The main thing that motivated me for this PR was the ability to render tables with more precise time values. The setFormatBy... methods were just a "neat" idea but the current implementation also looks good to me.

@manoelcampos
Copy link
Collaborator

Great. So I'm removing them and merging the changes. Could you please update the example PR?

Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
@struffel
Copy link
Contributor Author

Great. So I'm removing them and merging the changes. Could you please update the example PR?

Yes, I will do that later.

Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
@manoelcampos manoelcampos merged commit 9232e8e into cloudsimplus:master Nov 24, 2022
@manoelcampos
Copy link
Collaborator

Thanks for your contributions. I've just merged them.

@struffel
Copy link
Contributor Author

I'm glad to provide something to the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix accuracy issues when printing result tables and redesign TableBuilders for more flexibility
2 participants