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
IMAGING-151: use a copy of the list, make members package-protected/private, and re-use Comparator #64
Conversation
Added a few comments too, but planning to add more later when working on IMAGING-146. |
|
||
Collections.sort(colorGroup.colorCounts, comp); | ||
final List<ColorCount> colorCounts = colorGroup.getColorCounts(); | ||
Collections.sort(colorCounts, new ColorCountComparator(mode)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorting the local variable now.
@@ -130,7 +130,7 @@ public Palette process(final BufferedImage image, final int maxColors, | |||
|
|||
colorGroup.paletteIndex = i; | |||
|
|||
if (colorGroup.colorCounts.size() < 1) { | |||
if (colorGroup.getColorCounts().isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are several other places with similar code smell, will raise a PR in the next hours to use isEmpty()
in the rest of the code when possible.
@@ -52,13 +50,13 @@ public boolean performNextMedianCut(final List<ColorGroup> colorGroups, | |||
if (ignoreAlpha && colorComponent == ColorComponent.ALPHA) { | |||
continue; | |||
} | |||
Collections.sort(colorGroup.colorCounts, new ColorComparer(colorComponent)); | |||
Collections.sort(colorCounts, new ColorCountComparator(colorComponent)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is sorted multiple times for each color component. Later a best color component will be chosen, and a final sort will take place.
This PR creates a
Comparator
forColorCount
, replacing two comparators created in different parts of the code with the same logic.The list that was sorted was a member of a class that could be used elsewhere. So instead of altering the values in that list, now other classes need to access that list through a method that returns a copy of the list.
Members in the package-protected class were made package-protected (from public) or private.
Bruno