2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 13:47:41 +00:00

Replace Comparator implementations with lambda expressions.

This commit is contained in:
Isira Seneviratne 2020-07-01 08:01:02 +05:30
parent 03b61f7d1d
commit 6cfe45abfd
2 changed files with 8 additions and 16 deletions

View File

@ -42,6 +42,7 @@ import org.kde.kdeconnect_tp.R;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
@ -118,7 +119,7 @@ public class SftpPlugin extends Plugin implements SharedPreferences.OnSharedPref
ArrayList<String> pathNames = new ArrayList<>();
List<StorageInfo> storageInfoList = SftpSettingsFragment.getStorageInfoList(context, this);
Collections.sort(storageInfoList, new StorageInfo.UriNameComparator());
Collections.sort(storageInfoList, Comparator.comparing(StorageInfo::getUri));
if (storageInfoList.size() > 0) {
getPathsAndNamesForStorageInfoList(paths, pathNames, storageInfoList);
@ -306,6 +307,11 @@ public class SftpPlugin extends Plugin implements SharedPreferences.OnSharedPref
this.uri = uri;
}
@NonNull
Uri getUri() {
return uri;
}
static StorageInfo copy(StorageInfo from) {
//Both String and Uri are immutable
return new StorageInfo(from.displayName, from.uri);
@ -353,19 +359,5 @@ public class SftpPlugin extends Plugin implements SharedPreferences.OnSharedPref
result = 31 * result + uri.hashCode();
return result;
}
static class DisplayNameComparator implements java.util.Comparator<StorageInfo> {
@Override
public int compare(StorageInfo si1, StorageInfo si2) {
return si1.displayName.compareToIgnoreCase(si2.displayName);
}
}
static class UriNameComparator implements java.util.Comparator<StorageInfo> {
@Override
public int compare(StorageInfo si1, StorageInfo si2) {
return si1.uri.compareTo(si2.uri);
}
}
}
}

View File

@ -349,7 +349,7 @@ public class SftpSettingsFragment
}
private void sortStorageInfoListOnDisplayName() {
Collections.sort(storageInfoList, new SftpPlugin.StorageInfo.DisplayNameComparator());
Collections.sort(storageInfoList, (si1, si2) -> si1.displayName.compareToIgnoreCase(si2.displayName));
}
@NonNull