Minor refactoring.

Replaced use of reflection with use of functional factory interface (API change).
This commit is contained in:
Sebastian Hartte
2020-06-30 18:57:26 +02:00
parent d17f8cec92
commit 8d8d3dd2d7
6 changed files with 89 additions and 44 deletions
@@ -0,0 +1,43 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 AlgorithmX2
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package appeng.api.networking;
import javax.annotation.Nonnull;
/**
* A factory for grid cache implementations.
*/
@FunctionalInterface
public interface IGridCacheFactory<T extends IGridCache> {
/**
* Creates a grid cache for the given grid.
*
* @param grid The grid for which the cache should be created.
* @return A new grid cache instance.
*/
@Nonnull
T createCache(IGrid grid);
}
@@ -36,10 +36,10 @@ public interface IGridCacheRegistry {
* Register a new grid cache for use during operation, must be called during the
* loading phase.
*
* @param iface grid cache class
* @param iface grid cache class
* @param factory Factory for creating a new instance for each constructed grid
*/
void registerGridCache(@Nonnull Class<? extends IGridCache> iface,
@Nonnull Class<? extends IGridCache> implementation);
<T extends IGridCache> void registerGridCache(@Nonnull Class<T> iface, @Nonnull IGridCacheFactory<T> factory);
/**
* requests a new INSTANCE of a grid cache for use, used internally