Class MapBean

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,​java.lang.Object>, Bean, DynamicBean

    public class MapBean
    extends java.util.HashMap<java.lang.String,​java.lang.Object>
    implements DynamicBean
    Implementation of a fully dynamic Bean based on an exposed Map.

    Properties are dynamic, and can be added and removed at will from the map.

    This class extends HashMap, allowing it to be used wherever a map is. See FlexiBean for a map-like bean implementation that is more controlled.

    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Constructor Summary

      Constructors 
      Constructor Description
      MapBean()
      Creates an instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      MapBean clone()  
      static DynamicMetaBean meta()
      Creates a standalone meta-bean.
      DynamicMetaBean metaBean()
      Gets the meta-bean representing the parts of the bean that are common across all instances, such as the set of meta-properties.
      Property<java.lang.Object> property​(java.lang.String name)
      Gets a property by name.
      void propertyDefine​(java.lang.String propertyName, java.lang.Class<?> propertyType)
      Adds a property to those allowed to be stored in the bean.
      java.util.Set<java.lang.String> propertyNames()
      Gets the set of property names.
      void propertyRemove​(java.lang.String propertyName)
      Removes a property by name.
      java.lang.String toString()
      Returns a string that summarises the bean.
      • Methods inherited from class java.util.HashMap

        clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
      • Methods inherited from class java.util.AbstractMap

        equals, hashCode
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        equals, hashCode
    • Constructor Detail

      • MapBean

        public MapBean()
        Creates an instance.
    • Method Detail

      • meta

        public static DynamicMetaBean meta()
        Creates a standalone meta-bean.

        This creates a new instance each time in line with dynamic bean principles.

        Returns:
        the meta-bean, not null
      • metaBean

        public DynamicMetaBean metaBean()
        Description copied from interface: DynamicBean
        Gets the meta-bean representing the parts of the bean that are common across all instances, such as the set of meta-properties.
        Specified by:
        metaBean in interface Bean
        Specified by:
        metaBean in interface DynamicBean
        Returns:
        the meta-bean, not null
      • property

        public Property<java.lang.Object> property​(java.lang.String name)
        Description copied from interface: DynamicBean
        Gets a property by name.

        This will not throw an exception if the property name does not exist. Whether a property is immediately created or not is implementation dependent.

        Specified by:
        property in interface Bean
        Specified by:
        property in interface DynamicBean
        Parameters:
        name - the property name to retrieve, not null
        Returns:
        the property, not null
      • propertyNames

        public java.util.Set<java.lang.String> propertyNames()
        Description copied from interface: Bean
        Gets the set of property names.

        Each bean consists of a known set of properties. This method returns the known property names.

        Specified by:
        propertyNames in interface Bean
        Returns:
        the unmodifiable set of property names, not null
      • propertyDefine

        public void propertyDefine​(java.lang.String propertyName,
                                   java.lang.Class<?> propertyType)
        Description copied from interface: DynamicBean
        Adds a property to those allowed to be stored in the bean.

        Some implementations will automatically add properties, in which case this method will have no effect.

        Specified by:
        propertyDefine in interface DynamicBean
        Parameters:
        propertyName - the property name to check, not empty, not null
        propertyType - the property type, not null
      • propertyRemove

        public void propertyRemove​(java.lang.String propertyName)
        Description copied from interface: DynamicBean
        Removes a property by name.
        Specified by:
        propertyRemove in interface DynamicBean
        Parameters:
        propertyName - the property name to remove, null ignored
      • clone

        public MapBean clone()
        Overrides:
        clone in class java.util.HashMap<java.lang.String,​java.lang.Object>
      • toString

        public java.lang.String toString()
        Returns a string that summarises the bean.

        The string contains the class name and properties.

        Overrides:
        toString in class java.util.AbstractMap<java.lang.String,​java.lang.Object>
        Returns:
        a summary string, not null