-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/main/java/org/cryptomator/integrations/common/DisplayName.java
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.cryptomator.integrations.common; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
/** | ||
* A humanreadable name of the annotated class. | ||
*/ | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
@ApiStatus.Experimental | ||
public @interface DisplayName { | ||
String value(); | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/cryptomator/integrations/common/NamedServiceProvider.java
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.cryptomator.integrations.common; | ||
|
||
/** | ||
* A service provider with a specific, human-readable name. | ||
* | ||
*/ | ||
public interface NamedServiceProvider { | ||
|
||
/** | ||
* Get the name of this service provider. | ||
* @implNote The default implementation looks for the {@link DisplayName} annotation and uses its value. If the annotation is not present, it falls back to the qualified class name. | ||
* @return The name of the service provider | ||
* | ||
* @see DisplayName | ||
*/ | ||
default public String getName() { | ||
var displayName = this.getClass().getAnnotation(DisplayName.class); | ||
if(displayName != null) { | ||
return displayName.value(); | ||
} else { | ||
return this.getClass().getName(); | ||
} | ||
} | ||
} |