/** * Sets a default value that can be used for any parameter of type {@code type}. Returns this * object. */ public <T> NullPointerTester setDefault(Class<T> type, T value) { defaults.putInstance(type, checkNotNull(value)); return this; }
static <T extends Completable> T getInstance(Class<T> type, Supplier<T> supplier) { ClassToInstanceMap<Completable> components = state().components; @Nullable T instance = components.getInstance(type); if (instance == null) { instance = supplier.get(); components.putInstance(type, instance); } return instance; }
public void testPutAndGetInstance() { assertNull(map.putInstance(Integer.class, new Integer(5))); Integer oldValue = map.putInstance(Integer.class, new Integer(7)); assertEquals(5, (int) oldValue); Integer newValue = map.getInstance(Integer.class); assertEquals(7, (int) newValue); // Won't compile: map.putInstance(Double.class, new Long(42)); }
public void testPrimitiveAndWrapper() { assertNull(map.getInstance(int.class)); assertNull(map.getInstance(Integer.class)); assertNull(map.putInstance(int.class, 0)); assertNull(map.putInstance(Integer.class, 1)); assertEquals(2, map.size()); assertEquals(0, (int) map.getInstance(int.class)); assertEquals(1, (int) map.getInstance(Integer.class)); assertEquals(0, (int) map.putInstance(int.class, null)); assertEquals(1, (int) map.putInstance(Integer.class, null)); assertNull(map.getInstance(int.class)); assertNull(map.getInstance(Integer.class)); assertEquals(2, map.size()); } }
public void testNull() { try { map.put(null, new Integer(1)); fail(); } catch (NullPointerException expected) { } map.putInstance(Integer.class, null); assertNull(map.get(Integer.class)); assertNull(map.getInstance(Integer.class)); map.put(Long.class, null); assertNull(map.get(Long.class)); assertNull(map.getInstance(Long.class)); }
@Override public <T extends IAEStack<T>, C extends IStorageChannel<T>> void registerStorageChannel( Class<C> channel, C factory ) { Preconditions.checkNotNull( channel ); Preconditions.checkNotNull( factory ); Preconditions.checkArgument( channel.isInstance( factory ) ); Preconditions.checkArgument( !this.channels.containsKey( channel ) ); this.channels.putInstance( channel, factory ); }
@Override public <T extends DOMService> DOMMountPointBuilder addService(final Class<T> type, final T impl) { services.putInstance(type, impl); return this; }
@Override public <T> void setInstance(Class<T> type, T instance) { instances.putInstance(type, instance); }
/** * Sets a default value that can be used for any parameter of type {@code type}. Returns this * object. */ public <T> NullPointerTester setDefault(Class<T> type, T value) { defaults.putInstance(type, checkNotNull(value)); return this; }
/** * Sets a default value that can be used for any parameter of type * {@code type}. Returns this object. */ public <T> NullPointerTester setDefault(Class<T> type, T value) { defaults.putInstance(type, checkNotNull(value)); return this; }
/** * Adds a minion to the squad. * @param minion minion who should join the squad */ public <M extends Minion> void add(M minion) { minions.put(minion.getClass(), minion); Class sc = minion.getClass().getSuperclass(); while (sc != null && !Modifier.isAbstract(sc.getModifiers()) && !sc.equals(Minion.class) ) { minions.putInstance(sc, minion); sc = sc.getSuperclass(); } sorted.add(minion); }
public synchronized <T> void put(@Nullable String name, Class<T> aClass, T value) { ClassToInstanceMap<Object> instanceMap = nameMap.get(ofNullable(name)); if (instanceMap == null) { instanceMap = MutableClassToInstanceMap.create(); nameMap.put(ofNullable(name), instanceMap); } if (instanceMap.putInstance(aClass, value) != null) { String message = "Duplicate ReportCollection for " + aClass.toString(); if (name != null) { message += " named " + name; } throw new Error(message); } }
@Override public <T extends CoprocessorProtocol> boolean registerProtocol( Class<T> protocol, T handler) { /* No stacking of protocol handlers is currently allowed. The * first to claim wins! */ if (protocolHandlers.containsKey(protocol)) { LOG.error("Protocol "+protocol.getName()+ " already registered, rejecting request from "+ handler ); return false; } protocolHandlers.putInstance(protocol, handler); protocolHandlerNames.put(protocol.getName(), protocol); if (LOG.isDebugEnabled()) { LOG.debug("Registered master protocol handler: protocol="+protocol.getName()); } return true; }
public <T> NullPointerTester setDefault(final Class<T> type, final T value) { defaults.putInstance(type, checkNotNull(value)); return this; }
public ClassToInstanceMap<RpcService> getDrivers(String deviceType) { Preconditions.checkNotNull(deviceType); Preconditions.checkArgument(deviceType.equals(OVS_DEVICE_TYPE), "Only the '{}' device type is supported!", OVS_DEVICE_TYPE); ClassToInstanceMap<RpcService> drivers = MutableClassToInstanceMap.create(); drivers.putInstance(OpenflowFeatureService.class, new OpenFlowDeviceDriver()); // obtain the flow and group service. SalFlowService salFlowService = rpcRegistry.getRpcService(SalFlowService.class); SalGroupService salGroupService = rpcRegistry.getRpcService(SalGroupService.class); drivers.putInstance(AtriumFlowObjectiveService.class, new AtriumFlowObjectiveDriver(salFlowService, salGroupService)); return drivers; }
protocolHandlers.putInstance(protocol, handler); protocolHandlerNames.put(protocol.getName(), protocol); if (LOG.isDebugEnabled()) {
@Override public <T extends BrokerService> T getService(final Class<T> service) { checkNotClosed(); final T localProxy = instantiatedServices.getInstance(service); if (localProxy != null) { return localProxy; } final Optional<T> serviceImpl = broker.getGlobalService(service); if(serviceImpl.isPresent()) { final T ret = ProxyFactory.createProxy(null,serviceImpl.get()); instantiatedServices.putInstance(service, ret); return ret; } else { return null; } }
public void testPutAndGetInstance() { assertNull(map.putInstance(Integer.class, new Integer(5))); Integer oldValue = map.putInstance(Integer.class, new Integer(7)); assertEquals(5, (int) oldValue); Integer newValue = map.getInstance(Integer.class); assertEquals(7, (int) newValue); // Won't compile: map.putInstance(Double.class, new Long(42)); }
public void testPrimitiveAndWrapper() { assertNull(map.getInstance(int.class)); assertNull(map.getInstance(Integer.class)); assertNull(map.putInstance(int.class, 0)); assertNull(map.putInstance(Integer.class, 1)); assertEquals(2, map.size()); assertEquals(0, (int) map.getInstance(int.class)); assertEquals(1, (int) map.getInstance(Integer.class)); assertEquals(0, (int) map.putInstance(int.class, null)); assertEquals(1, (int) map.putInstance(Integer.class, null)); assertNull(map.getInstance(int.class)); assertNull(map.getInstance(Integer.class)); assertEquals(2, map.size()); } }
public void testNull() { try { map.put(null, new Integer(1)); fail(); } catch (NullPointerException expected) { } map.putInstance(Integer.class, null); assertNull(map.get(Integer.class)); assertNull(map.getInstance(Integer.class)); map.put(Long.class, null); assertNull(map.get(Long.class)); assertNull(map.getInstance(Long.class)); }