Class Keys
- java.lang.Object
-
- org.eclipse.aether.Keys
-
public final class Keys extends java.lang.Object
A helper class to create keys, to be used withSessionDataandRepositoryCacheinstances as keys. Resolver codebase started withStringkeys, that are generally perfect for keys in these constructs, as long as they are used by components loaded once in system. As we saw, some subsystems like transports can be loaded multiple times. For example, in case of Maven, some transport may be present in Maven core, but also loaded up by some extension. In this case, key should distinguish between theirClassLoaders.It is this class caller responsibility to use proper objects as keys, this class merely helps one to create composite keys out of object instances that are expected to be anyway good candidates as key. Examples of these objects are
Stringinstances but alsoClassinstances, and many other types also usable as keys.Important: never forget to perform
null-check, when getting cache fromRepositorySystemSession.getCache()method as it may returnnull, when cache is disabled session-wise.Historical note: As mentioned above, use of
Stringinstances for keys is perfect match, and it worked from very start. But, as use cases got more and more complex and keys used started to be constructed in more and more sophisticated ways, but were stillStringinstances. Believe, or not, the sole purpose of string keys was easier debugging. By using this helper class, this convenience should remain.- Since:
- 2.0.19
- See Also:
RepositorySystemSession.getData(),SessionData,RepositorySystemSession.getCache(),RepositoryCache
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Objectof(java.lang.Object... keys)Creates object instance usable as key in session data and cache.
-
-
-
Method Detail
-
of
public static java.lang.Object of(java.lang.Object... keys)
Creates object instance usable as key in session data and cache. Objects passed to this method may or may not implement equals/hashCode, but it is responsibility of caller to understand what is she or he doing.If the first element of key elements is an object instance that was created by this method, creation of "subkeys" happens, where original key elements expanded from first element and are concatenated with new ones. This expansion happens only, if the first key element was already a key created by this class. If the arguments contain only one argument, and it is an object instance that was created by this method, the passed in instance is returned unmodified.
Based on what kind of elements are used, one can create multiple kind of keys:
- To create globally matched keys, preferred is to use
Stringkey elements - To create ClassLoader wide matched keys, make sure at least one key element is
Classthat needs to be scoped to ClassLoader - To create private, matched by creator only keys, make sure to have one key element, that requires instance equality matching, and there is no other same instance of element
- Parameters:
keys- The key elements, it may not benulland may not have zero elements.- Returns:
- An object instance usable as key.
- To create globally matched keys, preferred is to use
-
-