Skip to content

Commit 22f3fc9

Browse files
author
Tom May
committed
Use the google collections static methods to simplify thrift argument
construction.
1 parent 7eee1c6 commit 22f3fc9

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

plugins/cassandra/src/main/java/org/elasticsearch/cassandra/blobstore/CassandraBlobStore.java

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
import org.elasticsearch.common.blobstore.ImmutableBlobContainer;
6868
import org.elasticsearch.common.blobstore.support.PlainBlobMetaData;
6969
import org.elasticsearch.common.collect.ImmutableMap;
70+
import org.elasticsearch.common.collect.ImmutableList;
71+
import org.elasticsearch.common.collect.Lists;
72+
import org.elasticsearch.common.collect.Maps;
7073
import org.elasticsearch.common.component.AbstractComponent;
7174
import org.elasticsearch.common.logging.ESLogger;
7275
import org.elasticsearch.common.logging.Loggers;
@@ -192,21 +195,19 @@ private boolean deleteBlobs(String blobPath, String... blobNames)
192195
long timestamp = System.currentTimeMillis();
193196

194197
Map<String, Map<String, List<Mutation>>> mutationMap =
195-
new HashMap<String, Map<String, List<Mutation>>>();
198+
Maps.newHashMap();
196199

197-
List<Mutation> blobNamesMutations = new ArrayList<Mutation>();
200+
List<Mutation> blobNamesMutations = Lists.newArrayList();
198201

199202
for (String blobName : blobNames) {
200203
String blobKey = blobKey(blobPath, blobName);
201204

202205
// Delete the blob data from Blobs.
203206

204-
List<Mutation> blobsMutations = new ArrayList<Mutation>(1);
205-
blobsMutations.add(createDelete(null, timestamp));
206-
207-
Map<String, List<Mutation>> blobsMutationMap =
208-
new HashMap<String, List<Mutation>>();
209-
blobsMutationMap.put("Blobs", blobsMutations);
207+
Map<String, List<Mutation>> blobsMutationMap = Maps.newHashMap();
208+
blobsMutationMap.put(
209+
"Blobs",
210+
ImmutableList.of(createDelete(null, timestamp)));
210211

211212
mutationMap.put(blobKey, blobsMutationMap);
212213

@@ -216,8 +217,7 @@ private boolean deleteBlobs(String blobPath, String... blobNames)
216217
}
217218

218219
Map<String, List<Mutation>> blobNamesMutationMap =
219-
new HashMap<String, List<Mutation>>();
220-
blobNamesMutationMap.put("BlobNames", blobNamesMutations);
220+
ImmutableMap.of("BlobNames", blobNamesMutations);
221221

222222
mutationMap.put(blobPath, blobNamesMutationMap);
223223

@@ -243,10 +243,9 @@ private boolean deleteBlobs(String blobPath, String... blobNames)
243243
private Mutation createDelete(String name, long timestamp) {
244244
Deletion deletion = new Deletion(timestamp);
245245
if (name != null) {
246-
List<ByteBuffer> columnNames = new ArrayList<ByteBuffer>(1);
247-
columnNames.add(utf8.encode(name));
248246
deletion.setPredicate(
249-
new SlicePredicate().setColumn_names(columnNames));
247+
new SlicePredicate().setColumn_names(
248+
ImmutableList.of(utf8.encode(name))));
250249
}
251250
return new Mutation().setDeletion(deletion);
252251
}
@@ -369,7 +368,7 @@ private void writeBlob(Cassandra.Client client, String blobPath, String blobName
369368
long timestamp = System.currentTimeMillis();
370369

371370
Map<String, Map<String, List<Mutation>>> mutationMap =
372-
new HashMap<String, Map<String, List<Mutation>>>();
371+
Maps.newHashMap();
373372

374373
// Insert the blob data into Blobs.
375374

@@ -382,25 +381,22 @@ private void writeBlob(Cassandra.Client client, String blobPath, String blobName
382381
ByteBuffer blobData = ByteBuffer.allocate(intSizeInBytes);
383382
new DataInputStream(is).readFully(blobData.array());
384383

385-
List<Mutation> blobsMutations = new ArrayList<Mutation>();
386-
blobsMutations.add(createInsert("data", blobData, timestamp));
387-
388-
Map<String, List<Mutation>> blobsMutationMap =
389-
new HashMap<String, List<Mutation>>();
390-
blobsMutationMap.put("Blobs", blobsMutations);
384+
Map<String, List<Mutation>> blobsMutationMap = Maps.newHashMap();
385+
blobsMutationMap.put(
386+
"Blobs",
387+
ImmutableList.of(createInsert("data", blobData, timestamp)));
391388

392389
mutationMap.put(blobKey, blobsMutationMap);
393390

394391
// Insert the blobName into BlobNames.
395392

396393
ByteBuffer size = utf8.encode(Long.toString(sizeInBytes));
397394

398-
List<Mutation> blobNamesMutations = new ArrayList<Mutation>();
399-
blobNamesMutations.add(createInsert(blobName, size, timestamp));
400-
401395
Map<String, List<Mutation>> blobNamesMutationMap =
402-
new HashMap<String, List<Mutation>>();
403-
blobNamesMutationMap.put("BlobNames", blobNamesMutations);
396+
Maps.newHashMap();
397+
blobNamesMutationMap.put(
398+
"BlobNames",
399+
ImmutableList.of(createInsert(blobName, size, timestamp)));
404400

405401
mutationMap.put(blobPath, blobNamesMutationMap);
406402

0 commit comments

Comments
 (0)