Class UniqueItemsDuplicatesDetector

java.lang.Object
ru.vyarus.dropwizard.guice.module.context.unique.UniqueItemsDuplicatesDetector
All Implemented Interfaces:
DuplicateConfigDetector

public class UniqueItemsDuplicatesDetector extends Object implements DuplicateConfigDetector
Simple deduplicator implementation to track uniqueness for exact items (not everything like LegacyModeDuplicatesDetector do).
Since:
24.09.2019
  • Constructor Details

    • UniqueItemsDuplicatesDetector

      public UniqueItemsDuplicatesDetector(Class<?>... uniqueItems)
      Create detector.
      Parameters:
      uniqueItems - unique items
  • Method Details

    • getDuplicateItem

      public Object getDuplicateItem(List<Object> registered, Object newItem)
      Description copied from interface: DuplicateConfigDetector
      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).

      Specified by:
      getDuplicateItem in interface DuplicateConfigDetector
      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)