Class BeanInstanceMap

Object
BeanInstanceMap

public class BeanInstanceMap extends Object
Maps a AnchorBean family-type to a bean that belongs to the family.

A family-type is always expresses as a class object for the most-abstract (i.e. highest level parent) of all classes in the family.

Author:
Owen Feehan
  • Constructor Details

    • BeanInstanceMap

      public BeanInstanceMap()
  • Method Details

    • containsFamily

      public boolean containsFamily(Class<?> familyType)
      Is a particular family-type contained in the map?
      Parameters:
      familyType - the class that defines the family
      Returns:
      true if the family type already exists in the map.
    • getInstanceFor

      public <T> Optional<T> getInstanceFor(Class<? extends T> familyType)
      Gets an instance from the map for a particular family-type.
      Type Parameters:
      T - the family-type.
      Parameters:
      familyType - the class that defines the family.
      Returns:
      an instance from the map if exists.
    • putInstanceFor

      public <T> T putInstanceFor(Class<? extends T> familyType, T instance)
      Assigns an instance to a particular family-type.
      Type Parameters:
      T - the family-type
      Parameters:
      familyType - the class that defines the family.
      instance - an instance to add.
      Returns:
      instance.
    • removeInstanceFor

      public <T> void removeInstanceFor(Class<? extends T> familyType)
      Removes any instance in the map of a particular family-type.

      If no instance exists, the method does notnhing.

      Type Parameters:
      T - the family-type
      Parameters:
      familyType - the class that defines the family.
    • addFrom

      public void addFrom(BeanInstanceMap other)
      Populates the entries from another BeanInstanceMap

      It is a "shallow-copy". No duplication of values occurs. So after the function is completed, any object references from other will also exist in this map.

      Any existing map-entries are retained.

      Parameters:
      other - provides entries that are added to the current map
    • addFrom

      public void addFrom(List<? extends NameValue<?>> listNamedInstances) throws BeanMisconfiguredException
      Populates from a list of NamedBean.

      Any existing map-entries are retained.

      Parameters:
      listNamedInstances - list of NamedBean. The name of each bean maps to the class in the map.
      Throws:
      BeanMisconfiguredException - if the list of NamedBean contains an invalid class.