[OLINGO-568] Removed not necessary code and enums

This commit is contained in:
mibo 2015-11-09 20:33:05 +01:00
parent 43bc49f963
commit 96483ae559
3 changed files with 36 additions and 48 deletions

View File

@ -19,7 +19,7 @@
package org.apache.olingo.server.core.uri.parser.search; package org.apache.olingo.server.core.uri.parser.search;
public interface SearchQueryToken { 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(); Token getToken();
String getLiteral(); String getLiteral();

View File

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

View File

@ -287,15 +287,22 @@ public class SearchTokenizerTest {
Assert.assertEquals(AND, it.next().getToken()); Assert.assertEquals(AND, it.next().getToken());
Assert.assertEquals(WORD, 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") SearchValidator.init("abc AND ANDsomething")
.addExpected(WORD, AND, WORD).validate(); .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 @Test