-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
amend: refactor ResolveMultiPath enum to encapsulate url selection lo…
…gic (#1079)
- Loading branch information
Showing
2 changed files
with
48 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 29 additions & 5 deletions
34
idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/core/ResolveMultiPath.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,33 @@ | ||
package com.itangcent.idea.plugin.api.export.core | ||
|
||
import com.itangcent.common.model.URL | ||
import com.itangcent.common.utils.longest | ||
import com.itangcent.common.utils.shortest | ||
|
||
/** | ||
* This enumeration defines strategies to resolve multiple URLs to a single URL, | ||
* based on different criteria like the first URL, last URL, longest URL, or shortest URL. | ||
* It also provides a strategy to return all URLs as-is without any resolution. | ||
*/ | ||
enum class ResolveMultiPath { | ||
FIRST, | ||
LAST, | ||
LONGEST, | ||
SHORTEST, | ||
ALL | ||
FIRST { | ||
override fun resolve(url: URL): URL = URL.of(url.urls().firstOrNull()) | ||
}, | ||
LAST { | ||
override fun resolve(url: URL): URL = URL.of(url.urls().lastOrNull()) | ||
}, | ||
LONGEST { | ||
override fun resolve(url: URL): URL = URL.of(url.urls().longest()) | ||
}, | ||
SHORTEST { | ||
override fun resolve(url: URL): URL = URL.of(url.urls().shortest()) | ||
}, | ||
ALL { | ||
override fun resolve(url: URL): URL = url | ||
}; | ||
|
||
/** | ||
* resolve the given URL based on the implemented strategy | ||
*/ | ||
abstract fun resolve(url: URL): URL | ||
} |