Class LegacyModeDuplicatesDetector
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.module.context.unique.LegacyModeDuplicatesDetector
-
- All Implemented Interfaces:
DuplicateConfigDetector
public class LegacyModeDuplicatesDetector extends java.lang.Object implements DuplicateConfigDetector
Duplicates detector, implementing legacy guicey behaviour: only one instance of class is allowed. It could be used during migrations from previous guicey versions (when new behaviour is not profitable because too much of current logic assumes duplicates eviction).See also
GuiceBundle.Builder.uniqueItems(Class[])
if only few types actually require deduplication (less restrictive option).- Since:
- 03.07.2019
-
-
Constructor Summary
Constructors Constructor Description LegacyModeDuplicatesDetector()
-
Method Summary
All Methods Instance Methods Concrete 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
public java.lang.Object getDuplicateItem(java.util.List<java.lang.Object> registered, java.lang.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 interfaceDuplicateConfigDetector
- Parameters:
registered
- already registered itemsnewItem
- new item to check- Returns:
- duplicate object from already registered (to mark this one as duplicate to already registered)
-
-