Class ObservableProperties.Key<T>

  • Type Parameters:
    T - the type of value this key should map to.
    All Implemented Interfaces:
    Serializable, Comparable<ObservableProperties.Key<?>>
    Enclosing class:
    ObservableProperties


    public static class ObservableProperties.Key<T>
    extends Object
    implements Serializable, Comparable<ObservableProperties.Key<?>>
    A key for a key/value pair. The reason keys are not simply Strings is that these objects have a parameterized type: so casting is not necessary.

    You can technically have two keys with the same name and different types in the same property set.

    It is recommended (but not necessary) that keys be stored as public static fields.

    See Also:
    Serialized Form
    • Constructor Detail

      • Key

        public Key(String keyName,
                   Class<T> type)
        Create a new Key.
        Parameters:
        keyName - the name of this key.
        type - the parameterized type of this key. (Is there a way to ascertain this by reflection? Stating this here seems redundant, but necessary.)
      • Key

        public Key(String keyName,
                   Class<T> type,
                   ObservableProperties.BoundsChecker checker)
        Create a new Key.
        Parameters:
        keyName - the name of this key.
        type - the parameterized type of this key. (Is there a way to ascertain this by reflection? Stating this here seems redundant, but necessary.)
        checker - an optional ObservableProperties.BoundsChecker to throw an exception if someone attempts to assign a value that isn't allowed.
      • Key

        public Key(String keyName,
                   Class<T> type,
                   Number min,
                   Number max,
                   boolean includeMin,
                   boolean includeMax)
        Create a new Key with a numeric ObservableProperties.BoundsChecker.
        Parameters:
        keyName - the name of this key.
        type - the parameterized type of this key. (Is there a way to ascertain this by reflection? Stating this here seems redundant, but necessary.)
        min - the minimum accepted value.
        max - the maximum accepted value.
        includeMin - if true then this applies a "greater than or equal to" check. If false then this simply applies a "greater than" check, so if someone tries to use a value that is exactly equal to the minimum: it will fail.
        includeMax - if true then this applies a "less than or equal to" check. If false then this simply applies a "less than" check, so if someone tries to use a value that is exactly equal to the maximum: it will fail.
    • Method Detail

      • getType

        public Class<T> getType()
        Returns:
        the class of the object this key requires.
      • get

        public T get(Map<String,Object> map,
                     T defaultValue)
        Retrieve this key from a map of values or return the default value provided if the key is not identified.

        Note the key name in the map does not have to be exact. For example if the map was generated via ObservableProperties.getMap(boolean, boolean, String...) then in might have text prepended or appended to the technical key name. As soon as a partial match is identified that matches this key name (that also is consistent with the type required by this Key): then that value is returned. For this reason: key names should err on the side of being more specific/thorough than not.

        Parameters:
        map - the map to check against.
        defaultValue - the optional default value if the map doesn't contain the key.
        Returns:
        the value of the key provided, or the default value if no value is identified.
      • matches

        public boolean matches(PropertyChangeEvent evt)
        Parameters:
        evt - the evt to check against.
        Returns:
        true if a PropertyChangeEvent relates to this Key.
      • hashCode

        public int hashCode()
      • equals

        public boolean equals(Object t)
      • getKeyName

        public String getKeyName()
        Returns the original key name associated with this key.
        Returns:
        the original key name associated with this key.
      • toString

        public String toString()
        The key name property.