Skip to content

Commit

Permalink
add display method interface
Browse files Browse the repository at this point in the history
  • Loading branch information
infeo committed Jul 1, 2024
1 parent 4bfb945 commit aad9c04
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/org/cryptomator/integrations/common/DisplayName.java
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();

}
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();
}
}
}

0 comments on commit aad9c04

Please sign in to comment.