Use var for Immutable builders

pull/666/head
Andrew Gaul 2024-07-20 12:42:05 +05:30
rodzic 5a129e54cf
commit 0effb4bf45
11 zmienionych plików z 64 dodań i 95 usunięć

Wyświetl plik

@ -135,8 +135,7 @@ public final class AliasBlobStore extends ForwardingBlobStore {
@Override
public PageSet<? extends StorageMetadata> list() {
PageSet<? extends StorageMetadata> upstream = this.delegate().list();
ImmutableList.Builder<StorageMetadata> results =
new ImmutableList.Builder<>();
var results = new ImmutableList.Builder<StorageMetadata>();
for (StorageMetadata sm : upstream) {
if (aliases.containsValue(sm.getName())) {
MutableStorageMetadata bucketAlias =

Wyświetl plik

@ -233,7 +233,7 @@ public final class EncryptedBlobStore extends ForwardingBlobStore {
// filter the list by showing the unencrypted blob size
private PageSet<? extends StorageMetadata> filteredList(
PageSet<? extends StorageMetadata> pageSet) {
ImmutableSet.Builder<StorageMetadata> builder = ImmutableSet.builder();
var builder = ImmutableSet.<StorageMetadata>builder();
for (StorageMetadata sm : pageSet) {
if (sm instanceof BlobMetadata) {
MutableBlobMetadata mbm =

Wyświetl plik

@ -106,10 +106,10 @@ public final class Main {
.build();
ExecutorService executorService = DynamicExecutors.newScalingThreadPool(
1, 20, 60 * 1000, factory);
ImmutableMap.Builder<String, Map.Entry<String, BlobStore>> locators =
ImmutableMap.builder();
ImmutableMap.Builder<PathMatcher, Map.Entry<String, BlobStore>>
globLocators = ImmutableMap.builder();
var locators = ImmutableMap
.<String, Map.Entry<String, BlobStore>>builder();
var globLocators = ImmutableMap
.<PathMatcher, Map.Entry<String, BlobStore>>builder();
Set<String> locatorGlobs = new HashSet<>();
Set<String> parsedIdentities = new HashSet<>();
for (File propertiesFile : options.propertiesFiles) {
@ -177,10 +177,8 @@ public final class Main {
throw e;
}
final Map<String, Map.Entry<String, BlobStore>> locator =
locators.build();
final Map<PathMatcher, Map.Entry<String, BlobStore>>
globLocator = globLocators.build();
var locator = locators.build();
var globLocator = globLocators.build();
if (!locator.isEmpty() || !globLocator.isEmpty()) {
s3Proxy.setBlobStoreLocator(
new GlobBlobStoreLocator(locator, globLocator));

Wyświetl plik

@ -100,7 +100,7 @@ final class NullBlobStore extends ForwardingBlobStore {
@Override
public PageSet<? extends StorageMetadata> list(String container) {
ImmutableSet.Builder<StorageMetadata> builder = ImmutableSet.builder();
var builder = ImmutableSet.<StorageMetadata>builder();
PageSet<? extends StorageMetadata> pageSet = super.list(container);
for (StorageMetadata sm : pageSet) {
MutableStorageMetadata msm = new MutableStorageMetadataImpl(sm);
@ -203,7 +203,7 @@ final class NullBlobStore extends ForwardingBlobStore {
@Override
public List<MultipartPart> listMultipartUpload(MultipartUpload mpu) {
ImmutableList.Builder<MultipartPart> builder = ImmutableList.builder();
var builder = ImmutableList.<MultipartPart>builder();
for (MultipartPart part : super.listMultipartUpload(mpu)) {
// get real blob size from stub blob
Blob blob = getBlob(mpu.containerName(),

Wyświetl plik

@ -1845,8 +1845,7 @@ public class S3ProxyHandler {
if (replaceMetadata) {
ContentMetadataBuilder contentMetadata =
ContentMetadataBuilder.create();
ImmutableMap.Builder<String, String> userMetadata =
ImmutableMap.builder();
var userMetadata = ImmutableMap.<String, String>builder();
for (String headerName : Collections.list(
request.getHeaderNames())) {
String headerValue = Strings.nullToEmpty(request.getHeader(
@ -2268,8 +2267,7 @@ public class S3ProxyHandler {
// List parts to get part sizes and to map multiple Azure parts
// into single parts.
ImmutableMap.Builder<Integer, MultipartPart> builder =
ImmutableMap.builder();
var builder = ImmutableMap.<Integer, MultipartPart>builder();
for (MultipartPart part : blobStore.listMultipartUpload(mpu)) {
builder.put(part.partNumber(), part);
}
@ -3026,8 +3024,7 @@ public class S3ProxyHandler {
private static void addContentMetdataFromHttpRequest(
BlobBuilder.PayloadBlobBuilder builder,
HttpServletRequest request) {
ImmutableMap.Builder<String, String> userMetadata =
ImmutableMap.builder();
var userMetadata = ImmutableMap.<String, String>builder();
for (String headerName : Collections.list(request.getHeaderNames())) {
if (startsWithIgnoreCase(headerName, USER_METADATA_PREFIX)) {
userMetadata.put(

Wyświetl plik

@ -126,8 +126,7 @@ final class ShardedBlobStore extends ForwardingBlobStore {
"Number of shards unset for sharded buckets: %s",
allMissingShards));
}
ImmutableMap.Builder<String, ShardedBucket> bucketsBuilder =
new ImmutableMap.Builder<>();
var bucketsBuilder = new ImmutableMap.Builder<String, ShardedBucket>();
for (String bucket : shards.keySet()) {
String prefix = prefixes.get(bucket);
if (prefix == null) {
@ -138,8 +137,7 @@ final class ShardedBlobStore extends ForwardingBlobStore {
}
this.buckets = bucketsBuilder.build();
ImmutableMap.Builder<String, String> prefixMapBuilder =
new ImmutableMap.Builder<>();
var prefixMapBuilder = new ImmutableMap.Builder<String, String>();
for (String virtualBucket : buckets.keySet()) {
String prefix = buckets.get(virtualBucket).prefix;
prefixMapBuilder.put(prefix, virtualBucket);
@ -149,8 +147,7 @@ final class ShardedBlobStore extends ForwardingBlobStore {
public static ImmutableMap<String, Integer> parseBucketShards(
Properties properties) {
ImmutableMap.Builder<String, Integer> shardsMap =
new ImmutableMap.Builder<>();
var shardsMap = new ImmutableMap.Builder<String, Integer>();
for (String key : properties.stringPropertyNames()) {
Matcher matcher = PROPERTIES_SHARDS_RE.matcher(key);
if (!matcher.matches()) {
@ -168,8 +165,7 @@ final class ShardedBlobStore extends ForwardingBlobStore {
public static ImmutableMap<String, String> parsePrefixes(
Properties properties) {
ImmutableMap.Builder<String, String> prefixesMap =
new ImmutableMap.Builder<>();
var prefixesMap = new ImmutableMap.Builder<String, String>();
for (String key : properties.stringPropertyNames()) {
Matcher matcher = PROPERTIES_PREFIX_RE.matcher(key);
if (!matcher.matches()) {
@ -189,8 +185,7 @@ final class ShardedBlobStore extends ForwardingBlobStore {
}
private Map<String, String> createSuperblockMeta(ShardedBucket bucket) {
ImmutableMap.Builder<String, String> meta =
new ImmutableMap.Builder<>();
var meta = new ImmutableMap.Builder<String, String>();
meta.put("s3proxy-sharded-superblock-version", SUPERBLOCK_VERSION);
meta.put("s3proxy-sharded-superblock-prefix", bucket.prefix);
meta.put("s3proxy-sharded-superblock-shards",
@ -229,8 +224,7 @@ final class ShardedBlobStore extends ForwardingBlobStore {
private boolean createShards(ShardedBucket bucket, Location location,
CreateContainerOptions options) {
ImmutableList.Builder<Future<Boolean>> futuresBuilder =
new ImmutableList.Builder<>();
var futuresBuilder = new ImmutableList.Builder<Future<Boolean>>();
ExecutorService executor = Executors.newFixedThreadPool(
Math.min(bucket.shards, MAX_SHARD_THREADS));
BlobStore blobStore = this.delegate();
@ -241,7 +235,7 @@ final class ShardedBlobStore extends ForwardingBlobStore {
() -> blobStore.createContainerInLocation(
location, shardContainer, options)));
}
ImmutableList<Future<Boolean>> futures = futuresBuilder.build();
var futures = futuresBuilder.build();
executor.shutdown();
boolean ret = true;
for (Future<Boolean> future : futures) {
@ -304,8 +298,7 @@ final class ShardedBlobStore extends ForwardingBlobStore {
@Override
public PageSet<? extends StorageMetadata> list() {
PageSet<? extends StorageMetadata> upstream = this.delegate().list();
ImmutableList.Builder<StorageMetadata> results =
new ImmutableList.Builder<>();
var results = new ImmutableList.Builder<StorageMetadata>();
Set<String> virtualBuckets = new HashSet<>();
for (StorageMetadata sm : upstream) {
Matcher matcher = SHARD_RE.matcher(sm.getName());
@ -403,8 +396,7 @@ final class ShardedBlobStore extends ForwardingBlobStore {
}
private boolean deleteShards(ShardedBucket bucket) {
ImmutableList.Builder<Future<Boolean>> futuresBuilder =
new ImmutableList.Builder<>();
var futuresBuilder = new ImmutableList.Builder<Future<Boolean>>();
ExecutorService executor = Executors.newFixedThreadPool(
Math.min(bucket.shards, MAX_SHARD_THREADS));
for (int n = 0; n < bucket.shards; ++n) {
@ -413,7 +405,7 @@ final class ShardedBlobStore extends ForwardingBlobStore {
() -> this.delegate().deleteContainerIfEmpty(shard)));
}
executor.shutdown();
ImmutableList<Future<Boolean>> futures = futuresBuilder.build();
var futures = futuresBuilder.build();
boolean ret = true;
for (Future<Boolean> future : futures) {
try {

Wyświetl plik

@ -66,8 +66,7 @@ public final class AliasBlobStoreTest {
.modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
.build(BlobStoreContext.class);
blobStore = context.getBlobStore();
ImmutableBiMap.Builder<String, String> aliasesBuilder =
new ImmutableBiMap.Builder<>();
var aliasesBuilder = new ImmutableBiMap.Builder<String, String>();
aliasesBuilder.put(aliasContainerName, containerName);
aliasBlobStore = AliasBlobStore.newAliasBlobStore(
blobStore, aliasesBuilder.build());
@ -152,8 +151,7 @@ public final class AliasBlobStoreTest {
MultipartPart part = aliasBlobStore.uploadMultipartPart(
mpu, 1, Payloads.newPayload(content));
assertThat(part.partETag()).isEqualTo(contentHash.toString());
ImmutableList.Builder<MultipartPart> parts =
new ImmutableList.Builder<>();
var parts = new ImmutableList.Builder<MultipartPart>();
parts.add(part);
String mpuETag = aliasBlobStore.completeMultipartUpload(mpu,
parts.build());

Wyświetl plik

@ -755,7 +755,7 @@ public final class AwsSdkTest {
@Test
public void testListBuckets() throws Exception {
ImmutableList.Builder<String> builder = ImmutableList.builder();
var builder = ImmutableList.<String>builder();
for (Bucket bucket : client.listBuckets()) {
builder.add(bucket.getName());
}
@ -841,7 +841,7 @@ public final class AwsSdkTest {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(BYTE_SOURCE.size());
ImmutableList.Builder<String> builder = ImmutableList.builder();
var builder = ImmutableList.<String>builder();
client.putObject(containerName, "blob1", BYTE_SOURCE.openStream(),
metadata);
listing = client.listObjects(containerName);
@ -872,7 +872,7 @@ public final class AwsSdkTest {
client.putObject(containerName, "prefix/blob2",
BYTE_SOURCE.openStream(), metadata);
ImmutableList.Builder<String> builder = ImmutableList.builder();
var builder = ImmutableList.<String>builder();
listing = client.listObjects(new ListObjectsRequest()
.withBucketName(containerName)
.withDelimiter("/"));
@ -1030,7 +1030,7 @@ public final class AwsSdkTest {
String contentEncoding = "gzip";
String contentLanguage = "fr";
String contentType = "audio/mp4";
Map<String, String> userMetadata = ImmutableMap.of(
var userMetadata = ImmutableMap.of(
"key1", "value1",
"key2", "value2");
ObjectMetadata metadata = new ObjectMetadata();
@ -1092,7 +1092,7 @@ public final class AwsSdkTest {
String contentEncoding = "gzip";
String contentLanguage = "fr";
String contentType = "audio/mp4";
Map<String, String> userMetadata = ImmutableMap.of(
var userMetadata = ImmutableMap.of(
"key1", "value1",
"key2", "value2");
ObjectMetadata metadata = new ObjectMetadata();
@ -1185,7 +1185,7 @@ public final class AwsSdkTest {
InitiateMultipartUploadResult result = client.initiateMultipartUpload(
new InitiateMultipartUploadRequest(containerName, blobName));
ImmutableList.Builder<PartETag> parts = ImmutableList.builder();
var parts = ImmutableList.<PartETag>builder();
for (int i = 0; i < numParts; ++i) {
ByteSource partByteSource = byteSource.slice(
@ -1286,7 +1286,7 @@ public final class AwsSdkTest {
String contentEncoding = "gzip";
String contentLanguage = "en";
String contentType = "audio/ogg";
Map<String, String> userMetadata = ImmutableMap.of(
var userMetadata = ImmutableMap.of(
"key1", "value1",
"key2", "value2");
ObjectMetadata metadata = new ObjectMetadata();
@ -1390,7 +1390,7 @@ public final class AwsSdkTest {
}
contentMetadata.setContentType(contentType);
// TODO: expires
Map<String, String> userMetadata = ImmutableMap.of(
var userMetadata = ImmutableMap.of(
"key3", "value3",
"key4", "value4");
contentMetadata.setUserMetadata(userMetadata);

Wyświetl plik

@ -56,10 +56,9 @@ public final class GlobBlobStoreLocatorTest {
@Test
public void testLocateIdentity() {
ImmutableMap<String, Map.Entry<String, BlobStore>> credsMap =
ImmutableSortedMap.of(
"id1", Maps.immutableEntry("one", blobStoreOne),
"id2", Maps.immutableEntry("two", blobStoreTwo));
var credsMap = ImmutableSortedMap.of(
"id1", Maps.immutableEntry("one", blobStoreOne),
"id2", Maps.immutableEntry("two", blobStoreTwo));
GlobBlobStoreLocator locator = new GlobBlobStoreLocator(
credsMap, ImmutableMap.of());
assertThat(locator.locateBlobStore("id2", null, null).getKey())
@ -71,19 +70,14 @@ public final class GlobBlobStoreLocatorTest {
@Test
public void testLocateContainer() {
ImmutableMap<String, Map.Entry<String, BlobStore>> credsMap =
ImmutableMap.of(
"id1", Maps.immutableEntry("one", blobStoreOne),
"id2", Maps.immutableEntry("two", blobStoreTwo));
ImmutableMap<PathMatcher, Map.Entry<String, BlobStore>> globMap =
ImmutableMap.of(
FileSystems.getDefault().getPathMatcher(
"glob:container1"),
Maps.immutableEntry("id1", blobStoreOne),
FileSystems.getDefault().getPathMatcher(
"glob:container2"),
Maps.immutableEntry("id2", blobStoreTwo)
);
var credsMap = ImmutableMap.of(
"id1", Maps.immutableEntry("one", blobStoreOne),
"id2", Maps.immutableEntry("two", blobStoreTwo));
var globMap = ImmutableMap.of(
FileSystems.getDefault().getPathMatcher("glob:container1"),
Maps.immutableEntry("id1", blobStoreOne),
FileSystems.getDefault().getPathMatcher("glob:container2"),
Maps.immutableEntry("id2", blobStoreTwo));
GlobBlobStoreLocator locator = new GlobBlobStoreLocator(credsMap,
globMap);
@ -103,20 +97,18 @@ public final class GlobBlobStoreLocatorTest {
@Test
public void testLocateGlob() {
ImmutableMap<String, Map.Entry<String, BlobStore>> credsMap =
ImmutableSortedMap.of(
"id0", Maps.immutableEntry("zero", null),
"id1", Maps.immutableEntry("one", blobStoreOne),
"id2", Maps.immutableEntry("two", blobStoreTwo));
ImmutableMap<PathMatcher, Map.Entry<String, BlobStore>> globMap =
ImmutableMap.of(
var credsMap =
ImmutableSortedMap.<String, Map.Entry<String, BlobStore>>of(
"id0", Maps.immutableEntry("zero", null),
"id1", Maps.immutableEntry("one", blobStoreOne),
"id2", Maps.immutableEntry("two", blobStoreTwo));
var globMap =
ImmutableMap.<PathMatcher, Map.Entry<String, BlobStore>>of(
FileSystems.getDefault().getPathMatcher(
"glob:{one,two}"),
Maps.immutableEntry("id1", blobStoreOne),
FileSystems.getDefault().getPathMatcher(
"glob:cont?X*"),
Maps.immutableEntry("id2", blobStoreTwo)
);
FileSystems.getDefault().getPathMatcher("glob:cont?X*"),
Maps.immutableEntry("id2", blobStoreTwo));
GlobBlobStoreLocator locator = new GlobBlobStoreLocator(credsMap,
globMap);
@ -130,15 +122,12 @@ public final class GlobBlobStoreLocatorTest {
@Test
public void testGlobLocatorAnonymous() {
ImmutableMap<PathMatcher, Map.Entry<String, BlobStore>> globMap =
ImmutableMap.of(
FileSystems.getDefault().getPathMatcher(
"glob:one"),
var globMap =
ImmutableMap.<PathMatcher, Map.Entry<String, BlobStore>>of(
FileSystems.getDefault().getPathMatcher("glob:one"),
Maps.immutableEntry(null, blobStoreOne),
FileSystems.getDefault().getPathMatcher(
"glob:two"),
Maps.immutableEntry(null, blobStoreTwo)
);
FileSystems.getDefault().getPathMatcher("glob:two"),
Maps.immutableEntry(null, blobStoreTwo));
GlobBlobStoreLocator locator = new GlobBlobStoreLocator(
ImmutableMap.of(), globMap);

Wyświetl plik

@ -71,12 +71,11 @@ public final class RegexBlobStoreTest {
@Test
public void testRemoveSomeCharsFromName() throws IOException {
ImmutableList.Builder<Map.Entry<Pattern, String>> regexBuilder =
new ImmutableList.Builder<>();
regexBuilder.add(new SimpleEntry<Pattern, String>(Pattern.compile(
"[^a-zA-Z0-9/_.]"), "_"));
var regexes = ImmutableList.<Map.Entry<Pattern, String>>of(
new SimpleEntry<Pattern, String>(
Pattern.compile("[^a-zA-Z0-9/_.]"), "_"));
BlobStore regexBlobStore = RegexBlobStore.newRegexBlobStore(delegate,
regexBuilder.build());
regexes);
String initialBlobName = "test/remove:badchars-folder/blob.txt";
String targetBlobName = "test/remove_badchars_folder/blob.txt";

Wyświetl plik

@ -60,11 +60,8 @@ public final class ShardedBlobStoreTest {
.modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
.build(BlobStoreContext.class);
blobStore = context.getBlobStore();
ImmutableMap<String, Integer> shardsMap =
new ImmutableMap.Builder<String, Integer>()
.put(containerName, shards).build();
prefixesMap = new ImmutableMap.Builder<String, String>()
.put(containerName, prefix).build();
var shardsMap = ImmutableMap.of(containerName, shards);
prefixesMap = ImmutableMap.of(containerName, prefix);
shardedBlobStore = ShardedBlobStore.newShardedBlobStore(
blobStore, shardsMap, prefixesMap);
createdContainers = new ArrayList<>();