From 764fccf0b546f05bd46ca42d04e5aaed1af5e9f5 Mon Sep 17 00:00:00 2001 From: Jan-Peter Klein Date: Thu, 10 Oct 2024 17:34:23 +0200 Subject: [PATCH] pr mentioned changes --- ...GoogleDriveMacLocationPresetsProvider.java | 60 +++++++++---------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/cryptomator/common/locationpresets/GoogleDriveMacLocationPresetsProvider.java b/src/main/java/org/cryptomator/common/locationpresets/GoogleDriveMacLocationPresetsProvider.java index 65c913dee..88ac67707 100644 --- a/src/main/java/org/cryptomator/common/locationpresets/GoogleDriveMacLocationPresetsProvider.java +++ b/src/main/java/org/cryptomator/common/locationpresets/GoogleDriveMacLocationPresetsProvider.java @@ -34,11 +34,9 @@ public final class GoogleDriveMacLocationPresetsProvider implements LocationPres @Override public Stream getLocations() { - if (isRootLocationPresent()) { - return getCloudStorageDirLocations(); - } else { - return getFallbackLocation(); - } + List 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. *

- * 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}. *

- * 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)}. *

* - * @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 getCloudStorageDirLocations() { + private List 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. *

- * 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}. *

- * 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 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. *

* 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. - *

- * 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 getFallbackLocation() { - return FALLBACK_LOCATIONS.stream() // - .filter(Files::isDirectory) // + private List 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. *

* 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. *

* The translations were originally extracted from the Chromium project’s Chrome OS translation files. *

* Source: `ui/chromeos/translations` directory in the Chromium repository. */ - private static final Set 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 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"); }