Skip to content

Conversation

@frigoref
Copy link
Member

  • method newMapUrlAndSizeLabelText: Extracted logic to separate methods
  • new method appendSizeAndPath: Includes sum up in case multiple downloaded maps are selected
  • new method appendSizeAndPathSingle

FileUtils.java

  • new method getFolderSize
  • new method getByteSizeFromPath

Notes to Reviewer

I tried to also get the size from the maps selected to be downloaded, but the GitHub-URLs did never return the size and a download just to know the size was pointless.

- method newMapUrlAndSizeLabelText: Extracted logic to separate methods
- new method appendSizeAndPath: Includes sum up in case multiple downloaded maps are selected
- new method appendSizeAndPathSingle

FileUtils.java
- new method getFolderSize
- new method getByteSizeFromPath
@DanVanAtta
Copy link
Member

What is the performance like of this update for the very large maps? I believe TWW is the largest map at like 200MB or something.

@frigoref
Copy link
Member Author

I did not recognize any even when selecting multiple maps with >400MB

- method getTextForSizeAndPath: Restructure processing with static methods
final long[] size = {0};

Files.walkFileTree(
folderPath,
Copy link
Member

Choose a reason for hiding this comment

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

Does walkFileTree work regardless of whether we have a directory or a file? If so, we don't need the check for is a file and this method can be combined into getByteSizeFromPath

Copy link
Member Author

Choose a reason for hiding this comment

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

The check is already done in method getByteSizeFromPath

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, what I'm saying is that check is potentially not needed. You can maybe simplify and just walk the file tree whether the parameter is a file or a directory.

The javadocs for the method make it sound like the parameter can be a file:

Where the file is a directory....

From:
https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#walkFileTree-java.nio.file.Path-java.nio.file.FileVisitor-

Copy link
Member Author

Choose a reason for hiding this comment

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

@DanVanAtta I am not clear one what that would help: If the path is not a file what is the expectation when calling method walkFileTree? From my perspective the way it is written now it is more clear what is supposed to happen.

Copy link
Member

Choose a reason for hiding this comment

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

If the path is not a file what is the expectation when calling method walkFileTree?

Returns just the file

From my perspective the way it is written now it is more clear what is supposed to happen.

I think questions are raised for why walkFileTree not being used. It's overly complicated, the getByteSizeFromPath seems entirely unnecessary.The questions are specifically things like "what did the author know that I don't that makes this not usable?" It's exactly the same scenario where we were wondering about ppt.getTerritory() and why that value was not being used directly - it's a mystery why it's coded that way since a simpler solution seems obvious.

Copy link
Member

Choose a reason for hiding this comment

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

If I misunderstand how walkFileTree works, then the two methods are reasonable. Let's experiment a bit.

The javadocs sound like we should be getting back the same file:

This method walks a file tree rooted at a given starting file. The file tree traversal is depth-first with the given FileVisitor invoked for each file encountered.

https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#walkFileTree(java.nio.file.Path,java.util.Set,int,java.nio.file.FileVisitor)

Fixes according to review comments
BattleCalculatorPanel.java
- use new constant for N/A

DownloadMapsWindow.java
- constant for "N/A"
- method getTextForSizeAndPath: rename map -> selectedMap; use new method mapsWindowModel.getByteSizeTextForMap
- move getTextForSizeAndPathByMapPath to DownloadMapsWindowModel
- method getTextForSizeAndPathFromMaps: rename map -> mapItem

DownloadMapsWindowModel.java
- new method getByteSizeTextForMap

FileUtils.java
- method getFolderSize: moved after usage as method is private
@frigoref
Copy link
Member Author

frigoref commented Jul 2, 2025

I hope I have not missed any of the already clarified comments in my new commit 2ca1ac5.
Please check and let me know.

return installedMapsListing.findMapFolderByName(mapDownloadItem.getMapName());
}

public Optional<@NonNls String> getByteSizeTextForMap(final MapDownloadItem mapDownloadItem) {
Copy link
Member

Choose a reason for hiding this comment

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

Should return a number here. Returning a string is mixing the UI and model logic together.

Copy link
Member Author

Choose a reason for hiding this comment

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

What with exception case?
Maybe you provide a commit for this to show me what you think is best.

Copy link
Member

Choose a reason for hiding this comment

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

Change:

byteSizeText =
                    org.apache.commons.io.FileUtils.byteCountToDisplaySize(
                        org.triplea.io.FileUtils.getByteSizeFromPath(mapPath));

To:

   return                    org.apache.commons.io.FileUtils.byteCountToDisplaySize(
                        org.triplea.io.FileUtils.getByteSizeFromPath(mapPath));

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is resolved now, right?

Copy link
Member

Choose a reason for hiding this comment

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

I don't see any updates since my original comments nor any discussion based on the suggestion. I don't see any evidence for how this was resolved - I don't think it was.

defenderLeftWhenDefenderWon.setText(
Double.isNaN(avgDefIfDefWon)
? "N/A"
? DownloadMapsWindow.TEXT_ABBREVIATION_NOT_APPLICABLE
Copy link
Member

Choose a reason for hiding this comment

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

IMO, leave the string inlined here. Why should DownloadMapsWindow own the N/A string?

I don't think the constant is really helping very much, it's okay to let things be inlined and duplicated sometimes.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is needed to make it translateble only once. The usage is the same, but I did not want to create an own class for it. At leadt not now when there are no others yet.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, but we're not making it translatable just yet. Let's do this work when we do the other thing. Otherwise this is just half done. Let's leave it be unless we do the whole effort.

Copy link
Member Author

Choose a reason for hiding this comment

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

We are outsourcing the text and combine 3 places into one. I do not see what benefit it has to undo it in order to redo it again in the future.

Copy link
Member

Choose a reason for hiding this comment

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

I do not see what benefit it has to undo it in order to redo it again in the future.

I'm suggesting that is premature optimization. Who is to say this class will even exist in its current form when we do redo it. The rule of thumb, have the simplest possible code for now, do the other stuff when it is needed. Would you prefer to add a feature to the simplest possible code base, or would you prefer to add a feature that tried to predict all the features that were going to be added?

To another extent, this PR is to "calculate the size of downloaded maps when selected." What does that have to do with internationalizing the string N/A?

FileUtils.java
- removed method getFolderSize
- method getByteSizeFromPath: Take over code from getFolderSize
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