fixes #772 added get method w/ default value

Project: http://git-wip-us.apache.org/repos/asf/incubator-fluo/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-fluo/commit/2f253dd5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-fluo/tree/2f253dd5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-fluo/diff/2f253dd5

Branch: refs/heads/master
Commit: 2f253dd59423f4861865e6bec717ab62081b5c90
Parents: 20d12a8
Author: Keith Turner <ke...@deenlo.com>
Authored: Thu Sep 15 14:44:21 2016 -0400
Committer: Keith Turner <ke...@deenlo.com>
Committed: Thu Sep 15 14:44:21 2016 -0400

----------------------------------------------------------------------
 .../apache/fluo/api/client/SnapshotBase.java    | 28 ++++++++++++++++++++
 1 file changed, 28 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/2f253dd5/modules/api/src/main/java/org/apache/fluo/api/client/SnapshotBase.java
----------------------------------------------------------------------
diff --git 
a/modules/api/src/main/java/org/apache/fluo/api/client/SnapshotBase.java 
b/modules/api/src/main/java/org/apache/fluo/api/client/SnapshotBase.java
index e08132a..723b9c7 100644
--- a/modules/api/src/main/java/org/apache/fluo/api/client/SnapshotBase.java
+++ b/modules/api/src/main/java/org/apache/fluo/api/client/SnapshotBase.java
@@ -44,6 +44,21 @@ public interface SnapshotBase {
   Bytes get(Bytes row, Column column);
 
   /**
+   * Retrieves the value (in {@link Bytes}) stored at a given row and {@link 
Column}. Returns the
+   * passed in defaultValue if does not exist.
+   * 
+   * @param defaultValue this will be returned if row+columns does not exists
+   */
+  default Bytes get(Bytes row, Column column, Bytes defaultValue) {
+    Bytes ret = get(row, column);
+    if (ret == null) {
+      return defaultValue;
+    }
+
+    return ret;
+  }
+
+  /**
    * Given a row and set of {@link Column}s, retrieves a map that contains the 
values at those
    * {@link Column}s. Only columns that exist will be returned in map.
    */
@@ -165,6 +180,19 @@ public interface SnapshotBase {
   }
 
   /**
+   * Wrapper for {@link #get(Bytes, Column, Bytes)} that uses Strings. All 
strings are encoded and
+   * decoded using UTF-8.
+   */
+  default String gets(CharSequence row, Column column, String defaultValue) {
+    Bytes val = get(Bytes.of(row), column);
+    if (val == null) {
+      return defaultValue;
+    }
+
+    return val.toString();
+  }
+
+  /**
    * Wrapper for {@link #get(Bytes, Set)} that uses Strings. All strings are 
encoded and decoded
    * using UTF-8.
    */

Reply via email to