Interface DuplicateConfigDetector

  • All Known Implementing Classes:
    LegacyModeDuplicatesDetector, UniqueItemsDuplicatesDetector

    public interface DuplicateConfigDetector
    Configuration items may be registered by class (extension, installer) or by instance (guicey bundle, guice module). Duplicates are obvious for class registrations: one class - one extension instance (no matter how much times this class was registered). But for instances it's not so obvious. For example, in dropwizard you can register multiple instances of the same bundle (and it's often very useful!). But, sometimes, there are common bundles (or guice modules), used by multiple other bundles (and so declared by all of them). In this case it would be desirable to register common bundle just once (and avoid duplicate).

    Default deduplication logic for instances will consider equal objects as duplicate. In cases, when it is impossible to properly implement equals method (e.g. 3rd party class), custom deduplication detector could be implemented.

    Since:
    03.07.2019
    See Also:
    with legacy guicey behaviour implementation (always one instance per class)
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.lang.Object getDuplicateItem​(java.util.List<java.lang.Object> registered, java.lang.Object newItem)
      Called every time when configured object (guicey bundle or guice module) of the same type is already registered.
    • Method Detail

      • getDuplicateItem

        java.lang.Object getDuplicateItem​(java.util.List<java.lang.Object> registered,
                                          java.lang.Object newItem)
        Called every time when configured object (guicey bundle or guice module) of the same type is already registered. Note that method is called only if new instance is not equal to any registered instances of the same type. Method must return duplicate object from already registered instances (or null to allow new registration).

        For example, if 3 or more instances of the same type are registered then method would be called for each new configured instance (in case of 3 registrations - 2 method calls, assuming that instances are not equal).

        Provided instances will always be of the same class (no polymorphic checks). Classes loaded from different class loaders will be recognized as same class (and so provided instances may be instances of the same class but from different class loaders).

        Parameters:
        registered - already registered items
        newItem - new item to check
        Returns:
        duplicate object from already registered (to mark this one as duplicate to already registered)