Class ItemId<T>
java.lang.Object
ru.vyarus.dropwizard.guice.module.context.info.ItemId<T>
- Type Parameters:
T- class type
As multiple instances of the same type may be used during configuration (e.g. bundle or module) then it's not
enough to declare just class in order to identify type.
Identity string is generated using object hash code (the same way as used in default Object.toString().
It is assumed that no one would override bundle hash code (who would be?) and toString so using the same
hash as in default toString would be ideal for instance identification (at least instance could be easily
associated in debugger).
Type has special equals behaviour: id, created from class only is equal to any instance identity (containing instance identifier). This simplifies searches by class only. In order to make this work, hash code for itemId is the same for all ids of the same type.
Reminder:
- Identity object could always be prepared from instance:
ItemId.from(instance) - Class item could be used to detect instanes: e.g.
listOfIds.contains(ItemId.from(MyModule.class))will be true if instance id is contained in collection.
- Since:
- 05.07.2019
-
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic <T> ItemId<T>Construct type key for class only.static <T> ItemId<T>Construct type key for instance of class.getType()inthashCode()static StringCreates object instance identity string.toString()typesOnly(Collection<ItemId<T>> items) Utility method to project collections of item ids into classes.
-
Method Details
-
getType
- Returns:
- type
-
getIdentity
- Returns:
- object instance hash or null
-
toString
-
identity
Creates object instance identity string. Returned code is the same as number part after "@" in defaultObject.toString().- Parameters:
instance- object instance- Returns:
- identity string (hash)
-
from
Construct type key for instance of class. When called with class instance it's equivalent tofrom(Class)call.- Type Parameters:
T- class type- Parameters:
instance- instance of object representing type (bundle, modules) or class- Returns:
- type key
-
from
Construct type key for class only. Useful when only one instance of type class is used.- Type Parameters:
T- class type- Parameters:
type- type class- Returns:
- type key
-
typesOnly
Utility method to project collections of item ids into classes. If list contains multiple instance ids of the same type then resulted list will contain only one type (and so resulted list will be shorter).- Type Parameters:
T- target items class type (when possible to declare)- Parameters:
items- item ids- Returns:
- list of classes from provided ids
-
equals
-
hashCode
public int hashCode()
-