@Test(expected = IllegalStateException.class) public void duplicateRegistration() { TestProviderRegistry registry = new TestProviderRegistry(); TestProvider pFoo = new TestProvider(new ProviderId("of", "foo")); registry.register(pFoo); registry.register(pFoo); }
@Override public synchronized S register(P provider) { checkNotNull(provider, "Provider cannot be null"); checkState(!services.containsKey(provider.id()), "Provider %s already registered", provider.id()); ProviderId pid = provider.id(); checkState(pid.isAncillary() || !providersByScheme.containsKey(pid.scheme()), "A primary provider with id %s is already registered", providersByScheme.get(pid.scheme())); S service = createProviderService(provider); services.put(provider.id(), service); providers.put(provider.id(), provider); if (!pid.isAncillary()) { providersByScheme.put(pid.scheme(), provider); } return service; }
AbstractProviderRegistry implements ProviderRegistry<P, S> { @Override public synchronized S register(P provider) { checkNotNull(provider, "Provider cannot be null"); checkState(!services.containsKey(provider.id()), "Provider %s already registered", provider.id()); ProviderId pid = provider.id(); checkState(pid.isAncillary() || !providersByScheme.containsKey(pid.scheme()), "A primary provider with id %s is already registered", providersByScheme.get(pid.scheme())); S service = createProviderService(provider); services.put(provider.id(), service); providers.put(provider.id(), provider); if (!pid.isAncillary()) { providersByScheme.put(pid.scheme(), provider); } return service; } }
AbstractProviderRegistry implements ProviderRegistry<P, S> { @Override public synchronized S register(P provider) { checkNotNull(provider, "Provider cannot be null"); checkState(!services.containsKey(provider.id()), "Provider %s already registered", provider.id()); ProviderId pid = provider.id(); checkState(pid.isAncillary() || !providersByScheme.containsKey(pid.scheme()), "A primary provider with id %s is already registered", providersByScheme.get(pid.scheme())); S service = createProviderService(provider); services.put(provider.id(), service); providers.put(provider.id(), provider); if (!pid.isAncillary()) { providersByScheme.put(pid.scheme(), provider); } return service; }  }
AbstractProviderRegistry implements ProviderRegistry<P, S> { @Override public synchronized S register(P provider) { checkNotNull(provider, "Provider cannot be null"); checkState(!services.containsKey(provider.id()), "Provider %s already registered", provider.id()); ProviderId pid = provider.id(); checkState(pid.isAncillary() || !providersByScheme.containsKey(pid.scheme()), "A primary provider with id %s is already registered", providersByScheme.get(pid.scheme())); S service = createProviderService(provider); services.put(provider.id(), service); providers.put(provider.id(), provider); if (!pid.isAncillary()) { providersByScheme.put(pid.scheme(), provider); } return service; }  @Override synchronized S register(P provider); @Override synchronized void unregister(P provider); @Override synchronized Set<ProviderId> getProviders(); }
AbstractProviderRegistry implements ProviderRegistry<P, S> { @Override public synchronized S register(P provider) { checkNotNull(provider, "Provider cannot be null"); checkState(!services.containsKey(provider.id()), "Provider %s already registered", provider.id()); ProviderId pid = provider.id(); checkState(pid.isAncillary() || !providersByScheme.containsKey(pid.scheme()), "A primary provider with id %s is already registered", providersByScheme.get(pid.scheme())); S service = createProviderService(provider); services.put(provider.id(), service); providers.put(provider.id(), provider); if (!pid.isAncillary()) { providersByScheme.put(pid.scheme(), provider); } return service; }  @Override synchronized S register(P provider); @Override synchronized void unregister(P provider); @Override synchronized Set<ProviderId> getProviders();  }