Class TypeMessages


  • public class TypeMessages
    extends TypeHolder<java.lang.String>
    An internal holder of the custom message for type. It is used to store messages for registered classes. When looking for a message for a given class the holder returns the most relevant comparator.
    • Constructor Summary

      Constructors 
      Constructor Description
      TypeMessages()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getMessageForType​(java.lang.Class<?> clazz)
      This method returns the most relevant error message for the given class.
      boolean hasMessageForType​(java.lang.Class<?> type)
      Checks, whether an any custom error message is associated with the giving type.
      java.util.stream.Stream<java.util.Map.Entry<java.lang.Class<?>,​java.lang.String>> messageByTypes()
      Returns a sequence of all type-message pairs which the current holder supplies.
      <T> void registerMessage​(java.lang.Class<T> clazz, java.lang.String message)
      Puts the message for the given clazz.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • TypeMessages

        public TypeMessages()
    • Method Detail

      • getMessageForType

        public java.lang.String getMessageForType​(java.lang.Class<?> clazz)
        This method returns the most relevant error message for the given class. The most relevant message is the message which is registered for the class that is closest in the inheritance chain of the given clazz. The order of checks is the following: 1. If there is a registered message for clazz then this one is used 2. We check if there is a registered message for a superclass of clazz 3. We check if there is a registered message for an interface of clazz
        Parameters:
        clazz - the class for which to find an error message
        Returns:
        the most relevant error message, or null if no message could be found
      • hasMessageForType

        public boolean hasMessageForType​(java.lang.Class<?> type)
        Checks, whether an any custom error message is associated with the giving type.
        Parameters:
        type - the type for which to check a error message
        Returns:
        is the giving type associated with any custom error message
      • registerMessage

        public <T> void registerMessage​(java.lang.Class<T> clazz,
                                        java.lang.String message)
        Puts the message for the given clazz.
        Type Parameters:
        T - the type of the objects to associate with the message for
        Parameters:
        clazz - the class for the error message
        message - the error message itself
      • messageByTypes

        public java.util.stream.Stream<java.util.Map.Entry<java.lang.Class<?>,​java.lang.String>> messageByTypes()
        Returns a sequence of all type-message pairs which the current holder supplies.
        Returns:
        sequence of field-message pairs