Class PropertyCheck


  • public class PropertyCheck
    extends java.lang.Object
    Helper class for for use when checking properties. This class uses I18N for its messages.
    Author:
    Derek Hulley
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ERR_PROPERTY_NOT_SET  
    • Constructor Summary

      Constructors 
      Constructor Description
      PropertyCheck()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getPropertyName​(java.lang.String value)
      Dig out the property name from a placeholder-style property of form ${prop.name}, which will yield prop.name.
      static boolean isValidPropertyString​(java.lang.String value)
      Checks that the given string is not: null empty a placeholder of form '${...}'
      static void mandatory​(java.lang.Object target, java.lang.String propertyName, java.lang.Object value)
      Checks that the property with the given name is not null.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ERR_PROPERTY_NOT_SET

        public static final java.lang.String ERR_PROPERTY_NOT_SET
        See Also:
        Constant Field Values
    • Constructor Detail

      • PropertyCheck

        public PropertyCheck()
    • Method Detail

      • mandatory

        public static void mandatory​(java.lang.Object target,
                                     java.lang.String propertyName,
                                     java.lang.Object value)
        Checks that the property with the given name is not null.
        Parameters:
        target - the object on which the property must have been set
        propertyName - the name of the property
        value - of the property value
      • isValidPropertyString

        public static boolean isValidPropertyString​(java.lang.String value)
        Checks that the given string is not:
        • null
        • empty
        • a placeholder of form '${...}'
        Parameters:
        value - the value to check
        Returns:
        true if the checks all pass
      • getPropertyName

        public static java.lang.String getPropertyName​(java.lang.String value)
        Dig out the property name from a placeholder-style property of form ${prop.name}, which will yield prop.name. If the placeholders are not there, the value is returned directly. null values are not allowed, but empty strings are.
        Parameters:
        value - The property with or without property placeholders
        Returns:
        Returns the core property without the property placeholders ${ and }.
        Throws:
        java.lang.IllegalArgumentException - if the value is null