knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kris...@apache.org
Subject [knox] branch master updated: KNOX-2024 - KnoxShellTable - Case Insensitive Operations with Col Names (#160)
Date Tue, 01 Oct 2019 18:21:30 GMT
This is an automated email from the ASF dual-hosted git repository.

krisden pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git


The following commit(s) were added to refs/heads/master by this push:
     new 579b43f  KNOX-2024 - KnoxShellTable - Case Insensitive Operations with Col Names
(#160)
579b43f is described below

commit 579b43fb1ccb29a420c21fca1895b8d166b727cd
Author: Larry McCay IV <46705753+lmccay4@users.noreply.github.com>
AuthorDate: Tue Oct 1 14:21:25 2019 -0400

    KNOX-2024 - KnoxShellTable - Case Insensitive Operations with Col Names (#160)
---
 .../knox/gateway/shell/table/KnoxShellTableFilter.java     | 14 +++++++++++---
 .../gateway/shell/table/KnoxShellTableFilterException.java |  3 +++
 .../knox/gateway/shell/table/KnoxShellTableFilterTest.java |  7 +++++++
 .../knox/gateway/shell/table/KnoxShellTableTest.java       |  2 +-
 4 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/table/KnoxShellTableFilter.java
b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/table/KnoxShellTableFilter.java
index 1dddee3..32bf9db 100644
--- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/table/KnoxShellTableFilter.java
+++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/table/KnoxShellTableFilter.java
@@ -24,15 +24,23 @@ import java.util.regex.Pattern;
 public class KnoxShellTableFilter {
 
   private KnoxShellTable tableToFilter;
-  private int index;
+  private int index = -1;
 
   public KnoxShellTableFilter table(KnoxShellTable table) {
     this.tableToFilter = table;
     return this;
   }
 
-  public KnoxShellTableFilter name(String name) {
-    index = tableToFilter == null ? -1 : tableToFilter.headers.indexOf(name);
+  public KnoxShellTableFilter name(String name) throws KnoxShellTableFilterException {
+    for (int i = 0; i < tableToFilter.headers.size(); i++) {
+      if (tableToFilter.headers.get(i).equalsIgnoreCase(name)) {
+        index = i;
+        break;
+      }
+    }
+    if (index == -1) {
+        throw new KnoxShellTableFilterException("Column name not found");
+    }
     return this;
   }
 
diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/table/KnoxShellTableFilterException.java
b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/table/KnoxShellTableFilterException.java
index 1966b8a..27c2a16 100644
--- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/table/KnoxShellTableFilterException.java
+++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/table/KnoxShellTableFilterException.java
@@ -23,4 +23,7 @@ class KnoxShellTableFilterException extends Exception {
     super("Error while filtering KnoxShellTable: " + e.getMessage());
   }
 
+  KnoxShellTableFilterException(String s) {
+      super("Error while filtering KnoxShellTable: " + s);
+    }
 }
diff --git a/gateway-shell/src/test/java/org/apache/knox/gateway/shell/table/KnoxShellTableFilterTest.java
b/gateway-shell/src/test/java/org/apache/knox/gateway/shell/table/KnoxShellTableFilterTest.java
index 701408b..b1f3736 100644
--- a/gateway-shell/src/test/java/org/apache/knox/gateway/shell/table/KnoxShellTableFilterTest.java
+++ b/gateway-shell/src/test/java/org/apache/knox/gateway/shell/table/KnoxShellTableFilterTest.java
@@ -50,6 +50,13 @@ public class KnoxShellTableFilterTest {
   }
 
   @Test
+  public void testNameMethod() throws KnoxShellTableFilterException, ParseException {
+    assertEquals(TABLE.filter().name("cOlUmN iNtEgEr").greaterThan(10).getRows().size(),
1);
+    assertEquals(TABLE.filter().name("COLUMN DOUBLE").greaterThan(25d).getRows().size(),
1);
+    assertEquals(TABLE.filter().name("column string").greaterThan("text20").getRows().size(),
2);
+  }
+
+  @Test
   public void testGreaterThanFilter() throws KnoxShellTableFilterException, ParseException
{
     assertEquals(TABLE.filter().name("Column Integer").greaterThan(5).getRows().size(), 3);
     assertEquals(TABLE.filter().name("Column Integer").greaterThan(25).getRows().size(),
2);
diff --git a/gateway-shell/src/test/java/org/apache/knox/gateway/shell/table/KnoxShellTableTest.java
b/gateway-shell/src/test/java/org/apache/knox/gateway/shell/table/KnoxShellTableTest.java
index 6b0c60c..c6c63e0 100644
--- a/gateway-shell/src/test/java/org/apache/knox/gateway/shell/table/KnoxShellTableTest.java
+++ b/gateway-shell/src/test/java/org/apache/knox/gateway/shell/table/KnoxShellTableTest.java
@@ -227,7 +227,7 @@ public class KnoxShellTableTest {
   }
 
   @Test
-  public void testFilterTable() {
+  public void testFilterTable() throws KnoxShellTableFilterException {
     KnoxShellTable table = new KnoxShellTable();
 
     table.header("Column A").header("Column B").header("Column C");


Mime
View raw message