Skip to content

Commit

Permalink
refactor: Collections.sort could be replaced with List.sort
Browse files Browse the repository at this point in the history
  • Loading branch information
ghusta committed Jan 2, 2024
1 parent 6518ba7 commit 4b0ceb3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Objects;

import androidx.appcompat.app.AlertDialog;
Expand Down Expand Up @@ -276,7 +275,7 @@ public boolean onQueryTextSubmit(String query)
.doOnSubscribe(data -> progressBar.show())
.subscribe(data -> {
Log.d(TAG, "searchImagesAsync.onResponse: returned " + data.getResults().size() + " out of " + data.getNumResults());
Collections.sort(data.getResults(), new DefaultImageSearchComparator());
data.getResults().sort(new DefaultImageSearchComparator());

dockerImageExpandableListAdapter.notifyDataSetInvalidated(); // necessaire ?
// Collapse all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import org.junit.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import fr.husta.android.dockersearch.docker.model.ImageSearchResult;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;

public class DefaultImageSearchComparatorTest
{
Expand All @@ -35,7 +33,7 @@ public void compare() throws Exception
ImageSearchResult elt5 = new ImageSearchResult("elt5", "elt5", false, 2);
list.add(elt5);

Collections.sort(list, comparator);
list.sort(comparator);
assertThat(list).isNotEmpty();
// #1 => elt3
assertThat(list.get(0)).isSameInstanceAs(elt3);
Expand Down

0 comments on commit 4b0ceb3

Please sign in to comment.