Class ThreadI18nContextProvider

java.lang.Object
dev.orne.i18n.context.AbstractI18nContextProvider
dev.orne.i18n.context.ThreadI18nContextProvider
All Implemented Interfaces:
I18nContextProvider
Direct Known Subclasses:
I18nSpringContextProvider

@API(status=STABLE, since="0.1") public class ThreadI18nContextProvider extends AbstractI18nContextProvider
Implementation of I18nContextProvider that provides a different I18nContext for each thread.
Since:
0.1
Version:
2.0, 2022-12
Author:
(w) Iker Hernaez
See Also:
  • Field Details

  • Constructor Details

    • ThreadI18nContextProvider

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

    • builder

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

      public boolean isInheritable()
      Returns true if the I18nContext instances will be inherited by child threads.
      Returns:
      If the I18nContext instances will be inherited by child threads.
    • getContexts

      @NotNull protected @NotNull ThreadLocal<I18nContext> getContexts()
      Returns the internal I18nContexts per Thread container.
      Returns:
      The I18nContexts per Thread container
    • 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)
      The default contexts don't expire.
      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