2626
2727package io .spine .server ;
2828
29+ import com .google .common .annotations .VisibleForTesting ;
30+ import com .google .errorprone .annotations .CanIgnoreReturnValue ;
2931import io .spine .environment .Environment ;
3032import io .spine .environment .EnvironmentType ;
3133import org .checkerframework .checker .nullness .qual .MonotonicNonNull ;
4749 * <p>For example:
4850 * <pre>{@code
4951 * EnvSetting<StorageFactory> storageFactory = new EnvSetting<>();
50- * storageFactory.use(InMemoryStorageFactory.newInstance(), Production.class);
51- * storageFactory .use(new MemoizingStorageFactory(), Tests.class);
52+ * storageFactory.use(InMemoryStorageFactory.newInstance(), Production.class)
53+ * .use(new MemoizingStorageFactory(), Tests.class);
5254 *
5355 * // Provides the `StorageFactory` for the current environment of the application.
5456 * StorageFactory currentStorageFactory = storageFactory.value();
@@ -196,6 +198,7 @@ public V value() {
196198 * <p>The environment type is retrieved from {@code Supplier} under the read lock
197199 * for the possibility of controlling this lock.
198200 */
201+ @ VisibleForTesting
199202 Optional <V > valueFor (Supplier <Class <? extends EnvironmentType >> type ) {
200203 Value <V > value = lockReadOperation (() -> {
201204 Class <? extends EnvironmentType > envType = type .get ();
@@ -227,12 +230,14 @@ public void reset() {
227230 * @param type
228231 * the type of the environment
229232 */
230- public void use (V value , Class <? extends EnvironmentType > type ) {
233+ @ CanIgnoreReturnValue
234+ public EnvSetting <V > use (V value , Class <? extends EnvironmentType > type ) {
231235 checkNotNull (value );
232236 checkNotNull (type );
233237 lockWriteOperation (() -> {
234238 this .environmentValues .put (type , new Value <>(value ));
235239 });
240+ return this ;
236241 }
237242
238243 /**
@@ -242,13 +247,16 @@ public void use(V value, Class<? extends EnvironmentType> type) {
242247 * <p>The value to set is initialized under the write lock
243248 * for the possibility of controlling this lock.
244249 */
245- void useViaInit (Supplier <V > initializer , Class <? extends EnvironmentType > type ) {
250+ @ CanIgnoreReturnValue
251+ @ VisibleForTesting
252+ EnvSetting <V > useViaInit (Supplier <V > initializer , Class <? extends EnvironmentType > type ) {
246253 checkNotNull (type );
247254 lockWriteOperation (() -> {
248255 V value = initializer .get ();
249256 checkNotNull (value );
250257 this .environmentValues .put (type , new Value <>(value ));
251258 });
259+ return this ;
252260 }
253261
254262 /**
@@ -263,12 +271,14 @@ void useViaInit(Supplier<V> initializer, Class<? extends EnvironmentType> type)
263271 * @param type
264272 * the type of the environment
265273 */
266- public void lazyUse (Supplier <V > value , Class <? extends EnvironmentType > type ) {
274+ @ CanIgnoreReturnValue
275+ public EnvSetting <V > lazyUse (Supplier <V > value , Class <? extends EnvironmentType > type ) {
267276 checkNotNull (value );
268277 checkNotNull (type );
269278 lockWriteOperation (() -> {
270279 this .environmentValues .put (type , new Value <>(value ));
271280 });
281+ return this ;
272282 }
273283
274284 private Optional <V > valueFor (Class <? extends EnvironmentType > type ) {
0 commit comments