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

IMAGING-151: use a copy of the list, make members package-protected/private, and re-use Comparator #64

Merged
merged 4 commits into from Dec 27, 2019

Conversation

kinow
Copy link
Member

@kinow kinow commented Dec 14, 2019

This PR creates a Comparator for ColorCount, 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

@kinow kinow self-assigned this Dec 14, 2019
@kinow
Copy link
Member Author

kinow commented Dec 14, 2019

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));
Copy link
Member Author

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()) {
Copy link
Member Author

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));
Copy link
Member Author

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.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 74.921% when pulling 56e9b2d on kinow:IMAGING-151 into a1072f6 on apache:master.

@kinow kinow merged commit 2e13c9e into apache:master Dec 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants