Interface Formatter<T>

Type Parameters:
T - the formatted type
All Known Subinterfaces:
Formatter.Identity
All Known Implementing Classes:
AddressSerializer.JGroupsAddressFormatter, EmbeddedCacheManagerGroupMemberSerializer.AddressGroupMemberFormatter, Formatter.Provided, KeyFormatter, LocalEmbeddedCacheManagerGroupMemberFormatter, SessionAttributesKeyFormatter, SessionKeyFormatter, SessionMetaDataKeyFormatter, UserContextKeyFormatter, UserSessionsKeyFormatter

public interface Formatter<T>
Formats an objects into a string representation and back again.
Author:
Paul Ferraro
  • Field Details

  • Method Details

    • getType

      Class<? extends T> getType()
      Returns the type of the formatted object.
      Returns:
      the type of the formatted object.
    • parse

      T parse(String value)
      Parses the key from the specified string.
      Parameters:
      value - a string representation of the key
      Returns:
      the parsed key
    • format

      String format(T value)
      Formats the specified key to a string representation.
      Parameters:
      value - a key to format
      Returns:
      a string representation of the specified key.
    • wrap

      default <U> Formatter<U> wrap(Class<? extends U> type, Function<U,T> unwrapper, Function<T,U> wrapper)
      Returns a wrapped formatter.
      Type Parameters:
      U - the wrapped type
      Parameters:
      type - the wrapped type
      unwrapper - the unwrapper function
      wrapper - the wrapper function
      Returns:
      a wrapped formmater
    • of

      static <T> Formatter<T> of(T value)
      Creates a formatter whose parse(String) always returns the specified value.
      Type Parameters:
      T - the formatted type
      Parameters:
      value - the fixed value
      Returns:
      a formatter whose parse(String) always returns the specified value.
    • joining

      static <T,V1,V2> Formatter<T> joining(Class<? extends T> type, String delimiter, Formatter<V1> formatter1, Formatter<V2> formatter2, Function<T,V1> unwrapper1, Function<T,V2> unwrapper2, BiFunction<V1,V2,T> wrapper)
      Creates a composite formatter from the specified formatters.
      Type Parameters:
      T - the formatted type
      V1 - the former component formatter
      V2 - the latter component formatter
      Parameters:
      type - the formatted type
      delimiter - a delimiter
      formatter1 - the former formatter
      formatter2 - the latter formatter
      unwrapper1 - the unwrapper of the former formatter
      unwrapper2 - the unwrapper of the latter formatter
      wrapper - a wrapper of the component formatters
      Returns:
      a composite formatter
    • joining

      static <T> Formatter<T> joining(Class<? extends T> type, String delimiter, Function<T,String[]> unwrapper, Function<String[],T> wrapper)
      Creates a composite formatter from the specified formatters.
      Type Parameters:
      T - the formatted type
      Parameters:
      type - the formatted type
      delimiter - a delimiter
      unwrapper - the parsing unwrapping function
      wrapper - the formatter wrapping function
      Returns:
      a composite formatter from the specified formatters.