Skip to content

Commit 20bf045

Browse files
committed
use Map.of
Signed-off-by: Artur Souza <asouza.pro@gmail.com>
1 parent 9dbe04f commit 20bf045

File tree

12 files changed

+37
-43
lines changed

12 files changed

+37
-43
lines changed

sdk-tests/src/test/java/io/dapr/it/DaprPorts.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import java.io.IOException;
2020
import java.net.ServerSocket;
2121
import java.util.ArrayList;
22-
import java.util.Collections;
23-
import java.util.HashMap;
2422
import java.util.HashSet;
2523
import java.util.List;
2624
import java.util.Map;
@@ -40,12 +38,12 @@ private DaprPorts(Integer appPort, Integer httpPort, Integer grpcPort) {
4038
this.grpcPort = grpcPort;
4139
this.httpPort = httpPort;
4240
this.appPort = appPort;
43-
this.overrides = Collections.unmodifiableMap(new HashMap<>(){{
44-
put(Properties.GRPC_PORT, grpcPort.toString());
45-
put(Properties.HTTP_PORT, httpPort.toString());
46-
put(Properties.HTTP_ENDPOINT, "http://127.0.0.1:" + httpPort);
47-
put(Properties.GRPC_ENDPOINT, "127.0.0.1:" + grpcPort);
48-
}});
41+
this.overrides = Map.of(
42+
Properties.GRPC_PORT, grpcPort.toString(),
43+
Properties.HTTP_PORT, httpPort.toString(),
44+
Properties.HTTP_ENDPOINT, "http://127.0.0.1:" + httpPort,
45+
Properties.GRPC_ENDPOINT, "127.0.0.1:" + grpcPort
46+
);
4947
}
5048

5149
public static DaprPorts build(boolean appPort, boolean httpPort, boolean grpcPort) {

sdk-tests/src/test/java/io/dapr/it/binding/http/BindingIT.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.util.Collections;
2626
import java.util.List;
27+
import java.util.Map;
2728

2829
import static io.dapr.it.Retry.callWithRetry;
2930
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -115,14 +116,14 @@ public void inputOutputBinding() throws Exception {
115116

116117
System.out.println("sending first message");
117118
client.invokeBinding(
118-
bidingName, "create", myClass, Collections.singletonMap("MyMetadata", "MyValue"), Void.class).block();
119+
bidingName, "create", myClass, Map.of("MyMetadata", "MyValue"), Void.class).block();
119120

120121
// This is an example of sending a plain string. The input binding will receive
121122
// cat
122123
final String m = "cat";
123124
System.out.println("sending " + m);
124125
client.invokeBinding(
125-
bidingName, "create", m, Collections.singletonMap("MyMetadata", "MyValue"), Void.class).block();
126+
bidingName, "create", m, Map.of("MyMetadata", "MyValue"), Void.class).block();
126127

127128
// Metadata is not used by Kafka component, so it is not possible to validate.
128129
callWithRetry(() -> {

sdk-tests/src/test/java/io/dapr/it/pubsub/http/PubSubIT.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.Iterator;
4444
import java.util.LinkedHashMap;
4545
import java.util.List;
46+
import java.util.Map;
4647
import java.util.Objects;
4748
import java.util.Random;
4849
import java.util.Set;
@@ -534,7 +535,7 @@ public void testPubSubTTLMetadata() throws Exception {
534535
PUBSUB_NAME,
535536
TTL_TOPIC_NAME,
536537
message,
537-
Collections.singletonMap(Metadata.TTL_IN_SECONDS, "1")).block();
538+
Map.of(Metadata.TTL_IN_SECONDS, "1")).block();
538539
System.out.println(String.format("Published message: '%s' to topic '%s' pubsub_name '%s'", message, TOPIC_NAME, PUBSUB_NAME));
539540
}
540541
}
@@ -652,7 +653,7 @@ public void testLongValues() throws Exception {
652653
PUBSUB_NAME,
653654
LONG_TOPIC_NAME,
654655
value,
655-
Collections.singletonMap(Metadata.TTL_IN_SECONDS, "30")).block();
656+
Map.of(Metadata.TTL_IN_SECONDS, "30")).block();
656657

657658
try {
658659
Thread.sleep((long) (1000 * Math.random()));

sdk-tests/src/test/java/io/dapr/it/spring/data/DaprKeyValueRepositoryIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class DaprKeyValueRepositoryIT {
5151
"host=postgres-repository user=postgres password=password port=5432 connect_timeout=10 database=dapr_db_repository";
5252
private static final Map<String, String> STATE_STORE_PROPERTIES = createStateStoreProperties();
5353

54-
private static final Map<String, String> BINDING_PROPERTIES = Collections.singletonMap("connectionString", CONNECTION_STRING);
54+
private static final Map<String, String> BINDING_PROPERTIES = Map.of("connectionString", CONNECTION_STRING);
5555

5656
private static final Network DAPR_NETWORK = Network.newNetwork();
5757

sdk-tests/src/test/java/io/dapr/it/spring/data/MySQLDaprKeyValueTemplateIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class MySQLDaprKeyValueTemplateIT {
6363
private static final String BINDING_DSN = "mysql:password@tcp(mysql:3306)/dapr_db";
6464
private static final Map<String, String> STATE_STORE_PROPERTIES = createStateStoreProperties();
6565

66-
private static final Map<String, String> BINDING_PROPERTIES = Collections.singletonMap("url", BINDING_DSN);
66+
private static final Map<String, String> BINDING_PROPERTIES = Map.of("url", BINDING_DSN);
6767

6868
private static final Network DAPR_NETWORK = Network.newNetwork();
6969

@@ -114,7 +114,7 @@ private static Map<String, String> createStateStoreProperties() {
114114
*/
115115
@AfterEach
116116
public void tearDown() {
117-
var meta = Collections.singletonMap("sql", "delete from state");
117+
var meta = Map.of("sql", "delete from state");
118118

119119
daprClient.invokeBinding(BINDING_NAME, "exec", null, meta).block();
120120
}

sdk-tests/src/test/java/io/dapr/it/spring/data/PostgreSQLDaprKeyValueTemplateIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class PostgreSQLDaprKeyValueTemplateIT {
5454
"host=postgres user=postgres password=password port=5432 connect_timeout=10 database=dapr_db";
5555
private static final Map<String, String> STATE_STORE_PROPERTIES = createStateStoreProperties();
5656

57-
private static final Map<String, String> BINDING_PROPERTIES = Collections.singletonMap("connectionString", CONNECTION_STRING);
57+
private static final Map<String, String> BINDING_PROPERTIES = Map.of("connectionString", CONNECTION_STRING);
5858

5959
private static final Network DAPR_NETWORK = Network.newNetwork();
6060

@@ -96,7 +96,7 @@ private static Map<String, String> createStateStoreProperties() {
9696

9797
@BeforeEach
9898
public void setUp() {
99-
var meta = Collections.singletonMap("sql", "delete from state");
99+
var meta = Map.of("sql", "delete from state");
100100

101101
daprClient.invokeBinding(BINDING_NAME, "exec", null, meta).block();
102102
}

sdk-tests/src/test/java/io/dapr/it/testcontainers/DaprContainerIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
4545
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
4646
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
47-
import static java.util.Collections.singletonMap;
4847
import static org.junit.jupiter.api.Assertions.assertEquals;
4948
import static org.junit.jupiter.api.Assertions.assertNotNull;
5049
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -149,7 +148,7 @@ public void testPubSub() throws Exception {
149148

150149
try (DaprClient client = (builder).build()) {
151150
String message = "message content";
152-
Map<String, String> metadata = singletonMap(Metadata.TTL_IN_SECONDS, MESSAGE_TTL_IN_SECONDS);
151+
Map<String, String> metadata = Map.of(Metadata.TTL_IN_SECONDS, MESSAGE_TTL_IN_SECONDS);
153152
client.publishEvent(PUBSUB_NAME, PUBSUB_TOPIC_NAME, message, metadata).block();
154153
}
155154

sdk-tests/src/test/java/io/dapr/it/testcontainers/DaprWorkflowsIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.time.Duration;
3838
import java.util.ArrayList;
3939
import java.util.Collections;
40+
import java.util.Map;
4041

4142
import static org.junit.jupiter.api.Assertions.assertEquals;
4243
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -59,7 +60,7 @@ public class DaprWorkflowsIT {
5960
.withAppName("workflow-dapr-app")
6061
.withNetwork(DAPR_NETWORK)
6162
.withComponent(new Component("kvstore", "state.in-memory", "v1",
62-
Collections.singletonMap("actorStateStore", "true")))
63+
Map.of("actorStateStore", "true")))
6364
.withComponent(new Component("pubsub", "pubsub.in-memory", "v1", Collections.emptyMap()))
6465
.withDaprLogLevel(DaprLogLevel.DEBUG)
6566
.withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))

sdk/src/main/java/io/dapr/client/DaprHttp.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ public class DaprHttp implements AutoCloseable {
7171
/**
7272
* Context entries allowed to be in HTTP Headers.
7373
*/
74-
private static final Set<String> ALLOWED_CONTEXT_IN_HEADERS =
75-
Collections.unmodifiableSet(new HashSet<>(Arrays.asList("grpc-trace-bin", "traceparent", "tracestate")));
74+
private static final Set<String> ALLOWED_CONTEXT_IN_HEADERS = Set.of("grpc-trace-bin", "traceparent", "tracestate");
7675

7776
/**
7877
* Object mapper to parse DaprError with or without details.

sdk/src/main/java/io/dapr/client/domain/BulkPublishEntry.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public BulkPublishEntry(String entryId, T event, String contentType) {
5555
this.entryId = entryId;
5656
this.event = event;
5757
this.contentType = contentType;
58-
this.metadata = Collections.unmodifiableMap(new HashMap<>());
58+
this.metadata = Map.of();
5959
}
6060

6161
/**
@@ -70,8 +70,7 @@ public BulkPublishEntry(String entryId, T event, String contentType, Map<String,
7070
this.entryId = entryId;
7171
this.event = event;
7272
this.contentType = contentType;
73-
this.metadata = metadata == null ? Collections.unmodifiableMap(new HashMap<>()) :
74-
Collections.unmodifiableMap(metadata);
73+
this.metadata = metadata == null ? Map.of() : Collections.unmodifiableMap(metadata);
7574
}
7675

7776
public String getEntryId() {

sdk/src/main/java/io/dapr/client/domain/BulkPublishRequest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ public BulkPublishRequest(String pubsubName, String topic, List<BulkPublishEntry
7272
Map<String, String> metadata) {
7373
this.pubsubName = pubsubName;
7474
this.topic = topic;
75-
this.entries = entries == null ? Collections.unmodifiableList(new ArrayList<>()) :
76-
Collections.unmodifiableList(entries);
77-
this.metadata = metadata == null ? Collections.unmodifiableMap(new HashMap<>()) :
78-
Collections.unmodifiableMap(metadata);
75+
this.entries = entries == null ? List.of() : Collections.unmodifiableList(entries);
76+
this.metadata = metadata == null ? Map.of() : Collections.unmodifiableMap(metadata);
7977
}
8078

8179
public String getPubsubName() {

sdk/src/main/java/io/dapr/exceptions/DaprErrorDetails.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,18 @@ public class DaprErrorDetails {
3333
static final DaprErrorDetails EMPTY_INSTANCE = new DaprErrorDetails((Status) null);
3434

3535
private static final Map<Class<? extends Message>, ErrorDetailType> SUPPORTED_ERROR_TYPES =
36-
Collections.unmodifiableMap(new HashMap<>() {
37-
{
38-
put(com.google.rpc.ErrorInfo.class, ErrorDetailType.ERROR_INFO);
39-
put(com.google.rpc.RetryInfo.class, ErrorDetailType.RETRY_INFO);
40-
put(com.google.rpc.DebugInfo.class, ErrorDetailType.DEBUG_INFO);
41-
put(com.google.rpc.QuotaFailure.class, ErrorDetailType.QUOTA_FAILURE);
42-
put(com.google.rpc.PreconditionFailure.class, ErrorDetailType.PRECONDITION_FAILURE);
43-
put(com.google.rpc.BadRequest.class, ErrorDetailType.BAD_REQUEST);
44-
put(com.google.rpc.RequestInfo.class, ErrorDetailType.REQUEST_INFO);
45-
put(com.google.rpc.ResourceInfo.class, ErrorDetailType.RESOURCE_INFO);
46-
put(com.google.rpc.Help.class, ErrorDetailType.HELP);
47-
put(com.google.rpc.LocalizedMessage.class, ErrorDetailType.LOCALIZED_MESSAGE);
48-
}
49-
});
36+
Map.of(
37+
com.google.rpc.ErrorInfo.class, ErrorDetailType.ERROR_INFO,
38+
com.google.rpc.RetryInfo.class, ErrorDetailType.RETRY_INFO,
39+
com.google.rpc.DebugInfo.class, ErrorDetailType.DEBUG_INFO,
40+
com.google.rpc.QuotaFailure.class, ErrorDetailType.QUOTA_FAILURE,
41+
com.google.rpc.PreconditionFailure.class, ErrorDetailType.PRECONDITION_FAILURE,
42+
com.google.rpc.BadRequest.class, ErrorDetailType.BAD_REQUEST,
43+
com.google.rpc.RequestInfo.class, ErrorDetailType.REQUEST_INFO,
44+
com.google.rpc.ResourceInfo.class, ErrorDetailType.RESOURCE_INFO,
45+
com.google.rpc.Help.class, ErrorDetailType.HELP,
46+
com.google.rpc.LocalizedMessage.class, ErrorDetailType.LOCALIZED_MESSAGE
47+
);
5048

5149
private static final Map<String, Class<? extends Message>> ERROR_TYPES_FQN_REVERSE_LOOKUP =
5250
SUPPORTED_ERROR_TYPES.keySet().stream().collect(Collectors.toMap(

0 commit comments

Comments
 (0)