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

Porting ho table model to kotlin #2177

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

wsbrenk
Copy link
Collaborator

@wsbrenk wsbrenk commented Nov 4, 2024

  1. changes proposed in this pull request:

    • fixes issue #___
    • if not fixing an existing issue, comments explaining the purpose of the PR should be provided)

My first steps in kotlin programming.
I'm really excited if this can lead to us being able to support Android in the near future (HO10 or HO11 !?).
I don't think it's so great that we lose the history of the changes on this tour.

  1. src/main/resources/release_notes.md ...
  • has been updated
  • does not require update
  1. [Optional] suggested person to review this PR @tychobrailleur

@tychobrailleur
Copy link
Collaborator

I don't think it's so great that we lose the history of the changes on this tour.

I experimented with this a bit, and one way of approaching this is to git mv from java to kt in one commit, and then the next commit converts the content to Kotlin. I don't recommend it, though, because (a) on certain commits we will have broken builds, and (b) after the conversion, the git history will probably be garbage anyway.

@tychobrailleur
Copy link
Collaborator

I'll have a look when I get a chance, there is a lot to unpack here :)

Copy link
Collaborator

@tychobrailleur tychobrailleur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we discussed introducing Kotlin, I remember we had proposed adding unit tests as part of the migration. Is that still something you're keen on doing? For Swing components this may be tricky, but for something like HOConfigurationIntParameter or HOConfigurationParameter this can have some value.

So, how do you find Kotlin? :)

/**
* Position of the divider between fixed and scrollable tables
*/
private var dividerLocation: HOConfigurationIntParameter? = null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sure you've figured that out, but where possible we should use non-nullable types.

*/
override fun setRowSorter(sorter: RowSorter<out TableModel?>) {
super.setRowSorter(sorter)
if (fixed != null) fixed!!.rowSorter = sorter
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is equivalent to

fixed?.rowSorter = sorter

return try {
super.getColumn(identifier)
} catch (e: IllegalArgumentException) {
fixed!!.getColumn(identifier)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can cause an NPE if fixed is null

*/
fun getTableColumn(i: Int): TableColumn {
if (i < fixedColumnsCount) {
return fixed!!.columnModel.getColumn(i)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can cause an NPE if fixed is null

Comment on lines +100 to +109
if (_displayedColumns == null) {
val displayedColumnsList = ArrayList<UserColumn>()
for (column in columns) {
if (column.isDisplay) {
displayedColumnsList.add(column)
} // column is displayed
} // for
_displayedColumns = displayedColumnsList.toTypedArray()
}
return _displayedColumns as Array<UserColumn>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be simplified to something like:

    fun getDisplayedColumns(): Array<UserColumn> {
        if (_displayedColumns == null) {
			_displayedColumns = columns.filter { col -> col.isDisplay }.toTypedArray()
        }
        return _displayedColumns as Array<UserColumn>
    }

* @return int
*/
override fun getRowCount(): Int {
return if ((m_clData != null)) m_clData!!.size else 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be shortened to return m_clData?.size ?: 0

*/
fun initTable(table: JTable) {
this.table = table
if (table !is FixedColumnsTable) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, didn't know that was possible, is! :D

val sortKeys = ArrayList<RowSorter.SortKey>()
val sortColumns = Arrays.stream(this.columns).filter { i: UserColumn -> i.sortPriority != null }.sorted(
Comparator.comparingInt { obj: UserColumn -> obj.getSortPriority() }).toList()
if (!sortColumns.isEmpty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can become sortColumns.isNotEmpty()

Comment on lines +398 to +401
companion object {
@Serial
private val serialVersionUID = -207230110294902139L
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still not sure whether there is any point to serialVersionUID. My understanding was that this was used in serialization/deserialization, and to ensure that the changes made to a serializable class were compatible so that older version of a serialized instance can still be deserialized (I remember a loooong time this mattered for example in RMI), but I don't believe we make sure changes are compatible, or if serialization is even used here.

for (i in players!!.indices) {
val currentPlayer = players!![i]
for (j in tmpDisplayedColumns.indices) {
if (tmpDisplayedColumns[j].id == UserColumnFactory.NAME || tmpDisplayedColumns[j].id == UserColumnFactory.LINEUP || tmpDisplayedColumns[j].id == UserColumnFactory.BEST_POSITION || tmpDisplayedColumns[j].id == UserColumnFactory.SCHUM_RANK_BENCHMARK || tmpDisplayedColumns[j].id == UserColumnFactory.GROUP) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind breaking up into multiple lines for readability?

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

Successfully merging this pull request may close these issues.

2 participants