Class NaturalAssociator

  • All Implemented Interfaces:
    Associator
    Direct Known Subclasses:
    DefaultKeyAssociator

    public class NaturalAssociator
    extends Object
    implements Associator
    NaturalAssociator provides an Associator implementation for objects that implement the Associated interface.
    Author:
    gg 2012.03.11
    • Constructor Detail

      • NaturalAssociator

        public NaturalAssociator()
    • Method Detail

      • getAssociatedKey

        public Object getAssociatedKey​(Object o)
        Determine the host key (or base) object to which the specified object is associated.

        Note: It's expected that the returned object is suitable to be used as an immutable identity (e.g. a key in a Map).
        Note 2: Circular associations are not permitted.

        Specified by:
        getAssociatedKey in interface Associator
        Parameters:
        o - the object to obtain an association for
        Returns:
        the host key that for this object, or null if this object has no association
      • validateAssociated

        protected Object validateAssociated​(Associated assoc)
        Check if given Associated object generates a circular association.
        Parameters:
        assoc - an Associated object to check
        Returns:
        the key object that is associated with the specified object, or null if there is no association
        Throws:
        RuntimeException - if there is a circular key association chain, or if the maximum association depth has been reached