🎨 @Annotation final -> final @Annotation
This commit is contained in:
parent
a6b98ca278
commit
7f013124b2
113 changed files with 844 additions and 842 deletions
|
|
@ -40,8 +40,8 @@ class AnnotatedMethodService<Context, Result> implements Service<Context, Result
|
|||
private final Method method;
|
||||
private final Object instance;
|
||||
|
||||
AnnotatedMethodService(@NonNull final Object instance,
|
||||
@NonNull final Method method)
|
||||
AnnotatedMethodService(final @NonNull Object instance,
|
||||
final @NonNull Method method)
|
||||
throws Exception {
|
||||
ExecutionOrder executionOrder = ExecutionOrder.SOON;
|
||||
try {
|
||||
|
|
@ -60,7 +60,7 @@ class AnnotatedMethodService<Context, Result> implements Service<Context, Result
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public @Nullable Result handle(@NonNull final Context context) {
|
||||
public @Nullable Result handle(final @NonNull Context context) {
|
||||
try {
|
||||
return (Result) this.methodHandle.invoke(this.instance, context);
|
||||
} catch (final Throwable throwable) {
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ enum AnnotatedMethodServiceFactory {
|
|||
INSTANCE;
|
||||
|
||||
@NonNull Map<? extends Service<?, ?>, TypeToken<? extends Service<?, ?>>> lookupServices(
|
||||
@NonNull final Object instance) throws Exception {
|
||||
final @NonNull Object instance) throws Exception {
|
||||
final Map<Service<?, ?>, TypeToken<? extends Service<?, ?>>> map = new HashMap<>();
|
||||
final Class<?> clazz = instance.getClass();
|
||||
for (final Method method : clazz.getDeclaredMethods()) {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public abstract class ChunkedRequestContext<@NonNull Context, @NonNull Result> {
|
|||
*
|
||||
* @param requests Request contexts
|
||||
*/
|
||||
protected ChunkedRequestContext(@NonNull final Collection<Context> requests) {
|
||||
protected ChunkedRequestContext(final @NonNull Collection<Context> requests) {
|
||||
this.requests = new ArrayList<>(requests);
|
||||
this.results = new HashMap<>(requests.size());
|
||||
}
|
||||
|
|
@ -83,7 +83,7 @@ public abstract class ChunkedRequestContext<@NonNull Context, @NonNull Result> {
|
|||
* @param context Context
|
||||
* @param result Result
|
||||
*/
|
||||
public final void storeResult(@NonNull final Context context, @NonNull final Result result) {
|
||||
public final void storeResult(final @NonNull Context context, final @NonNull Result result) {
|
||||
synchronized (this.lock) {
|
||||
this.results.put(context, result);
|
||||
this.requests.remove(context);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public final class PipelineException extends RuntimeException {
|
|||
*
|
||||
* @param cause Cause of the exception
|
||||
*/
|
||||
public PipelineException(@NonNull final Exception cause) {
|
||||
public PipelineException(final @NonNull Exception cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ public final class PipelineException extends RuntimeException {
|
|||
* @param message Message explaining the exception
|
||||
* @param cause Cause of the exception
|
||||
*/
|
||||
public PipelineException(@NonNull final String message, @NonNull final Exception cause) {
|
||||
public PipelineException(final @NonNull String message, final @NonNull Exception cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ enum ServiceFilterHandler {
|
|||
INSTANCE;
|
||||
|
||||
<Context> boolean passes(
|
||||
@NonNull final ServiceRepository<Context, ?>.ServiceWrapper<? extends Service<Context, ?>> service,
|
||||
@NonNull final Context context) {
|
||||
final @NonNull ServiceRepository<Context, ?>.ServiceWrapper<? extends Service<Context, ?>> service,
|
||||
final @NonNull Context context) {
|
||||
if (!service.isDefaultImplementation()) {
|
||||
for (final Predicate<Context> predicate : service.getFilters()) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public final class ServicePipeline {
|
|||
private final Map<Type, ServiceRepository<?, ?>> repositories;
|
||||
private final Executor executor;
|
||||
|
||||
ServicePipeline(@NonNull final Executor executor) {
|
||||
ServicePipeline(final @NonNull Executor executor) {
|
||||
this.repositories = new HashMap<>();
|
||||
this.executor = executor;
|
||||
}
|
||||
|
|
@ -72,8 +72,8 @@ public final class ServicePipeline {
|
|||
* @return ServicePipeline The service pipeline instance
|
||||
*/
|
||||
public <Context, Result> @NonNull ServicePipeline registerServiceType(
|
||||
@NonNull final TypeToken<? extends Service<@NonNull Context, @NonNull Result>> type,
|
||||
@NonNull final Service<@NonNull Context, @NonNull Result> defaultImplementation) {
|
||||
final @NonNull TypeToken<? extends Service<@NonNull Context, @NonNull Result>> type,
|
||||
final @NonNull Service<@NonNull Context, @NonNull Result> defaultImplementation) {
|
||||
synchronized (this.lock) {
|
||||
if (repositories.containsKey(type.getType())) {
|
||||
throw new IllegalArgumentException(String
|
||||
|
|
@ -106,7 +106,7 @@ public final class ServicePipeline {
|
|||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> @NonNull ServicePipeline registerMethods(
|
||||
@NonNull final T instance) throws Exception {
|
||||
final @NonNull T instance) throws Exception {
|
||||
synchronized (this.lock) {
|
||||
final Map<? extends Service<?, ?>, TypeToken<? extends Service<?, ?>>> services =
|
||||
AnnotatedMethodServiceFactory.INSTANCE.lookupServices(instance);
|
||||
|
|
@ -139,9 +139,9 @@ public final class ServicePipeline {
|
|||
* @return ServicePipeline The service pipeline instance
|
||||
*/
|
||||
public <Context, Result> ServicePipeline registerServiceImplementation(
|
||||
@NonNull final TypeToken<? extends Service<Context, Result>> type,
|
||||
@NonNull final Service<Context, Result> implementation,
|
||||
@NonNull final Collection<Predicate<Context>> filters) {
|
||||
final @NonNull TypeToken<? extends Service<Context, Result>> type,
|
||||
final @NonNull Service<Context, Result> implementation,
|
||||
final @NonNull Collection<Predicate<Context>> filters) {
|
||||
synchronized (this.lock) {
|
||||
final ServiceRepository<Context, Result> repository = getRepository(type);
|
||||
repository.registerImplementation(implementation, filters);
|
||||
|
|
@ -163,9 +163,9 @@ public final class ServicePipeline {
|
|||
* @return ServicePipeline The service pipeline instance
|
||||
*/
|
||||
public <Context, Result> ServicePipeline registerServiceImplementation(
|
||||
@NonNull final Class<? extends Service<Context, Result>> type,
|
||||
@NonNull final Service<Context, Result> implementation,
|
||||
@NonNull final Collection<Predicate<Context>> filters) {
|
||||
final @NonNull Class<? extends Service<Context, Result>> type,
|
||||
final @NonNull Service<Context, Result> implementation,
|
||||
final @NonNull Collection<Predicate<Context>> filters) {
|
||||
return registerServiceImplementation(TypeToken.get(type), implementation, filters);
|
||||
}
|
||||
|
||||
|
|
@ -178,14 +178,14 @@ public final class ServicePipeline {
|
|||
* @return Service pumper instance
|
||||
*/
|
||||
@NonNull
|
||||
public <Context> ServicePump<Context> pump(@NonNull final Context context) {
|
||||
public <Context> ServicePump<Context> pump(final @NonNull Context context) {
|
||||
return new ServicePump<>(this, context);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@NonNull
|
||||
<Context, Result> ServiceRepository<Context, Result> getRepository(
|
||||
@NonNull final TypeToken<? extends Service<Context, Result>> type) {
|
||||
final @NonNull TypeToken<? extends Service<Context, Result>> type) {
|
||||
final ServiceRepository<Context, Result> repository =
|
||||
(ServiceRepository<Context, Result>) this.repositories.get(type.getType());
|
||||
if (repository == null) {
|
||||
|
|
@ -218,7 +218,7 @@ public final class ServicePipeline {
|
|||
@NonNull
|
||||
@SuppressWarnings("unchecked")
|
||||
public <Context, Result, S extends Service<Context, Result>> Collection<TypeToken<? extends S>> getImplementations(
|
||||
@NonNull final TypeToken<S> type) {
|
||||
final @NonNull TypeToken<S> type) {
|
||||
ServiceRepository<Context, Result> repository = getRepository(type);
|
||||
List<TypeToken<? extends S>> collection = new LinkedList<>();
|
||||
final LinkedList<? extends ServiceRepository<Context, Result>.ServiceWrapper<? extends Service<Context, Result>>>
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public final class ServicePipelineBuilder {
|
|||
* @param executor New executor
|
||||
* @return Builder instance
|
||||
*/
|
||||
public @NonNull ServicePipelineBuilder withExecutor(@NonNull final Executor executor) {
|
||||
public @NonNull ServicePipelineBuilder withExecutor(final @NonNull Executor executor) {
|
||||
this.executor = Objects.requireNonNull(executor, "Executor may not be null");
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ public final class ServicePump<Context> {
|
|||
private final ServicePipeline servicePipeline;
|
||||
private final Context context;
|
||||
|
||||
ServicePump(@NonNull final ServicePipeline servicePipeline,
|
||||
@NonNull final Context context) {
|
||||
ServicePump(final @NonNull ServicePipeline servicePipeline,
|
||||
final @NonNull Context context) {
|
||||
this.servicePipeline = servicePipeline;
|
||||
this.context = context;
|
||||
}
|
||||
|
|
@ -51,7 +51,7 @@ public final class ServicePump<Context> {
|
|||
* @return Service spigot instance
|
||||
*/
|
||||
public <Result> @NonNull ServiceSpigot<@NonNull Context, @NonNull Result> through(
|
||||
@NonNull final TypeToken<? extends Service<@NonNull Context, @NonNull Result>> type) {
|
||||
final @NonNull TypeToken<? extends Service<@NonNull Context, @NonNull Result>> type) {
|
||||
return new ServiceSpigot<>(this.servicePipeline, this.context, type);
|
||||
}
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ public final class ServicePump<Context> {
|
|||
* @return Service spigot instance
|
||||
*/
|
||||
public <Result> @NonNull ServiceSpigot<@NonNull Context, @NonNull Result> through(
|
||||
@NonNull final Class<? extends Service<@NonNull Context, @NonNull Result>> clazz) {
|
||||
final @NonNull Class<? extends Service<@NonNull Context, @NonNull Result>> clazz) {
|
||||
return this.through(TypeToken.get(clazz));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public final class ServiceRepository<Context, Response> {
|
|||
*
|
||||
* @param serviceType Service type
|
||||
*/
|
||||
ServiceRepository(@NonNull final TypeToken<? extends Service<Context, Response>> serviceType) {
|
||||
ServiceRepository(final @NonNull TypeToken<? extends Service<Context, Response>> serviceType) {
|
||||
this.serviceType = serviceType;
|
||||
this.implementations = new LinkedList<>();
|
||||
}
|
||||
|
|
@ -66,8 +66,8 @@ public final class ServiceRepository<Context, Response> {
|
|||
* @param filters Filters that will be used to determine whether or not the service gets used
|
||||
* @param <T> Type of the implementation
|
||||
*/
|
||||
<T extends Service<Context, Response>> void registerImplementation(@NonNull final T service,
|
||||
@NonNull final Collection<Predicate<Context>> filters) {
|
||||
<T extends Service<Context, Response>> void registerImplementation(final @NonNull T service,
|
||||
final @NonNull Collection<Predicate<Context>> filters) {
|
||||
synchronized (this.lock) {
|
||||
this.implementations.add(new ServiceWrapper<>(service, filters));
|
||||
}
|
||||
|
|
@ -101,8 +101,8 @@ public final class ServiceRepository<Context, Response> {
|
|||
private final int registrationOrder = ServiceRepository.this.registrationOrder++;
|
||||
private final ExecutionOrder executionOrder;
|
||||
|
||||
private ServiceWrapper(@NonNull final T implementation,
|
||||
@NonNull final Collection<Predicate<Context>> filters) {
|
||||
private ServiceWrapper(final @NonNull T implementation,
|
||||
final @NonNull Collection<Predicate<Context>> filters) {
|
||||
this.defaultImplementation = implementations.isEmpty();
|
||||
this.implementation = implementation;
|
||||
this.filters = filters;
|
||||
|
|
@ -140,7 +140,7 @@ public final class ServiceRepository<Context, Response> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NonNull final ServiceWrapper<T> other) {
|
||||
public int compareTo(final @NonNull ServiceWrapper<T> other) {
|
||||
return Comparator.<ServiceWrapper<T>>comparingInt(
|
||||
wrapper -> wrapper.isDefaultImplementation()
|
||||
? Integer.MIN_VALUE
|
||||
|
|
|
|||
|
|
@ -45,9 +45,9 @@ public final class ServiceSpigot<Context, Result> {
|
|||
private final ServicePipeline pipeline;
|
||||
private final ServiceRepository<Context, Result> repository;
|
||||
|
||||
ServiceSpigot(@NonNull final ServicePipeline pipeline,
|
||||
@NonNull final Context context,
|
||||
@NonNull final TypeToken<? extends Service<@NonNull Context, @NonNull Result>> type) {
|
||||
ServiceSpigot(final @NonNull ServicePipeline pipeline,
|
||||
final @NonNull Context context,
|
||||
final @NonNull TypeToken<? extends Service<@NonNull Context, @NonNull Result>> type) {
|
||||
this.context = context;
|
||||
this.pipeline = pipeline;
|
||||
this.repository = pipeline.getRepository(type);
|
||||
|
|
@ -129,7 +129,7 @@ public final class ServiceSpigot<Context, Result> {
|
|||
* default implementation
|
||||
* @throws IllegalStateException If a {@link SideEffectService} returns {@code null}
|
||||
*/
|
||||
public void getResult(@NonNull final BiConsumer<Result, Throwable> consumer) {
|
||||
public void getResult(final @NonNull BiConsumer<Result, Throwable> consumer) {
|
||||
try {
|
||||
consumer.accept(getResult(), null);
|
||||
} catch (final PipelineException pipelineException) {
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public interface ConsumerService<Context>
|
|||
}
|
||||
|
||||
@Override
|
||||
default @NonNull State handle(@NonNull final Context context) {
|
||||
default @NonNull State handle(final @NonNull Context context) {
|
||||
try {
|
||||
this.accept(context);
|
||||
} catch (final PipeBurst burst) {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public interface PartialResultService<Context, Result, Chunked extends ChunkedRe
|
|||
extends Service<Chunked, @Nullable Map<@NonNull Context, @NonNull Result>> {
|
||||
|
||||
@Override
|
||||
default @Nullable Map<@NonNull Context, @NonNull Result> handle(@NonNull final Chunked context) {
|
||||
default @Nullable Map<@NonNull Context, @NonNull Result> handle(final @NonNull Chunked context) {
|
||||
if (!context.isCompleted()) {
|
||||
this.handleRequests(context.getRemaining()).forEach(context::storeResult);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue