Class Setting<T>


  • public class Setting<T>
    extends java.lang.Object
    Represents a value for a configuration. Provides methods to get the value as well as marking the value as locked. Each instance of this class has an associated ValueChecker. This checker can be used to check if the current value is valid. The default value _must_ be valid. Null values can not originate externally so are (mostly) considered valid.
    • Constructor Summary

      Constructors 
      Constructor Description
      Setting​(java.lang.String name, java.lang.String description, boolean locked, ValueValidator validator, T defaultValue, T value, java.lang.String source)
      Creates a new Settings object
      Setting​(Setting<T> other)
      Creates a new Settings object by cloning the values from another Settings object
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T getDefaultValue()  
      java.lang.String getDescription()  
      java.lang.String getName()  
      java.lang.String getSource()  
      ValueValidator getValidator()  
      T getValue()  
      boolean isLocked()  
      void setLocked​(boolean locked)
      Marks this setting as locked or unlocked.
      void setSource​(java.lang.String source)
      Sets the source of the current value of this Setting.
      void setValue​(T value)
      Note that setting the value is not enforced - it is the caller's responsibility to check if a value is locked or not before setting a new value
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • Setting

        public Setting​(java.lang.String name,
                       java.lang.String description,
                       boolean locked,
                       ValueValidator validator,
                       T defaultValue,
                       T value,
                       java.lang.String source)
        Creates a new Settings object
        Parameters:
        name - the name of this setting
        description - a human readable description of this setting
        locked - whether this setting is currently locked
        validator - the ValueValidator that can be used to validate the value
        defaultValue - the default value of this setting. If this is not a recognized setting, use null.
        value - the initial value of this setting
        source - the origin of the value (a file, or perhaps "<internal>")
      • Setting

        public Setting​(Setting<T> other)
        Creates a new Settings object by cloning the values from another Settings object
        Parameters:
        other - a Settings object to initialize settings from
    • Method Detail

      • getDefaultValue

        public T getDefaultValue()
        Returns:
        the default value for this setting. May be null if this is not one of the supported settings
      • getDescription

        public java.lang.String getDescription()
        Returns:
        a human readable description of this setting
      • getName

        public java.lang.String getName()
        Returns:
        the name (like foo.bar.baz) of this setting
      • getSource

        public java.lang.String getSource()
        Returns:
        the source of the current value of this setting. May be a string like "internal" or it may be the location of the properties file
      • getValue

        public T getValue()
        Returns:
        the current value of this setting
      • isLocked

        public boolean isLocked()
        Returns:
        true if this setting is locked
      • setLocked

        public void setLocked​(boolean locked)
        Marks this setting as locked or unlocked. Setting the value is not enforced by this class.
        Parameters:
        locked - whether to mark this setting as locked or not locked.
      • setSource

        public void setSource​(java.lang.String source)
        Sets the source of the current value of this Setting. Maybe a string like "internal" or the location of the properties file
        Parameters:
        source - the source of the value
      • setValue

        public void setValue​(T value)
        Note that setting the value is not enforced - it is the caller's responsibility to check if a value is locked or not before setting a new value
        Parameters:
        value - the new value
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object