# Class PropertyBase<T,K>

java.lang.Object
com.codename1.properties.PropertyBase<T,K>

Direct Known Subclasses:
  `CollectionProperty, MapProperty, Property`

public class PropertyBase<T,K> extends Object
Base class for property types

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `PropertyBase(String name)`
  All properties must have a name
  `protected`
  `PropertyBase(String name, Class genericType)`
  All properties must have a name, a generic type is helpful

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addChangeListener(PropertyChangeListener<T,K> pl)`
  Fires a notification that a property value changed to the given listener
  `static void`
  `bindGlobalGetListener(PropertyChangeListener listener)`
  Binds an event callback for get calls and property reads
  `static void`
  `bindGlobalSetListener(PropertyChangeListener listener)`
  Binds an event callback for set calls and property mutation
  `boolean`
  `equals(Object obj)`
  Compares this property to another property
  `protected void`
  `firePropertyChanged()`
  Delivers the property change event to listeners if applicable
  `Object`
  `getClientProperty(String key)`
  Returns the client property set to this property name
  `Class`
  `getGenericType()`
  Returns the generic type of this property if it is known or null
  `String`
  `getLabel()`
  The label of the property defaults to its name but can be changed to anything
  `String`
  `getName()`
  The property name is immutable and can't be changed after creation it should match the parent field name by convention
  `int`
  `hashCode()`
  Returns a hash code value for the object.
  `void`
  `putClientProperty(String key, Object o)`
  Places a property that will apply statically to all instances of this property
  `void`
  `removeChangeListener(PropertyChangeListener<T,K> pl)`
  Removes the property change listener from the list of listeners
  `void`
  `setLabel(String label)`
  The label of the property defaults to its name but can be changed to anything, it can be used when binding a property to UI elements
  `void`
  `stopListening()`
  This method will work when invoked from a propertyChanged callback and should be similar to `removePropertyChangeListener(this)`.
  `String`
  `toString()`
  Default toString that provides easier debug information
  `protected final void`
  `validateCollectionType(Class elementType)`
  Validates that the collection type is valid and throws an exception otherwise

  ### Methods inherited from class Object

  `clone, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### PropertyBase

    protected PropertyBase(String name)

    All properties must have a name

    ###### Parameters

    - `name`: the name of the property

  - ### PropertyBase

    protected PropertyBase(String name, Class genericType)

    All properties must have a name, a generic type is helpful

    ###### Parameters

    - `name`: the name of the property

    - `genericType`: the property type to workaround issues with erasure

- ## Method Details

  - ### bindGlobalSetListener

    public static void bindGlobalSetListener(PropertyChangeListener listener)

    Binds an event callback for set calls and property mutation

    ###### Parameters

    - `listener`: will be invoked whenever any mutable property is changed

    ###### Throws

    - `RuntimeException`: if a set listener is already bound, there can be only one per application

    ###### Deprecated

    Usage of this method isn't recommended, it's designed for internal use

  - ### bindGlobalGetListener

    public static void bindGlobalGetListener(PropertyChangeListener listener)

    Binds an event callback for get calls and property reads

    ###### Parameters

    - `listener`: will be invoked whenever any property is read

    ###### Throws

    - `RuntimeException`: if a get listener is already bound, there can be only one per application

    ###### Deprecated

    Usage of this method isn't recommended, it's designed for internal use

  - ### getName

    public String getName()

    The property name is immutable and can't be changed after creation it should match the parent field name by convention

    ###### Returns

    the property name;

  - ### firePropertyChanged

    protected void firePropertyChanged()
    Delivers the property change event to listeners if applicable

  - ### stopListening

    public void stopListening()
    This method will work when invoked from a propertyChanged callback and should be similar to `removePropertyChangeListener(this)`. It's useful for lambda's where `this` means the base class and not the listener so `removePropertyChangeListener(this)` won't do what we want unless we convert to an inner class

  - ### addChangeListener

    public void addChangeListener(PropertyChangeListener<T,K> pl)

    Fires a notification that a property value changed to the given listener

    ###### Parameters

    - `pl`: the listener

  - ### removeChangeListener

    public void removeChangeListener(PropertyChangeListener<T,K> pl)

    Removes the property change listener from the list of listeners

    ###### Parameters

    - `pl`: the change listener

  - ### putClientProperty

    public void putClientProperty(String key, Object o)

    Places a property that will apply statically to all instances of this property

    ###### Parameters

    - `key`: the key to put

    - `o`: the value object

  - ### getClientProperty

    public Object getClientProperty(String key)

    Returns the client property set to this property name

    ###### Parameters

    - `key`: the key of the property

    ###### Returns

    the value that was previously placed with put client property

  - ### equals

    public boolean equals(Object obj)

    Compares this property to another property

    ###### Parameters

    - `obj`: the other property

    ###### Returns

    true if they are equal in name and value

    Overrides:
      `equals` in class `Object`

  - ### hashCode

    public int hashCode()
    Description copied from class: `Object`
    Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable. The general contract of hashCode is: Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result. It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables. As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)
    Overrides:
      `hashCode` in class `Object`

  - ### toString

    public String toString()

    Default toString that provides easier debug information

    ###### Returns

    a formatted representation of the property for debugging

    Overrides:
      `toString` in class `Object`

  - ### getGenericType

    public Class getGenericType()

    Returns the generic type of this property if it is known or null

    ###### Returns

    the generic type

  - ### getLabel

    public String getLabel()

    The label of the property defaults to its name but can be changed to anything

    ###### Returns

    the label for the property

  - ### setLabel

    public void setLabel(String label)

    The label of the property defaults to its name but can be changed to anything, it can be used when binding a property to UI elements

    ###### Parameters

    - `label`: the new label value

  - ### validateCollectionType

    protected final void validateCollectionType(Class elementType)

    Validates that the collection type is valid and throws an exception otherwise

    ###### Parameters

    - `elementType`: the generic type of the collection