Skip to content

Commit

Permalink
Replace uses of Maps.immutableEntry with Map.entry
Browse files Browse the repository at this point in the history
The latter does not support null keys or values so this cannot replace
all uses.
  • Loading branch information
gaul committed Aug 8, 2024
1 parent 6a9778a commit 4976e17
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 22 deletions.
3 changes: 1 addition & 2 deletions src/main/java/org/gaul/s3proxy/GlobBlobStoreLocator.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public Map.Entry<String, BlobStore> locateBlobStore(
if (locatorEntry == null) {
return null;
}
return Maps.immutableEntry(locatorEntry.getKey(),
globEntry.getValue());
return Map.entry(locatorEntry.getKey(), globEntry.getValue());
}
}
5 changes: 2 additions & 3 deletions src/main/java/org/gaul/s3proxy/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.io.Files;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.inject.Module;
Expand Down Expand Up @@ -137,7 +136,7 @@ public static void main(String[] args) throws Exception {
S3ProxyConstants.PROPERTY_CREDENTIAL);
if (parsedIdentities.add(localIdentity)) {
locators.put(localIdentity,
Maps.immutableEntry(localCredential, blobStore));
Map.entry(localCredential, blobStore));
}
}
for (String key : properties.stringPropertyNames()) {
Expand All @@ -147,7 +146,7 @@ public static void main(String[] args) throws Exception {
globLocators.put(
FileSystems.getDefault().getPathMatcher(
"glob:" + bucketLocator),
Maps.immutableEntry(localIdentity, blobStore));
Map.entry(localIdentity, blobStore));
} else {
System.err.println("Multiple definitions of the " +
"bucket locator: " + bucketLocator);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/gaul/s3proxy/S3ProxyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public Map.Entry<String, BlobStore> locateBlobStore(
if (!identity.equals(identityArg)) {
return null;
}
return Maps.immutableEntry(credential, blobStore);
return Map.entry(credential, blobStore);
}
};
} else {
Expand Down Expand Up @@ -1400,7 +1400,7 @@ private void handleBlobList(HttpServletRequest request,
if (marker != null) {
if (Quirks.OPAQUE_MARKERS.contains(blobStoreType)) {
String realMarker = lastKeyToMarker.getIfPresent(
Maps.immutableEntry(containerName, marker));
Map.entry(containerName, marker));
if (realMarker != null) {
marker = realMarker;
}
Expand Down Expand Up @@ -1494,7 +1494,7 @@ private void handleBlobList(HttpServletRequest request,
StorageMetadata sm = Streams.findLast(
set.stream()).orElse(null);
if (sm != null) {
lastKeyToMarker.put(Maps.immutableEntry(
lastKeyToMarker.put(Map.entry(
containerName,
encodeBlob(encodingType, nextMarker)),
nextMarker);
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/org/gaul/s3proxy/AwsSdkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
import com.amazonaws.services.s3.model.UploadPartResult;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.io.ByteSource;

import org.assertj.core.api.Fail;
Expand Down Expand Up @@ -1518,10 +1517,9 @@ public void testBlobStoreLocator() throws Exception {
public Map.Entry<String, BlobStore> locateBlobStore(
String identity, String container, String blob) {
if (identity.equals(awsCreds.getAWSAccessKeyId())) {
return Maps.immutableEntry(awsCreds.getAWSSecretKey(),
blobStore1);
return Map.entry(awsCreds.getAWSSecretKey(), blobStore1);
} else if (identity.equals("other-identity")) {
return Maps.immutableEntry("credential", blobStore2);
return Map.entry("credential", blobStore2);
} else {
return null;
}
Expand Down
20 changes: 10 additions & 10 deletions src/test/java/org/gaul/s3proxy/GlobBlobStoreLocatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public void setUp() {
@Test
public void testLocateIdentity() {
var credsMap = ImmutableSortedMap.of(
"id1", Maps.immutableEntry("one", blobStoreOne),
"id2", Maps.immutableEntry("two", blobStoreTwo));
"id1", Map.entry("one", blobStoreOne),
"id2", Map.entry("two", blobStoreTwo));
GlobBlobStoreLocator locator = new GlobBlobStoreLocator(
credsMap, ImmutableMap.of());
assertThat(locator.locateBlobStore("id2", null, null).getKey())
Expand All @@ -71,13 +71,13 @@ public void testLocateIdentity() {
@Test
public void testLocateContainer() {
var credsMap = ImmutableMap.of(
"id1", Maps.immutableEntry("one", blobStoreOne),
"id2", Maps.immutableEntry("two", blobStoreTwo));
"id1", Map.entry("one", blobStoreOne),
"id2", Map.entry("two", blobStoreTwo));
var globMap = ImmutableMap.of(
FileSystems.getDefault().getPathMatcher("glob:container1"),
Maps.immutableEntry("id1", blobStoreOne),
Map.entry("id1", blobStoreOne),
FileSystems.getDefault().getPathMatcher("glob:container2"),
Maps.immutableEntry("id2", blobStoreTwo));
Map.entry("id2", blobStoreTwo));
GlobBlobStoreLocator locator = new GlobBlobStoreLocator(credsMap,
globMap);

Expand All @@ -100,15 +100,15 @@ public void testLocateGlob() {
var credsMap =
ImmutableSortedMap.<String, Map.Entry<String, BlobStore>>of(
"id0", Maps.immutableEntry("zero", null),
"id1", Maps.immutableEntry("one", blobStoreOne),
"id2", Maps.immutableEntry("two", blobStoreTwo));
"id1", Map.entry("one", blobStoreOne),
"id2", Map.entry("two", blobStoreTwo));
var globMap =
ImmutableMap.<PathMatcher, Map.Entry<String, BlobStore>>of(
FileSystems.getDefault().getPathMatcher(
"glob:{one,two}"),
Maps.immutableEntry("id1", blobStoreOne),
Map.entry("id1", blobStoreOne),
FileSystems.getDefault().getPathMatcher("glob:cont?X*"),
Maps.immutableEntry("id2", blobStoreTwo));
Map.entry("id2", blobStoreTwo));
GlobBlobStoreLocator locator = new GlobBlobStoreLocator(credsMap,
globMap);

Expand Down

0 comments on commit 4976e17

Please sign in to comment.