pr mentioned changes

This commit is contained in:
Jan-Peter Klein 2024-10-10 17:34:23 +02:00
parent 2dce7b6f71
commit 764fccf0b5
No known key found for this signature in database
GPG Key ID: 90EDA3A7C822FD0E

View File

@ -34,11 +34,9 @@ public final class GoogleDriveMacLocationPresetsProvider implements LocationPres
@Override
public Stream<LocationPreset> getLocations() {
if (isRootLocationPresent()) {
return getCloudStorageDirLocations();
} else {
return getFallbackLocation();
}
List<LocationPreset> cloudStorageDirLocations = getCloudStorageDirLocations();
return cloudStorageDirLocations.isEmpty() ? getFallbackLocation().stream() : cloudStorageDirLocations.stream();
}
@CheckAvailability
@ -49,11 +47,9 @@ public final class GoogleDriveMacLocationPresetsProvider implements LocationPres
/**
* Checks if a root location directory is present that matches the specified pattern.
* <p>
* This method scans the `ROOT_LOCATION` directory for subdirectories and tests each one against a pre-defined pattern.
* The method returns `true` if at least one directory is found that satisfies the pattern condition, and `false` otherwise.
* This method scans the {@code ROOT_LOCATION} directory for subdirectories and tests each one against a pre-defined pattern ({@code PATTERN}).
*
* @return {@code true} if a matching root location is present, otherwise {@code false}.
* @throws UncheckedIOException if an I/O error occurs during directory traversal.
*/
public static boolean isRootLocationPresent() {
try (var dirStream = Files.list(ROOT_LOCATION)) {
@ -75,33 +71,34 @@ public final class GoogleDriveMacLocationPresetsProvider implements LocationPres
}
/**
* Retrieves a stream of `LocationPreset` objects from directories within the `ROOT_LOCATION` path.
* Retrieves a list of cloud storage directory locations based on the {@code ROOT_LOCATION}.
* <p>
* This method lists all directories in the `ROOT_LOCATION`, filters them based on whether their names match
* a predefined pattern (`PATTERN`), and then extracts presets using `getPresetsFromAccountPath(Path)`.
* The results are collected into a list and returned as a stream.
* This method lists all directories in the {@code ROOT_LOCATION}, filters them based on whether their names match
* a predefined pattern ({@code PATTERN}), and then extracts presets using {@code getPresetsFromAccountPath(Path)}.
* <p>
*
* @return a stream of `LocationPreset` objects representing valid cloud storage directory locations.
* @return a list of {@code LocationPreset} objects representing valid cloud storage directory locations.
*/
private Stream<LocationPreset> getCloudStorageDirLocations() {
private List<LocationPreset> getCloudStorageDirLocations() {
try (var dirStream = Files.list(ROOT_LOCATION)) {
return dirStream.filter(path -> Files.isDirectory(path) && PATTERN.test(path.getFileName().toString())).flatMap(this::getPresetsFromAccountPath).toList().stream();
return dirStream.filter(path -> Files.isDirectory(path) && PATTERN.test(path.getFileName().toString()))
.flatMap(this::getPresetsFromAccountPath)
.toList();
} catch (IOException | UncheckedIOException e) {
return Stream.empty();
return List.of();
}
}
/**
* Retrieves a stream of `LocationPreset` objects from a given Google Drive account path.
* Retrieves a stream of {@code LocationPreset} objects from a given Google Drive account path.
* <p>
* This method lists all directories within the provided `accountPath` and filters them
* to identify folders whose names match any of the translations defined in `MY_DRIVE_TRANSLATIONS`.
* This method lists all directories within the provided {@code accountPath} and filters them
* to identify folders whose names match any of the translations defined in {@code MY_DRIVE_TRANSLATIONS}.
* <p>
* Each matching folder is then converted into a `LocationPreset` object.
* Each matching folder is then converted into a {@code LocationPreset} object.
*
* @param accountPath the root path of the Google Drive account to scan.
* @return a stream of `LocationPreset` objects representing matching directories.
* @return a stream of {@code LocationPreset} objects representing matching directories.
*/
private Stream<LocationPreset> getPresetsFromAccountPath(Path accountPath) {
try (var driveStream = Files.list(accountPath)) {
@ -119,35 +116,32 @@ public final class GoogleDriveMacLocationPresetsProvider implements LocationPres
}
/**
* Returns a stream containing a fallback location preset for Google Drive.
* Returns a list containing a fallback location preset for Google Drive.
* <p>
* This method iterates through the predefined fallback locations, checks if any of them is a directory,
* and creates a `LocationPreset` object for the first matching directory found. The resulting stream contains
* either one preset (if a matching directory is found) or is empty.
* <p>
* This method is marked as {@code @Deprecated} because it is intended for legacy support only and may be removed in future versions.
* and creates a {@code LocationPreset} object for the first matching directory found.
*
* @return a stream containing a single fallback location preset if a valid directory is found, otherwise an empty stream.
* @return a list containing a single fallback location preset if a valid directory is found, otherwise an empty list.
* @deprecated This method is intended for legacy support and may be removed in future releases.
*/
@Deprecated
private Stream<LocationPreset> getFallbackLocation() {
return FALLBACK_LOCATIONS.stream() //
.filter(Files::isDirectory) //
private List<LocationPreset> getFallbackLocation() {
return FALLBACK_LOCATIONS.stream()
.filter(Files::isDirectory)
.map(location -> new LocationPreset("Google Drive", location))
.findFirst()
.stream();
.stream()
.toList();
}
/**
* Set of translations for "My Drive" in various languages.
* <p>
* This constant is used to identify different language-specific labels for "My Drive" in Google Drive.
* By using a {@link HashSet}, duplicate entries are automatically removed, ensuring a unique set of translations.
* <p>
* The translations were originally extracted from the Chromium projects Chrome OS translation files.
* <p>
* Source: `ui/chromeos/translations` directory in the Chromium repository.
*/
private static final Set<String> MY_DRIVE_TRANSLATIONS = new HashSet<>(List.of("My Drive", "የእኔ Drive", "ملفاتي", "মোৰ ড্ৰাইভ", "Diskim", "Мой Дыск", "Моят диск", "আমার ড্রাইভ", "Moj disk", "La meva unitat", "Můj disk", "My Drive", "Mit drev", "Meine Ablage", "Το Drive μου", "My Drive", "Mi unidad", "Mi unidad", "Minu ketas", "Nire unitatea", "My Drive", "Aking Drive", "Oma Drive", "Mon disque", "Mon Drive", "A miña unidade", "મારી ડ્રાઇવ", "मेरी ड्राइव", "Moj disk", "Saját meghajtó", "Իմ դրայվը", "Drive Saya", "Drifið mitt", "I miei file", "האחסון שלי", "マイドライブ", "ჩემი Drive", "Менің Drive дискім", "ដ្រាយរបស់ខ្ញុំ", "ನನ್ನ ಡ್ರೈವ್", "내 드라이브", "Менин Drive'ым", "My Drive", "Mano Diskas", "Mans disks", "Мојот Drive", "എന്റെ ഡ്രൈവ്", "Миний Драйв", "माझा ड्राइव्ह", "Drive Saya", "My Drive", "मेरो ड्राइभ", "Mijn Drive", "Min disk", "ମୋ ଡ୍ରାଇଭ୍", "My Drive", "Mój dysk", "Meu Drive", "O meu disco", "Contul meu Drive", "Мой диск", "මගේ Drive", "Môj disk", "Moj disk", "Disku im", "Moj disk", "Мој диск", "Min enhet", "Hifadhi Yangu", "எனது இயக்ககம்", "నా డ్రైవ్‌", "ไดรฟ์ของฉัน", "Drive'ım", "Мій диск", "میری ڈرائیو", "My Drive", "Drive của tôi", "我的云端硬盘", "我的雲端硬碟", "我的雲端硬碟", "IDrayivu yami"));
private static final Set<String> MY_DRIVE_TRANSLATIONS = Set.of("My Drive", "የእኔ Drive", "ملفاتي", "মোৰ ড্ৰাইভ", "Diskim", "Мой Дыск", "Моят диск", "আমার ড্রাইভ", "Moj disk", "La meva unitat", "Můj disk", "Mit drev", "Meine Ablage", "Το Drive μου", "Mi unidad", "Minu ketas", "Nire unitatea", "Aking Drive", "Oma Drive", "Mon disque", "Mon Drive", "A miña unidade", "મારી ડ્રાઇવ", "मेरी ड्राइव", "Saját meghajtó", "Իմ դրայվը", "Drive Saya", "Drifið mitt", "I miei file", "האחסון שלי", "マイドライブ", "ჩემი Drive", "Менің Drive дискім", "ដ្រាយរបស់ខ្ញុំ", "ನನ್ನ ಡ್ರೈವ್", "내 드라이브", "Менин Drive'ым", "Mano Diskas", "Mans disks", "Мојот Drive", "എന്റെ ഡ്രൈവ്", "Миний Драйв", "माझा ड्राइव्ह", "मेरो ड्राइभ", "Mijn Drive", "Min disk", "ମୋ ଡ୍ରାଇଭ୍", "Mój dysk", "Meu Drive", "O meu disco", "Contul meu Drive", "Мой диск", "මගේ Drive", "Môj disk", "Disku im", "Мој диск", "Min enhet", "Hifadhi Yangu", "எனது இயக்ககம்", "నా డ్రైవ్‌", "ไดรฟ์ของฉัน", "Drive'ım", "Мій диск", "میری ڈرائیو", "Drive của tôi", "我的云端硬盘", "我的雲端硬碟", "IDrayivu yami");
}