Interface Displayable

All Known Subinterfaces:
HtmlDisplayable, MutableDisplayable, PlainTextDisplayable
All Known Implementing Classes:
FileEntity
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Displayable
The role of an object which can provide its own display name.
Since:
2.0-ALPHA-1
Author:
Fabrizio Giudici
Status: stable API
Stereotype:
Role
  • Field Details

    • _Displayable_

      static final Class<Displayable> _Displayable_
    • DEFAULT

      static final Displayable DEFAULT
      A default Displayable with an empty display name.
  • Method Details

    • getDisplayName

      @Nonnull String getDisplayName()
      Returns the display name in the current Locale.
      Returns:
      the display name
    • getDisplayName

      @Nonnull default String getDisplayName(@Nonnull Locale locale)
      Returns the display name in the given Locale.
      Parameters:
      locale - the Locale
      Returns:
      the display name
      Since:
      2.0-ALPHA-2
    • getDisplayNames

      @Nonnull default Map<Locale,String> getDisplayNames()
      Returns all the display names in Map where they are indexed by Locale.
      Returns:
      the display names
      Since:
      2.0-ALPHA-2
    • getLocales

      @Nonnull default SortedSet<Locale> getLocales()
      Returns the supported Locales.
      Returns:
      the available Locales
      Since:
      2.0-ALPHA-2
    • display

      default void display(@Nonnull Consumer<String> consumer)
      Sends the display name in the current Locale to a given customer.
      Parameters:
      consumer - the Consumer
      Since:
      3.2-ALPHA-15
    • of

      @Nonnull static Displayable of(@Nonnull String displayName)
      Creates an instance with a given display name.
      Parameters:
      displayName - the display name
      Returns:
      the new instance
      Since:
      3.2-ALPHA-1 (was DefaultDisplayable
    • of

      @Nonnull static Displayable of(@Nonnull String displayName, @Nonnull String toStringName)
      Creates an instance with a given display name iand an explicit label for toString().
      Parameters:
      displayName - the display name
      toStringName - the name to be rendered when toString() is called
      Returns:
      the new instance
      Since:
      3.2-ALPHA-1 (was DefaultDisplayable
    • of

      @Nonnull static Displayable of(@Nonnull Supplier<String> supplier)
      Creates an instance from a Supplier<String>. The supplier is invoked each time getDisplayName() is called.
      Parameters:
      supplier - the Supplier
      Returns:
      the new instance
      Since:
      3.2-ALPHA-3
    • of

      @Nonnull static <T> Displayable of(@Nonnull Function<T,String> function, @Nonnull T object)
      Creates an instance from a Function<T, String> and a generic object that the function is applied to. The function is invoked each time getDisplayName() is called.
      Type Parameters:
      T - the type of the object
      Parameters:
      function - the Function
      object - the object
      Returns:
      the new instance
      Since:
      3.2-ALPHA-3
    • fromBundle

      @Nonnull static Displayable fromBundle(@Nonnull Class<?> ownerClass, @Nonnull String key)
      Creates a Displayable from a resource bundle. The bundle resource file is named Bundle.properties and it should be placed in the same package as the owner class.
      Parameters:
      ownerClass - the class that owns the bundle
      key - the resource key
      Returns:
      the new instance
      Since:
      2.0-ALPHA-2
    • comparing

      @Nonnull static Comparator<Displayable> comparing()
      Returns a Comparator for comparing two instances of Displayable.
      Returns:
      the Comparator
      Since:
      3.2-ALPHA-6
    • asComparing

      @Nonnull static Comparator<it.tidalwave.util.As> asComparing()
      Returns a Comparator for comparing two instances of objects implementing As that contain the Displayable role.
      Returns:
      the Comparator
      Since:
      3.2-ALPHA-6
    • render

      @Nonnull default String render(@Nonnull Object... args)
      Renders the attached object into a String. The method accepts optional parameters that can be used to control the format of the rendering; they are usually specific of the object attached to this role.
      Parameters:
      args - optional rendering parameters
      Returns:
      the string
    • renderTo

      default void renderTo(@Nonnull Consumer<? super String> consumer, @Nonnull Object... args)
      Renders the attached object providing the string tu a Consumer. The method accepts optional parameters that can be used to control the format of the rendering; they are usually specific of the object attached to this role.
      Parameters:
      consumer - the Consumer to append to
      args - optional rendering parameters