Skip to content

Commit

Permalink
Sort processors
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
  • Loading branch information
Gabriel-Trintinalia committed May 12, 2024
1 parent 7a4ba1b commit 6048a1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
import java.util.List;
import java.util.Optional;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedMap;

/** Processes various types of requests based on their RequestType. */
public class RequestProcessorCoordinator {
private final ImmutableMap<RequestType, RequestProcessor> processors;
private final ImmutableSortedMap<RequestType, RequestProcessor> processors;

/**
* Constructs a RequestsProcessor with a given map of processors.
*
* @param processors A map associating RequestType with their corresponding RequestProcessor.
*/
private RequestProcessorCoordinator(
final ImmutableMap<RequestType, RequestProcessor> processors) {
final ImmutableSortedMap<RequestType, RequestProcessor> processors) {
this.processors = processors;
}

Expand All @@ -55,8 +55,8 @@ public Optional<List<Request>> process(
}

public static class Builder {
private final ImmutableMap.Builder<RequestType, RequestProcessor> requestProcessorBuilder =
ImmutableMap.builder();
private final ImmutableSortedMap.Builder<RequestType, RequestProcessor>
requestProcessorBuilder = ImmutableSortedMap.naturalOrder();

public RequestProcessorCoordinator.Builder addProcessor(
final RequestType type, final RequestProcessor processor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -39,7 +39,7 @@
*/
public class RequestsValidatorCoordinator {
private static final Logger LOG = LoggerFactory.getLogger(RequestsValidatorCoordinator.class);
private final ImmutableMap<RequestType, RequestValidator> validators;
private final ImmutableSortedMap<RequestType, RequestValidator> validators;

/**
* Constructs a new RequestsDelegateValidator with a mapping of request types to their respective
Expand All @@ -48,7 +48,7 @@ public class RequestsValidatorCoordinator {
* @param validators An immutable map of request types to their corresponding validators.
*/
private RequestsValidatorCoordinator(
final ImmutableMap<RequestType, RequestValidator> validators) {
final ImmutableSortedMap<RequestType, RequestValidator> validators) {
this.validators = validators;
}

Expand Down Expand Up @@ -149,8 +149,8 @@ private static List<Request> filterRequestsOfType(
}

public static class Builder {
private final ImmutableMap.Builder<RequestType, RequestValidator> validatorsBuilder =
ImmutableMap.builder();
private final ImmutableSortedMap.Builder<RequestType, RequestValidator> validatorsBuilder =
ImmutableSortedMap.naturalOrder();

public Builder addValidator(final RequestType type, final RequestValidator validator) {
this.validatorsBuilder.put(type, validator);
Expand Down

0 comments on commit 6048a1e

Please sign in to comment.