some minor code cleanup (#83)
diff --git a/src/main/java/org/apache/accumulo/examples/client/CountingVerifyingReceiver.java b/src/main/java/org/apache/accumulo/examples/client/CountingVerifyingReceiver.java
index 9b3d909..1744795 100644
--- a/src/main/java/org/apache/accumulo/examples/client/CountingVerifyingReceiver.java
+++ b/src/main/java/org/apache/accumulo/examples/client/CountingVerifyingReceiver.java
@@ -46,7 +46,7 @@
String row = key.getRow().toString();
long rowid = Integer.parseInt(row.split("_")[1]);
- byte expectedValue[] = RandomBatchWriter.createValue(rowid, expectedValueSize);
+ byte[] expectedValue = RandomBatchWriter.createValue(rowid, expectedValueSize);
if (!Arrays.equals(expectedValue, value.get())) {
log.error("Got unexpected value for " + key + " expected : "
diff --git a/src/main/java/org/apache/accumulo/examples/client/RandomBatchWriter.java b/src/main/java/org/apache/accumulo/examples/client/RandomBatchWriter.java
index a004aec..03b6fbb 100644
--- a/src/main/java/org/apache/accumulo/examples/client/RandomBatchWriter.java
+++ b/src/main/java/org/apache/accumulo/examples/client/RandomBatchWriter.java
@@ -58,7 +58,7 @@
*/
public static byte[] createValue(long rowid, int dataSize) {
Random r = new Random(rowid);
- byte value[] = new byte[dataSize];
+ byte[] value = new byte[dataSize];
r.nextBytes(value);
@@ -89,7 +89,7 @@
// create a random value that is a function of the
// row id for verification purposes
- byte value[] = createValue(rowid, dataSize);
+ byte[] value = createValue(rowid, dataSize);
m.put(new Text("foo"), new Text("1"), visibility, new Value(value));
@@ -159,7 +159,7 @@
if (e.getSecurityErrorCodes().size() > 0) {
HashMap<String,Set<SecurityErrorCode>> tables = new HashMap<>();
for (Entry<TabletId,Set<SecurityErrorCode>> ke : e.getSecurityErrorCodes().entrySet()) {
- String tableId = ke.getKey().getTableId().toString();
+ String tableId = ke.getKey().getTable().toString();
Set<SecurityErrorCode> secCodes = tables.get(tableId);
if (secCodes == null) {
secCodes = new HashSet<>();
diff --git a/src/main/java/org/apache/accumulo/examples/client/TracingExample.java b/src/main/java/org/apache/accumulo/examples/client/TracingExample.java
index 551b43c..5891b96 100644
--- a/src/main/java/org/apache/accumulo/examples/client/TracingExample.java
+++ b/src/main/java/org/apache/accumulo/examples/client/TracingExample.java
@@ -52,7 +52,7 @@
private static final Logger log = LoggerFactory.getLogger(TracingExample.class);
private static final String DEFAULT_TABLE_NAME = "test";
- private AccumuloClient client;
+ private final AccumuloClient client;
static class Opts extends ClientOnDefaultTable {
@Parameter(names = {"--createtable"}, description = "create table before doing anything")
diff --git a/src/main/java/org/apache/accumulo/examples/dirlist/FileCount.java b/src/main/java/org/apache/accumulo/examples/dirlist/FileCount.java
index ad9c70f..83b449f 100644
--- a/src/main/java/org/apache/accumulo/examples/dirlist/FileCount.java
+++ b/src/main/java/org/apache/accumulo/examples/dirlist/FileCount.java
@@ -44,12 +44,12 @@
private int entriesScanned;
private int inserts;
- private ScannerOpts scanOpts;
- private BatchWriterOpts bwOpts;
- private AccumuloClient client;
- private String tableName;
- private Authorizations auths;
- private ColumnVisibility visibility;
+ private final ScannerOpts scanOpts;
+ private final BatchWriterOpts bwOpts;
+ private final AccumuloClient client;
+ private final String tableName;
+ private final Authorizations auths;
+ private final ColumnVisibility visibility;
private static class CountValue {
int dirCount = 0;
@@ -100,7 +100,7 @@
}
private int findMaxDepth(Scanner scanner, int min, int mid, int max) {
- // check to see if the mid point exist
+ // check to see if the mid-point exist
if (max < min)
return -1;
diff --git a/src/main/java/org/apache/accumulo/examples/dirlist/Ingest.java b/src/main/java/org/apache/accumulo/examples/dirlist/Ingest.java
index d5f3b35..47794a1 100644
--- a/src/main/java/org/apache/accumulo/examples/dirlist/Ingest.java
+++ b/src/main/java/org/apache/accumulo/examples/dirlist/Ingest.java
@@ -68,7 +68,7 @@
if (path.equals("/"))
path = "";
Mutation m = new Mutation(QueryUtil.getRow(path));
- Text colf = null;
+ Text colf;
if (isDir)
colf = QueryUtil.DIR_COLF;
else
diff --git a/src/main/java/org/apache/accumulo/examples/dirlist/QueryUtil.java b/src/main/java/org/apache/accumulo/examples/dirlist/QueryUtil.java
index 28d4f53..7be97de 100644
--- a/src/main/java/org/apache/accumulo/examples/dirlist/QueryUtil.java
+++ b/src/main/java/org/apache/accumulo/examples/dirlist/QueryUtil.java
@@ -39,9 +39,9 @@
* and performing single wild card searches on file or directory names.
*/
public class QueryUtil {
- private AccumuloClient client;
- private String tableName;
- private Authorizations auths;
+ private final AccumuloClient client;
+ private final String tableName;
+ private final Authorizations auths;
public static final Text DIR_COLF = new Text("dir");
public static final Text FORWARD_PREFIX = new Text("f");
public static final Text REVERSE_PREFIX = new Text("r");
@@ -171,7 +171,7 @@
name = name.substring(name.lastIndexOf("/") + 1);
String type = getType(e.getKey().getColumnFamily());
if (!fim.containsKey(name)) {
- fim.put(name, new TreeMap<String,String>());
+ fim.put(name, new TreeMap<>());
fim.get(name).put("fullname", e.getKey().getRow().toString().substring(3));
}
fim.get(name).put(type + e.getKey().getColumnQualifier().toString() + ":"
@@ -202,7 +202,7 @@
* beginning or end
*/
public Iterable<Entry<Key,Value>> singleRestrictedWildCardSearch(String exp) throws Exception {
- if (exp.indexOf("/") >= 0)
+ if (exp.contains("/"))
throw new Exception("this method only works with unqualified names");
Scanner scanner = client.createScanner(tableName, auths);
@@ -214,7 +214,7 @@
System.out.println("executing ending wildcard search for " + exp);
exp = exp.substring(0, exp.length() - 1);
scanner.setRange(Range.prefix(getForwardIndex(exp)));
- } else if (exp.indexOf("*") >= 0) {
+ } else if (exp.contains("*")) {
throw new Exception("this method only works for beginning or ending wild cards");
} else {
return exactTermSearch(exp);
diff --git a/src/main/java/org/apache/accumulo/examples/dirlist/Viewer.java b/src/main/java/org/apache/accumulo/examples/dirlist/Viewer.java
index ea28179..6cfe513 100644
--- a/src/main/java/org/apache/accumulo/examples/dirlist/Viewer.java
+++ b/src/main/java/org/apache/accumulo/examples/dirlist/Viewer.java
@@ -62,8 +62,8 @@
JScrollPane dataPane;
public static class NodeInfo {
- private String name;
- private Map<String,String> data;
+ private final String name;
+ private final Map<String,String> data;
public NodeInfo(String name, Map<String,String> data) {
this.name = name;
diff --git a/src/main/java/org/apache/accumulo/examples/filedata/CharacterHistogram.java b/src/main/java/org/apache/accumulo/examples/filedata/CharacterHistogram.java
index e83bed2..26bc73e 100644
--- a/src/main/java/org/apache/accumulo/examples/filedata/CharacterHistogram.java
+++ b/src/main/java/org/apache/accumulo/examples/filedata/CharacterHistogram.java
@@ -53,8 +53,7 @@
public void map(List<Entry<Key,Value>> k, InputStream v, Context context)
throws IOException, InterruptedException {
Long[] hist = new Long[256];
- for (int i = 0; i < hist.length; i++)
- hist[i] = 0L;
+ Arrays.fill(hist, 0L);
int b = v.read();
while (b >= 0) {
hist[b] += 1L;
diff --git a/src/main/java/org/apache/accumulo/examples/filedata/ChunkInputFormat.java b/src/main/java/org/apache/accumulo/examples/filedata/ChunkInputFormat.java
index 49f592d..3a29f8d 100644
--- a/src/main/java/org/apache/accumulo/examples/filedata/ChunkInputFormat.java
+++ b/src/main/java/org/apache/accumulo/examples/filedata/ChunkInputFormat.java
@@ -41,7 +41,7 @@
@Override
public RecordReader<List<Entry<Key,Value>>,InputStream> createRecordReader(InputSplit split,
TaskAttemptContext context) {
- return new RecordReaderBase<List<Entry<Key,Value>>,InputStream>() {
+ return new RecordReaderBase<>() {
private PeekingIterator<Entry<Key,Value>> peekingScannerIterator;
@Override
diff --git a/src/main/java/org/apache/accumulo/examples/filedata/ChunkInputStream.java b/src/main/java/org/apache/accumulo/examples/filedata/ChunkInputStream.java
index efe6c12..5c40101 100644
--- a/src/main/java/org/apache/accumulo/examples/filedata/ChunkInputStream.java
+++ b/src/main/java/org/apache/accumulo/examples/filedata/ChunkInputStream.java
@@ -45,7 +45,7 @@
protected int currentChunkSize;
protected boolean gotEndMarker;
- protected byte buf[];
+ protected byte[] buf;
protected int count;
protected int pos;
@@ -86,9 +86,7 @@
currentVis.add(currentKey.getColumnVisibility());
currentChunk = FileDataIngest.bytesToInt(currentKey.getColumnQualifier().getBytes(), 4);
currentChunkSize = FileDataIngest.bytesToInt(currentKey.getColumnQualifier().getBytes(), 0);
- gotEndMarker = false;
- if (buf.length == 0)
- gotEndMarker = true;
+ gotEndMarker = buf.length == 0;
if (currentChunk != 0) {
source = null;
throw new IOException("starting chunk number isn't 0 for " + currentKey.getRow());
@@ -136,8 +134,7 @@
}
// add the visibility to the list if it's not there
- if (!currentVis.contains(thisKey.getColumnVisibility()))
- currentVis.add(thisKey.getColumnVisibility());
+ currentVis.add(thisKey.getColumnVisibility());
// check to see if it is an identical chunk with a different visibility
if (thisKey.getColumnQualifier().equals(currentKey.getColumnQualifier())) {
diff --git a/src/main/java/org/apache/accumulo/examples/filedata/FileDataQuery.java b/src/main/java/org/apache/accumulo/examples/filedata/FileDataQuery.java
index daa6713..04a2a8d 100644
--- a/src/main/java/org/apache/accumulo/examples/filedata/FileDataQuery.java
+++ b/src/main/java/org/apache/accumulo/examples/filedata/FileDataQuery.java
@@ -40,7 +40,7 @@
*/
public class FileDataQuery {
List<Entry<Key,Value>> lastRefs;
- private ChunkInputStream cis;
+ private final ChunkInputStream cis;
Scanner scanner;
public FileDataQuery(AccumuloClient client, String tableName, Authorizations auths)
diff --git a/src/main/java/org/apache/accumulo/examples/filedata/VisibilityCombiner.java b/src/main/java/org/apache/accumulo/examples/filedata/VisibilityCombiner.java
index ec1814b..a3534ef 100644
--- a/src/main/java/org/apache/accumulo/examples/filedata/VisibilityCombiner.java
+++ b/src/main/java/org/apache/accumulo/examples/filedata/VisibilityCombiner.java
@@ -26,7 +26,7 @@
*/
public class VisibilityCombiner {
- private TreeSet<String> visibilities = new TreeSet<>();
+ private final TreeSet<String> visibilities = new TreeSet<>();
void add(ByteSequence cv) {
if (cv.length() == 0)
diff --git a/src/main/java/org/apache/accumulo/examples/mapreduce/NGramIngest.java b/src/main/java/org/apache/accumulo/examples/mapreduce/NGramIngest.java
index 2755858..b41c240 100644
--- a/src/main/java/org/apache/accumulo/examples/mapreduce/NGramIngest.java
+++ b/src/main/java/org/apache/accumulo/examples/mapreduce/NGramIngest.java
@@ -57,7 +57,7 @@
@Override
protected void map(LongWritable location, Text value, Context context)
throws IOException, InterruptedException {
- String parts[] = value.toString().split("\\t");
+ String[] parts = value.toString().split("\\t");
if (parts.length >= 4) {
Mutation m = new Mutation(parts[0]);
m.put(parts[1], String.format("%010d", Long.parseLong(parts[2])),
@@ -92,9 +92,9 @@
log.info("Creating table " + opts.tableName);
Common.createTableWithNamespace(client, opts.tableName);
SortedSet<Text> splits = new TreeSet<>();
- String numbers[] = "1 2 3 4 5 6 7 8 9".split("\\s");
- String lower[] = "a b c d e f g h i j k l m n o p q r s t u v w x y z".split("\\s");
- String upper[] = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z".split("\\s");
+ String[] numbers = "1 2 3 4 5 6 7 8 9".split("\\s");
+ String[] lower = "a b c d e f g h i j k l m n o p q r s t u v w x y z".split("\\s");
+ String[] upper = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z".split("\\s");
for (String[] array : new String[][] {numbers, lower, upper}) {
for (String s : array) {
splits.add(new Text(s));
diff --git a/src/main/java/org/apache/accumulo/examples/mapreduce/TeraSortIngest.java b/src/main/java/org/apache/accumulo/examples/mapreduce/TeraSortIngest.java
index 90973e2..95a2630 100644
--- a/src/main/java/org/apache/accumulo/examples/mapreduce/TeraSortIngest.java
+++ b/src/main/java/org/apache/accumulo/examples/mapreduce/TeraSortIngest.java
@@ -183,8 +183,8 @@
}
}
- private static String NUMSPLITS = "terasort.overridesplits";
- private static String NUMROWS = "terasort.numrows";
+ private static final String NUMSPLITS = "terasort.overridesplits";
+ private static final String NUMROWS = "terasort.numrows";
static class RandomGenerator {
private long seed = 0;
@@ -237,12 +237,12 @@
private int minvaluelength = 0;
private int maxvaluelength = 0;
- private Text key = new Text();
- private Text value = new Text();
+ private final Text key = new Text();
+ private final Text value = new Text();
private RandomGenerator rand;
private byte[] keyBytes; // = new byte[12];
- private byte[] spaces = " ".getBytes();
- private byte[][] filler = new byte[26][];
+ private final byte[] spaces = " ".getBytes();
+ private final byte[][] filler = new byte[26][];
{
for (int i = 0; i < 26; ++i) {
filler[i] = new byte[10];
@@ -255,7 +255,7 @@
/**
* Add a random key to the text
*/
- private Random random = new Random();
+ private final Random random = new Random();
private void addKey() {
int range = random.nextInt(maxkeylength - minkeylength + 1);
diff --git a/src/main/java/org/apache/accumulo/examples/mapreduce/UniqueColumns.java b/src/main/java/org/apache/accumulo/examples/mapreduce/UniqueColumns.java
index 696760a..c734c4d 100644
--- a/src/main/java/org/apache/accumulo/examples/mapreduce/UniqueColumns.java
+++ b/src/main/java/org/apache/accumulo/examples/mapreduce/UniqueColumns.java
@@ -44,7 +44,7 @@
private static final Text EMPTY = new Text();
public static class UMapper extends Mapper<Key,Value,Text,Text> {
- private Text temp = new Text();
+ private final Text temp = new Text();
private static final Text CF = new Text("cf:");
private static final Text CQ = new Text("cq:");
diff --git a/src/main/java/org/apache/accumulo/examples/shard/ContinuousQuery.java b/src/main/java/org/apache/accumulo/examples/shard/ContinuousQuery.java
index 5bac8ff..3e1b0b9 100644
--- a/src/main/java/org/apache/accumulo/examples/shard/ContinuousQuery.java
+++ b/src/main/java/org/apache/accumulo/examples/shard/ContinuousQuery.java
@@ -126,7 +126,7 @@
int numTerms) {
if (words.size() >= numTerms) {
Collections.shuffle(words, rand);
- Text docWords[] = new Text[numTerms];
+ Text[] docWords = new Text[numTerms];
for (int i = 0; i < docWords.length; i++) {
docWords[i] = words.get(i);
}
diff --git a/src/main/java/org/apache/accumulo/examples/shard/Index.java b/src/main/java/org/apache/accumulo/examples/shard/Index.java
index 598079a..bf675c4 100644
--- a/src/main/java/org/apache/accumulo/examples/shard/Index.java
+++ b/src/main/java/org/apache/accumulo/examples/shard/Index.java
@@ -82,7 +82,7 @@
StringBuilder sb = new StringBuilder();
- char data[] = new char[4096];
+ char[] data = new char[4096];
int len;
while ((len = fr.read(data)) != -1) {
sb.append(data, 0, len);
diff --git a/src/main/java/org/apache/accumulo/examples/shard/Query.java b/src/main/java/org/apache/accumulo/examples/shard/Query.java
index eaf4bd1..8991f93 100644
--- a/src/main/java/org/apache/accumulo/examples/shard/Query.java
+++ b/src/main/java/org/apache/accumulo/examples/shard/Query.java
@@ -52,16 +52,16 @@
@Parameter(names = {"--sample"},
description = "Do queries against sample, useful when sample is built using column qualifier")
- private boolean useSample = false;
+ private final boolean useSample = false;
@Parameter(names = {"--sampleCutoff"},
description = "Use sample data to determine if a query might return a number of documents over the cutoff. This check is per tablet.")
- private Integer sampleCutoff = null;
+ private final Integer sampleCutoff = null;
}
public static List<String> query(BatchScanner bs, List<String> terms, Integer cutoff) {
- Text columns[] = new Text[terms.size()];
+ Text[] columns = new Text[terms.size()];
int i = 0;
for (String term : terms) {
columns[i++] = new Text(term);
diff --git a/src/test/java/org/apache/accumulo/examples/constraints/AlphaNumKeyConstraintTest.java b/src/test/java/org/apache/accumulo/examples/constraints/AlphaNumKeyConstraintTest.java
index 5a1fcc0..dc2cece 100644
--- a/src/test/java/org/apache/accumulo/examples/constraints/AlphaNumKeyConstraintTest.java
+++ b/src/test/java/org/apache/accumulo/examples/constraints/AlphaNumKeyConstraintTest.java
@@ -28,7 +28,7 @@
public class AlphaNumKeyConstraintTest {
- private AlphaNumKeyConstraint ankc = new AlphaNumKeyConstraint();
+ private final AlphaNumKeyConstraint ankc = new AlphaNumKeyConstraint();
@Test
public void test() {
diff --git a/src/test/java/org/apache/accumulo/examples/constraints/NumericValueConstraintTest.java b/src/test/java/org/apache/accumulo/examples/constraints/NumericValueConstraintTest.java
index fec92bc..8e89545 100644
--- a/src/test/java/org/apache/accumulo/examples/constraints/NumericValueConstraintTest.java
+++ b/src/test/java/org/apache/accumulo/examples/constraints/NumericValueConstraintTest.java
@@ -28,7 +28,7 @@
public class NumericValueConstraintTest {
- private NumericValueConstraint nvc = new NumericValueConstraint();
+ private final NumericValueConstraint nvc = new NumericValueConstraint();
@Test
public void testCheck() {
diff --git a/src/test/java/org/apache/accumulo/examples/filedata/ChunkCombinerTest.java b/src/test/java/org/apache/accumulo/examples/filedata/ChunkCombinerTest.java
index 53da97d..e64f5fa 100644
--- a/src/test/java/org/apache/accumulo/examples/filedata/ChunkCombinerTest.java
+++ b/src/test/java/org/apache/accumulo/examples/filedata/ChunkCombinerTest.java
@@ -42,7 +42,7 @@
private Iterator<Entry<Key,Value>> iter;
private Entry<Key,Value> entry;
Collection<ByteSequence> columnFamilies;
- private SortedMap<Key,Value> map;
+ private final SortedMap<Key,Value> map;
private Range range;
@Override
diff --git a/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputFormatIT.java b/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputFormatIT.java
index 87ca328..5756493 100644
--- a/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputFormatIT.java
+++ b/src/test/java/org/apache/accumulo/examples/filedata/ChunkInputFormatIT.java
@@ -65,7 +65,7 @@
// track errors in the map reduce job; jobs insert a dummy error for the map and cleanup tasks (to
// ensure test correctness), so error tests should check to see if there is at least one error
// (could be more depending on the test) rather than zero
- private static Multimap<String,AssertionError> assertionErrors = ArrayListMultimap.create();
+ private static final Multimap<String,AssertionError> assertionErrors = ArrayListMultimap.create();
private static final Authorizations AUTHS = new Authorizations("A", "B", "C", "D");
@@ -126,7 +126,7 @@
byte[] b = new byte[20];
int read;
- try {
+ try (value) {
switch (count) {
case 0:
assertEquals(key.size(), 2);
@@ -149,8 +149,6 @@
}
} catch (AssertionError e) {
assertionErrors.put(table, e);
- } finally {
- value.close();
}
count++;
}