olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject [07/23] olingo-odata4 git commit: [OLINGO-568] Removed not necessary code and enums
Date Tue, 17 Nov 2015 15:04:17 GMT
[OLINGO-568] Removed not necessary code and enums


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/96483ae5
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/96483ae5
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/96483ae5

Branch: refs/heads/master
Commit: 96483ae559ea8d9dc0624b68876a4045102ba659
Parents: 43bc49f
Author: mibo <mibo@apache.org>
Authored: Mon Nov 9 20:33:05 2015 +0100
Committer: mibo <mibo@apache.org>
Committed: Mon Nov 9 20:33:05 2015 +0100

----------------------------------------------------------------------
 .../uri/parser/search/SearchQueryToken.java     |  2 +-
 .../core/uri/parser/search/SearchTokenizer.java | 61 +++++++-------------
 .../uri/parser/search/SearchTokenizerTest.java  | 21 ++++---
 3 files changed, 36 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96483ae5/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/search/SearchQueryToken.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/search/SearchQueryToken.java
b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/search/SearchQueryToken.java
index a08c1a2..eb1a009 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/search/SearchQueryToken.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/search/SearchQueryToken.java
@@ -19,7 +19,7 @@
 package org.apache.olingo.server.core.uri.parser.search;
 
 public interface SearchQueryToken {
-  enum Token {OPEN, BWS, RWS, TERM, SEARCH_EXPRESSION, NOT, AND, OR, WORD, PHRASE, CLOSE}
+  enum Token {OPEN, TERM, NOT, AND, OR, WORD, PHRASE, CLOSE}
 
   Token getToken();
   String getLiteral();

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96483ae5/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizer.java
b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizer.java
index f62e0f4..12af609 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizer.java
@@ -44,7 +44,6 @@ public class SearchTokenizer {
     private Token token = null;
     private boolean finished = false;
 
-    protected static final char EOF = 0x03;
     protected static final char QUOTATION_MARK = '\"';
     protected static final char CHAR_N = 'N';
     protected static final char CHAR_O = 'O';
@@ -82,8 +81,8 @@ public class SearchTokenizer {
       return token;
     }
 
-    public boolean close() {
-      return nextChar(EOF).isFinished();
+    public State close() {
+      return this;
     }
 
     static boolean isAllowedChar(final char character) {
@@ -114,10 +113,6 @@ public class SearchTokenizer {
           || character == '=';
     }
 
-    static boolean isEof(final char character) {
-      return character == EOF;
-    }
-
     //BWS =  *( SP / HTAB / "%20" / "%09" )  ; "bad" whitespace
     //RWS = 1*( SP / HTAB / "%20" / "%09" )  ; "required" whitespace
     static boolean isWhitespace(final char character) {
@@ -138,7 +133,7 @@ public class SearchTokenizer {
   }
 
   private static abstract class LiteralState extends State {
-    private final StringBuilder literal = new StringBuilder();
+    protected final StringBuilder literal = new StringBuilder();
     public LiteralState(Token t) {
       super(t);
     }
@@ -170,7 +165,7 @@ public class SearchTokenizer {
 
   private class SearchExpressionState extends LiteralState {
     public SearchExpressionState() {
-      super(Token.SEARCH_EXPRESSION);
+      super(null);
     }
     @Override
     public State nextChar(char c) {
@@ -180,19 +175,12 @@ public class SearchTokenizer {
         return new RwsImplicitAndState();
       } else if(c == CHAR_CLOSE) {
         return new CloseState();
-      } else if(isWhitespace(c)) {
-        return new AndState(c);
       } else {
         return new SearchTermState().init(c);
       }
     }
 
     @Override
-    public boolean close() {
-      return true;
-    }
-
-    @Override
     public State init(char c) {
       return nextChar(c);
     }
@@ -237,11 +225,14 @@ public class SearchTokenizer {
       } else if (isWhitespace(c)) {
         finish();
         return new RwsImplicitAndState();
-      } else if (isEof(c)) {
-        return finish();
       }
       return forbidden(c);
     }
+
+    @Override
+    public State close() {
+      return finish();
+    }
   }
 
   private class SearchPhraseState extends LiteralState {
@@ -254,7 +245,7 @@ public class SearchTokenizer {
 
     @Override
     public State nextChar(char c) {
-      if(isFinished() && !isEof(c)) {
+      if(isFinished()) {
         return new SearchExpressionState().init(c);
       } else if (isAllowedPhrase(c)) {
         return allowed(c);
@@ -272,8 +263,6 @@ public class SearchTokenizer {
           return new CloseState();
         }
         return allowed(c);
-      } else if (isEof(c)) {
-        return finish();
       }
       return forbidden(c);
     }
@@ -302,11 +291,7 @@ public class SearchTokenizer {
 
     @Override
     public State nextChar(char c) {
-      if (isEof(c)) {
-        return finish();
-      } else {
-        return new SearchExpressionState().init(c);
-      }
+      return new SearchExpressionState().init(c);
     }
   }
 
@@ -319,9 +304,9 @@ public class SearchTokenizer {
     }
     @Override
     public State nextChar(char c) {
-      if (getLiteral().length() == 1 && (c == CHAR_O)) {
+      if (getLiteral().length() == 1 && c == CHAR_O) {
         return allowed(c);
-      } else if (getLiteral().length() == 2 && (c == CHAR_T)) {
+      } else if (getLiteral().length() == 2 && c == CHAR_T) {
         return allowed(c);
       } else if(getLiteral().length() == 3 && isWhitespace(c)) {
         finish();
@@ -341,11 +326,11 @@ public class SearchTokenizer {
     }
     @Override
     public State nextChar(char c) {
-      if (getLiteral().length() == 1 && (c == CHAR_N)) {
+      if (literal.length() == 1 && c == CHAR_N) {
         return allowed(c);
-      } else if (getLiteral().length() == 2 && (c == CHAR_D)) {
+      } else if (literal.length() == 2 && c == CHAR_D) {
         return allowed(c);
-      } else if(getLiteral().length() == 3 && isWhitespace(c)) {
+      } else if(literal.length() == 3 && isWhitespace(c)) {
         finish();
         return new BeforeSearchExpressionRwsState();
       } else {
@@ -363,9 +348,9 @@ public class SearchTokenizer {
     }
     @Override
     public State nextChar(char c) {
-      if (getLiteral().length() == 1 && (c == CHAR_R)) {
+      if (literal.length() == 1 && (c == CHAR_R)) {
         return allowed(c);
-      } else if(getLiteral().length() == 2 && isWhitespace(c)) {
+      } else if(literal.length() == 2 && isWhitespace(c)) {
         finish();
         return new BeforeSearchExpressionRwsState();
       } else {
@@ -378,7 +363,7 @@ public class SearchTokenizer {
   // RWS [ 'AND' RWS ] searchExpr
   private class BeforeSearchExpressionRwsState extends State {
     public BeforeSearchExpressionRwsState() {
-      super(Token.RWS);
+      super(null);
     }
     @Override
     public State nextChar(char c) {
@@ -424,12 +409,8 @@ public class SearchTokenizer {
       state = next;
     }
 
-    if(state.close()) {
-     if(state.isFinished()) {
-       states.add(state);
-     }
-    } else {
-      throw new IllegalStateException("State: " + state + " not finished and list is: " +
states.toString());
+    if(state.close().isFinished()) {
+      states.add(state);
     }
 
     return states;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96483ae5/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java
index e53b6b2..29287cd 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java
@@ -287,15 +287,22 @@ public class SearchTokenizerTest {
     Assert.assertEquals(AND, it.next().getToken());
     Assert.assertEquals(WORD, it.next().getToken());
 
-    result = tokenizer.tokenize("abc OR orsomething");
-    log(result.toString());
-    it = result.iterator();
-    Assert.assertEquals(WORD, it.next().getToken());
-    Assert.assertEquals(OR, it.next().getToken());
-    Assert.assertEquals(WORD, it.next().getToken());
-
     SearchValidator.init("abc AND ANDsomething")
         .addExpected(WORD, AND, WORD).validate();
+
+    // FIXME (mibo): issue with implicit and
+//    SearchValidator.init("abc ANDsomething").enableLogging()
+//        .addExpected(WORD, AND, WORD).validate();
+
+//    SearchValidator.init("abc ORsomething")
+//        .addExpected(WORD, AND, WORD).validate();
+
+    SearchValidator.init("abc OR orsomething")
+        .addExpected(WORD, OR, WORD).validate();
+
+    SearchValidator.init("abc OR ORsomething")
+        .addExpected(WORD, OR, WORD).validate();
+
   }
 
   @Test


Mime
View raw message