Skip to content

Commit aad9c04

Browse files
committed
add display method interface
1 parent 4bfb945 commit aad9c04

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.cryptomator.integrations.common;
2+
3+
import java.lang.annotation.Documented;
4+
import java.lang.annotation.ElementType;
5+
import java.lang.annotation.Retention;
6+
import java.lang.annotation.RetentionPolicy;
7+
import java.lang.annotation.Target;
8+
9+
import org.jetbrains.annotations.ApiStatus;
10+
11+
/**
12+
* A humanreadable name of the annotated class.
13+
*/
14+
@Documented
15+
@Retention(RetentionPolicy.RUNTIME)
16+
@Target(ElementType.TYPE)
17+
@ApiStatus.Experimental
18+
public @interface DisplayName {
19+
String value();
20+
21+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.cryptomator.integrations.common;
2+
3+
/**
4+
* A service provider with a specific, human-readable name.
5+
*
6+
*/
7+
public interface NamedServiceProvider {
8+
9+
/**
10+
* Get the name of this service provider.
11+
* @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.
12+
* @return The name of the service provider
13+
*
14+
* @see DisplayName
15+
*/
16+
default public String getName() {
17+
var displayName = this.getClass().getAnnotation(DisplayName.class);
18+
if(displayName != null) {
19+
return displayName.value();
20+
} else {
21+
return this.getClass().getName();
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)