Added javadoc description for name property. Cleaned up code in ContextBuilder

This commit is contained in:
Ioannis Canellos 2012-10-06 10:30:27 +03:00
parent 76beeee55b
commit 0dcd648599
2 changed files with 5 additions and 4 deletions

View File

@ -47,7 +47,9 @@ import com.google.inject.ImplementedBy;
public interface Context extends Location, Closeable { public interface Context extends Location, Closeable {
/** /**
* Identifies the Context. * Identifies the Context. This is a unique name optionally specified by the user and safe to index on.
* The purpose of this property is to provide means to distinct between multiple contexts, without having to check
* multiple properties or have explicit knowledge of how the context was created.
* @return * @return
*/ */
String getName(); String getName();

View File

@ -259,9 +259,8 @@ public class ContextBuilder {
ProviderMetadata providerMetadata = new UpdateProviderMetadataFromProperties(apiMetadata, this.providerMetadata).apply(expanded); ProviderMetadata providerMetadata = new UpdateProviderMetadataFromProperties(apiMetadata, this.providerMetadata).apply(expanded);
//We use either the specified name (optional) or a hash of provider/api, endpoint, api version & identity. Hash is used to be something readable. //We use either the specified name (optional) or a hash of provider/api, endpoint, api version & identity. Hash is used to be something readable.
String name = this.name.isPresent() ? this.name.get() : String.valueOf(Objects.hashCode(providerMetadata.getId(), providerMetadata.getEndpoint() , apiVersion , identity.get())); return buildInjector(name.or(String.valueOf(Objects.hashCode(providerMetadata.getId(),
providerMetadata.getEndpoint() , apiVersion , identity.get()))), providerMetadata, creds, modules);
return buildInjector(name, providerMetadata, creds, modules);
} }
private static String getAndRemove(Properties expanded, String key) { private static String getAndRemove(Properties expanded, String key) {