Class BeanMapEntry

java.lang.Object
org.apache.juneau.commons.bean.BeanMapEntry
All Implemented Interfaces:
Map.Entry<String,Object>

public class BeanMapEntry extends Object implements Map.Entry<String,Object>
Represents a single entry in a bean map.

This class can be used to get and set property values on a bean, or to get metadata on a property.

Example:

// Construct a new bean Person person = new Person(); // Wrap it in a bean map BeanMap<Person> beanMap = BeanMap.of(person); // Get a reference to the birthDate property BeanMapEntry birthDate = beanMap.getProperty("birthDate"); // Set the property value birthDate.setValue(new Date(1, 2, 3, 4, 5, 6)); // Or if the DateSwap.DEFAULT_ISO8601DT is registered with the bean context, set a transformed value birthDate.setValue("'1901-03-03T04:05:06-5000'");

Thread safety
This is a lightweight immutable view over a BeanMap. Its thread-safety characteristics are the same as the backing BeanMap.
  • Constructor Details

    • BeanMapEntry

      protected BeanMapEntry(BeanMap<?> beanMap, BeanPropertyMeta property, String pName)
      Constructor.
      Parameters:
      beanMap - The bean map that this entry belongs to.
      property - The bean property.
      pName - The bean property name.
  • Method Details

    • getBeanMap

      public BeanMap<?> getBeanMap()
      Returns the bean map that contains this property.
      Returns:
      The bean map that contains this property.
    • getKey

      public String getKey()
      Specified by:
      getKey in interface Map.Entry<String,Object>
    • getMeta

      Returns the metadata about this bean property.
      Returns:
      Metadata about this bean property.
    • getValue

      public Object getValue()
      Returns the value of this property.

      If there is a ObjectSwap associated with this bean property or bean property type class, then this method will return the transformed value. For example, if the bean property type class is a Date and the bean property has the DateFormat.ISO_INSTANT setting associated with it through the @Swap(value) annotation, this method will return a String containing an ISO8601 date-time string value.

      Specified by:
      getValue in interface Map.Entry<String,Object>
    • setValue

      public Object setValue(Object value)
      Sets the value of this property.

      If the property is an array of type X, then the value can be a Collection<X> or X[] or Object[].

      If the property is a bean type X, then the value can either be an X or a Map.

      If there is a ObjectSwap associated with this bean property or bean property type class, then you must pass in a transformed value. For example, if the bean property type class is a Date and the bean property has the DateFormat.ISO_INSTANT setting associated with it through the @Swap(value) annotation, the value being passed in must be a String containing an ISO8601 date-time string value.

      Specified by:
      setValue in interface Map.Entry<String,Object>
      Parameters:
      value - The new value for this property. Can be null to set the property to null.
      Returns:
      The set value after it's been converted.
    • equals

      public boolean equals(Object obj)
      Returns true if the given object is a Map.Entry with equal key and value.

      This follows the Map.Entry equality contract: two entries are equal if both their keys and values compare equal via Objects.equals(java.lang.Object, java.lang.Object).

      Specified by:
      equals in interface Map.Entry<String,Object>
      Overrides:
      equals in class Object
      Parameters:
      obj - The object to compare against.
      Returns:
      true if equal.
    • hashCode

      public int hashCode()
      Returns the hash code for this entry, consistent with the Map.Entry contract.

      The hash code is computed as key.hashCode() ^ value.hashCode(), matching the contract that equal entries must have equal hash codes.

      Specified by:
      hashCode in interface Map.Entry<String,Object>
      Overrides:
      hashCode in class Object
      Returns:
      The hash code.
    • toString

      public String toString()
      Overrides:
      toString in class Object