-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced the Table and Row classes to simplify the print-out of tab…
…les in CLI
- Loading branch information
Showing
8 changed files
with
293 additions
and
55 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
36 changes: 36 additions & 0 deletions
36
io-mokamint-tools/src/main/java/io/mokamint/tools/AbstractTable.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,36 @@ | ||
/* | ||
Copyright 2024 Fausto Spoto | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package io.mokamint.tools; | ||
|
||
import io.mokamint.tools.internal.TableImpl; | ||
|
||
/** | ||
* Partial implementation of a table of rows. | ||
*/ | ||
public abstract class AbstractTable extends TableImpl { | ||
|
||
/** | ||
* Creates an empty table, without rows, with just its header. | ||
* | ||
* @param header the first row of this table, that gets added to it | ||
* @param columns the number of elements in the rows of this table | ||
* @param json true if and only if the print-out of the table must occur in JSON | ||
*/ | ||
protected AbstractTable(Row header, int columns, boolean json) { | ||
super(header, columns, json); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
io-mokamint-tools/src/main/java/io/mokamint/tools/Row.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,42 @@ | ||
/* | ||
Copyright 2024 Fausto Spoto | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package io.mokamint.tools; | ||
|
||
/** | ||
* A row in a table, that can be printed by a tool command. | ||
*/ | ||
public interface Row { | ||
|
||
/** | ||
* Yields the given column element of this row. | ||
* | ||
* @param index the index of the column, from 0 upwards | ||
* @return the element | ||
*/ | ||
String getColumn(int index); | ||
|
||
/** | ||
* Yields a string representation of this row, as it must | ||
* be reported to the user. The position is relative to the head of the table: | ||
* 0 is the first row (typically, the titles), 1 is the second row and so on. | ||
* | ||
* @param pos the position, relative to the head of the table | ||
* @param table the table this row belongs to | ||
* @return the string representation | ||
*/ | ||
String toString(int pos, Table table); | ||
} |
55 changes: 55 additions & 0 deletions
55
io-mokamint-tools/src/main/java/io/mokamint/tools/Table.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,55 @@ | ||
/* | ||
Copyright 2024 Fausto Spoto | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package io.mokamint.tools; | ||
|
||
/** | ||
* A table of rows. | ||
*/ | ||
public interface Table { | ||
|
||
/** | ||
* Adds the given row at the end of this table. | ||
* | ||
* @param row the row to add; it is assumed to have | ||
* the same number of columns as this table | ||
*/ | ||
void add(Row row); | ||
|
||
/** | ||
* Yields the number of characters that are used at most for the given column | ||
* of this table. | ||
* | ||
* @param column the column index, starting at 0 | ||
* @return the number of characters | ||
*/ | ||
int getSlotsForColumn(int column); | ||
|
||
/** | ||
* Calls {@link Row#toString(int, Table)} on each row of this table | ||
* and concatenates the result with newlines as separators. If the table is empty | ||
* (that is, if it only contains its heading), then the empty string is returned. | ||
* | ||
* @return the resulting concatenation | ||
*/ | ||
@Override | ||
String toString(); | ||
|
||
/** | ||
* Prints this object on the screen. | ||
*/ | ||
void print(); | ||
} |
Oops, something went wrong.