/** * Get the value assigned to the specific key. * * @param key the key * @return the value assigned to the key, this value is newly created upon the first request */ @Nonnull public V get(@Nonnull final K key) { V value = storage.get(key); if (value == null) { value = valueFactory.createNew(); storage.put(key, value); } return value; } }
/** * Fetch a new or unused instance of the pool object. * * @return a pool object instance */ @Nonnull public T allocate() { while (!pool.isEmpty()) { @Nullable T obj = pool.removeLast().get(); if (obj != null) { return obj; } } return factory.createNew(); }
/** * Creates a Controller given a fully qualified class name. If a factory is * registered to a controller class type, it will be responsible to create the * new instance of the controller. Otherwise, we try to instantiate the * controller using an empty constructor. * * @param controllerClassName a fully qualified controller class name. * @return a new Controller, or null if not able to create one. */ @Nullable public Controller create(@Nullable final String controllerClassName) { if (controllerClassName == null) { return null; } if (registeredControllersFactories.containsKey(controllerClassName)) { return registeredControllersFactories.get(controllerClassName).createNew(); } else { return ClassHelper.getInstance(controllerClassName, Controller.class); } }