From 52598143ca9a5d0c3088bcc272217e5827de5867 Mon Sep 17 00:00:00 2001
From: "Robert J. Moore" <Robert.J.Moore@allanbank.com>
Date: Sun, 8 Nov 2015 19:10:07 -0500
Subject: [PATCH] [redis] Checkstyle updates for the Redis binding.

---
 redis/pom.xml                                 |  24 +++
 .../java/com/yahoo/ycsb/db/RedisClient.java   | 192 +++++++++---------
 .../java/com/yahoo/ycsb/db/package-info.java  |  22 ++
 3 files changed, 146 insertions(+), 92 deletions(-)
 create mode 100644 redis/src/main/java/com/yahoo/ycsb/db/package-info.java

diff --git a/redis/pom.xml b/redis/pom.xml
index 0d1de45d..c374869c 100644
--- a/redis/pom.xml
+++ b/redis/pom.xml
@@ -42,4 +42,28 @@ LICENSE file.
       <scope>provided</scope>
     </dependency>
   </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+        <version>2.15</version>
+        <configuration>
+          <consoleOutput>true</consoleOutput>
+          <configLocation>../checkstyle.xml</configLocation>
+          <failOnViolation>true</failOnViolation>
+          <failsOnError>true</failsOnError>
+        </configuration>
+        <executions>
+          <execution>
+            <id>validate</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>checkstyle</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
 </project>
diff --git a/redis/src/main/java/com/yahoo/ycsb/db/RedisClient.java b/redis/src/main/java/com/yahoo/ycsb/db/RedisClient.java
index 8d0d4e2a..fbcfcb0a 100644
--- a/redis/src/main/java/com/yahoo/ycsb/db/RedisClient.java
+++ b/redis/src/main/java/com/yahoo/ycsb/db/RedisClient.java
@@ -23,6 +23,7 @@
  */
 
 package com.yahoo.ycsb.db;
+
 import com.yahoo.ycsb.ByteIterator;
 import com.yahoo.ycsb.DB;
 import com.yahoo.ycsb.DBException;
@@ -39,111 +40,118 @@ import java.util.Properties;
 import java.util.Set;
 import java.util.Vector;
 
+/**
+ * YCSB binding for <a href="http://redis.io/">Redis</a>.
+ *
+ * See {@code redis/README.md} for details.
+ */
 public class RedisClient extends DB {
 
-    private Jedis jedis;
+  private Jedis jedis;
 
-    public static final String HOST_PROPERTY = "redis.host";
-    public static final String PORT_PROPERTY = "redis.port";
-    public static final String PASSWORD_PROPERTY = "redis.password";
+  public static final String HOST_PROPERTY = "redis.host";
+  public static final String PORT_PROPERTY = "redis.port";
+  public static final String PASSWORD_PROPERTY = "redis.password";
 
-    public static final String INDEX_KEY = "_indices";
+  public static final String INDEX_KEY = "_indices";
 
-    public void init() throws DBException {
-        Properties props = getProperties();
-        int port;
+  public void init() throws DBException {
+    Properties props = getProperties();
+    int port;
 
-        String portString = props.getProperty(PORT_PROPERTY);
-        if (portString != null) {
-            port = Integer.parseInt(portString);
-        }
-        else {
-            port = Protocol.DEFAULT_PORT;
-        }
-        String host = props.getProperty(HOST_PROPERTY);
-
-        jedis = new Jedis(host, port);
-        jedis.connect();
-
-        String password = props.getProperty(PASSWORD_PROPERTY);
-        if (password != null) {
-            jedis.auth(password);
-        }
+    String portString = props.getProperty(PORT_PROPERTY);
+    if (portString != null) {
+      port = Integer.parseInt(portString);
+    } else {
+      port = Protocol.DEFAULT_PORT;
     }
+    String host = props.getProperty(HOST_PROPERTY);
 
-    public void cleanup() throws DBException {
-        jedis.disconnect();
-    }
+    jedis = new Jedis(host, port);
+    jedis.connect();
 
-    /* Calculate a hash for a key to store it in an index.  The actual return
-     * value of this function is not interesting -- it primarily needs to be
-     * fast and scattered along the whole space of doubles.  In a real world
-     * scenario one would probably use the ASCII values of the keys.
-     */
-    private double hash(String key) {
-        return key.hashCode();
+    String password = props.getProperty(PASSWORD_PROPERTY);
+    if (password != null) {
+      jedis.auth(password);
     }
-
-    //XXX jedis.select(int index) to switch to `table`
-
-    @Override
-    public Status read(String table, String key, Set<String> fields,
-            HashMap<String, ByteIterator> result) {
-        if (fields == null) {
-            StringByteIterator.putAllAsByteIterators(result, jedis.hgetAll(key));
-        }
-        else {
-            String[] fieldArray = (String[])fields.toArray(new String[fields.size()]);
-            List<String> values = jedis.hmget(key, fieldArray);
-
-            Iterator<String> fieldIterator = fields.iterator();
-            Iterator<String> valueIterator = values.iterator();
-
-            while (fieldIterator.hasNext() && valueIterator.hasNext()) {
-                result.put(fieldIterator.next(),
-			   new StringByteIterator(valueIterator.next()));
-            }
-            assert !fieldIterator.hasNext() && !valueIterator.hasNext();
-        }
-        return result.isEmpty() ? Status.ERROR : Status.OK;
+  }
+
+  public void cleanup() throws DBException {
+    jedis.disconnect();
+  }
+
+  /*
+   * Calculate a hash for a key to store it in an index. The actual return value
+   * of this function is not interesting -- it primarily needs to be fast and
+   * scattered along the whole space of doubles. In a real world scenario one
+   * would probably use the ASCII values of the keys.
+   */
+  private double hash(String key) {
+    return key.hashCode();
+  }
+
+  // XXX jedis.select(int index) to switch to `table`
+
+  @Override
+  public Status read(String table, String key, Set<String> fields,
+      HashMap<String, ByteIterator> result) {
+    if (fields == null) {
+      StringByteIterator.putAllAsByteIterators(result, jedis.hgetAll(key));
+    } else {
+      String[] fieldArray =
+          (String[]) fields.toArray(new String[fields.size()]);
+      List<String> values = jedis.hmget(key, fieldArray);
+
+      Iterator<String> fieldIterator = fields.iterator();
+      Iterator<String> valueIterator = values.iterator();
+
+      while (fieldIterator.hasNext() && valueIterator.hasNext()) {
+        result.put(fieldIterator.next(),
+            new StringByteIterator(valueIterator.next()));
+      }
+      assert !fieldIterator.hasNext() && !valueIterator.hasNext();
     }
-
-    @Override
-    public Status insert(String table, String key, HashMap<String, ByteIterator> values) {
-        if (jedis.hmset(key, StringByteIterator.getStringMap(values)).equals("OK")) {
-            jedis.zadd(INDEX_KEY, hash(key), key);
-            return Status.OK;
-        }
-        return Status.ERROR;
-    }
-
-    @Override
-    public Status delete(String table, String key) {
-        return jedis.del(key) == 0
-            && jedis.zrem(INDEX_KEY, key) == 0
-               ? Status.ERROR : Status.OK;
+    return result.isEmpty() ? Status.ERROR : Status.OK;
+  }
+
+  @Override
+  public Status insert(String table, String key,
+      HashMap<String, ByteIterator> values) {
+    if (jedis.hmset(key, StringByteIterator.getStringMap(values))
+        .equals("OK")) {
+      jedis.zadd(INDEX_KEY, hash(key), key);
+      return Status.OK;
     }
-
-    @Override
-    public Status update(String table, String key, HashMap<String, ByteIterator> values) {
-        return jedis.hmset(key, StringByteIterator.getStringMap(values)).equals("OK") ? 
-            Status.OK : Status.ERROR;
+    return Status.ERROR;
+  }
+
+  @Override
+  public Status delete(String table, String key) {
+    return jedis.del(key) == 0 && jedis.zrem(INDEX_KEY, key) == 0 ? Status.ERROR
+        : Status.OK;
+  }
+
+  @Override
+  public Status update(String table, String key,
+      HashMap<String, ByteIterator> values) {
+    return jedis.hmset(key, StringByteIterator.getStringMap(values))
+        .equals("OK") ? Status.OK : Status.ERROR;
+  }
+
+  @Override
+  public Status scan(String table, String startkey, int recordcount,
+      Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
+    Set<String> keys = jedis.zrangeByScore(INDEX_KEY, hash(startkey),
+        Double.POSITIVE_INFINITY, 0, recordcount);
+
+    HashMap<String, ByteIterator> values;
+    for (String key : keys) {
+      values = new HashMap<String, ByteIterator>();
+      read(table, key, fields, values);
+      result.add(values);
     }
 
-    @Override
-    public Status scan(String table, String startkey, int recordcount,
-            Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
-        Set<String> keys = jedis.zrangeByScore(INDEX_KEY, hash(startkey),
-                                Double.POSITIVE_INFINITY, 0, recordcount);
-
-        HashMap<String, ByteIterator> values;
-        for (String key : keys) {
-            values = new HashMap<String, ByteIterator>();
-            read(table, key, fields, values);
-            result.add(values);
-        }
-
-        return Status.OK;
-    }
+    return Status.OK;
+  }
 
 }
diff --git a/redis/src/main/java/com/yahoo/ycsb/db/package-info.java b/redis/src/main/java/com/yahoo/ycsb/db/package-info.java
new file mode 100644
index 00000000..d000d6c8
--- /dev/null
+++ b/redis/src/main/java/com/yahoo/ycsb/db/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2014, Yahoo!, Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you
+ * may not use this file except in compliance with the License. You
+ * may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License. See accompanying
+ * LICENSE file.
+ */
+
+/**
+ * The YCSB binding for <a href="http://redis.io/">Redis</a>.
+ */
+package com.yahoo.ycsb.db;
+
-- 
GitLab