Class SharedI18nContextProvider

java.lang.Object
dev.orne.i18n.context.AbstractI18nContextProvider
dev.orne.i18n.context.SharedI18nContextProvider
All Implemented Interfaces:
I18nContextProvider

@API(status=STABLE, since="0.1") public class SharedI18nContextProvider extends AbstractI18nContextProvider
Implementation of I18nContextProvider that shares a single I18nContext instance for all threads.
Since:
0.2
Version:
1.0, 2022-10
Author:
(w) Iker Hernaez
See Also:
  • Field Details

  • Constructor Details

    • SharedI18nContextProvider

      protected SharedI18nContextProvider(@NotNull @NotNull SharedI18nContextProvider.BuilderImpl<?,?> builder)
      Creates a new instance based on specified builder.
      Parameters:
      builder - The I18N context provider builder.
  • Method Details

    • builder

      @NotNull public static @NotNull SharedI18nContextProvider.Builder builder()
      Creates a new SharedI18nContextProvider instances builder.
      Returns:
      The SharedI18nContextProvider instances builder.
    • getContext

      @NotNull public @NotNull I18nContext getContext()
      Return the I18nContext associated with the current Thread.

      If no I18nContext exists for the current Thread or the existing one is not alive anymore a new one is created.

      Returns:
      The current I18nContext. Never null.
    • isContextValid

      public boolean isContextValid(@NotNull @NotNull I18nContext context)
      Returns true if the specified context is valid or should be discarded.
      Parameters:
      context - The I18N context
      Returns:
      true if the specified context is valid
    • clearContext

      public void clearContext()
      Clears the I18N context for the current thread.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class AbstractI18nContextProvider
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class AbstractI18nContextProvider