T - class typepublic final class ItemId<T>
extends java.lang.Object
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:
ItemId.from(instance)listOfIds.contains(ItemId.from(MyModule.class))
will be true if instance id is contained in collection.| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(java.lang.Object o) |
static <T> ItemId<T> |
from(java.lang.Class<?> type)
Construct type key for class only.
|
static <T> ItemId<T> |
from(java.lang.Object instance)
Construct type key for instance of class.
|
java.lang.String |
getIdentity() |
java.lang.Class<T> |
getType() |
int |
hashCode() |
static java.lang.String |
identity(java.lang.Object instance)
Creates object instance identity string.
|
java.lang.String |
toString() |
static <T> java.util.List<java.lang.Class<T>> |
typesOnly(java.util.Collection<ItemId<T>> items)
Utility method to project collections of item ids into classes.
|
public java.lang.Class<T> getType()
public java.lang.String getIdentity()
public java.lang.String toString()
toString in class java.lang.Objectpublic static java.lang.String identity(java.lang.Object instance)
Object.toString().instance - object instancepublic static <T> ItemId<T> from(java.lang.Object instance)
from(Class) call.T - class typeinstance - instance of object representing type (bundle, modules) or classpublic static <T> ItemId<T> from(java.lang.Class<?> type)
T - class typetype - type classpublic static <T> java.util.List<java.lang.Class<T>> typesOnly(java.util.Collection<ItemId<T>> items)
T - target items class type (when possible to declare)items - item idspublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object