[OLINGO-568] Minor code clean up

This commit is contained in:
Michael Bolz 2015-11-19 07:59:08 +01:00
parent ca7059c778
commit ee3501dd87
2 changed files with 21 additions and 33 deletions

View File

@ -54,9 +54,15 @@ public class SearchTokenizer {
protected static final char CHAR_CLOSE = ')'; protected static final char CHAR_CLOSE = ')';
protected static final char CHAR_OPEN = '('; protected static final char CHAR_OPEN = '(';
public State() {
}
public State(Token t) { public State(Token t) {
token = t; token = t;
} }
public State(Token t, boolean finished) {
this(t);
this.finished = finished;
}
protected abstract State nextChar(char c) throws SearchTokenizerException; protected abstract State nextChar(char c) throws SearchTokenizerException;
@ -91,7 +97,7 @@ public class SearchTokenizer {
return token; return token;
} }
public State close() { public State close() throws SearchTokenizerException {
return this; return this;
} }
@ -260,11 +266,9 @@ public class SearchTokenizer {
private static abstract class LiteralState extends State { private static abstract class LiteralState extends State {
protected final StringBuilder literal = new StringBuilder(); protected final StringBuilder literal = new StringBuilder();
public LiteralState() {
public LiteralState(Token t) { super();
super(t);
} }
public LiteralState(Token t, char c) throws SearchTokenizerException { public LiteralState(Token t, char c) throws SearchTokenizerException {
super(t); super(t);
init(c); init(c);
@ -296,10 +300,6 @@ public class SearchTokenizer {
} }
private class SearchExpressionState extends LiteralState { private class SearchExpressionState extends LiteralState {
public SearchExpressionState() {
super(null);
}
@Override @Override
public State nextChar(char c) throws SearchTokenizerException { public State nextChar(char c) throws SearchTokenizerException {
if (c == CHAR_OPEN) { if (c == CHAR_OPEN) {
@ -320,10 +320,6 @@ public class SearchTokenizer {
} }
private class SearchTermState extends LiteralState { private class SearchTermState extends LiteralState {
public SearchTermState() {
super(null);
}
@Override @Override
public State nextChar(char c) throws SearchTokenizerException { public State nextChar(char c) throws SearchTokenizerException {
if (c == CHAR_N) { if (c == CHAR_N) {
@ -428,7 +424,7 @@ public class SearchTokenizer {
} }
@Override @Override
public State close() { public State close() throws SearchTokenizerException {
if(closed) { if(closed) {
return finish(); return finish();
} }
@ -438,8 +434,7 @@ public class SearchTokenizer {
private class OpenState extends State { private class OpenState extends State {
public OpenState() { public OpenState() {
super(Token.OPEN); super(Token.OPEN, true);
finish();
} }
@Override @Override
@ -454,8 +449,7 @@ public class SearchTokenizer {
private class CloseState extends State { private class CloseState extends State {
public CloseState() { public CloseState() {
super(Token.CLOSE); super(Token.CLOSE, true);
finish();
} }
@Override @Override
@ -484,6 +478,13 @@ public class SearchTokenizer {
} }
return forbidden(c); return forbidden(c);
} }
@Override
public State close() throws SearchTokenizerException {
if(Token.NOT.name().equals(literal.toString())) {
return finish();
}
return super.close();
}
} }
private class AndState extends LiteralState { private class AndState extends LiteralState {
@ -533,10 +534,6 @@ public class SearchTokenizer {
// RWS 'OR' RWS searchExpr // RWS 'OR' RWS searchExpr
// RWS [ 'AND' RWS ] searchExpr // RWS [ 'AND' RWS ] searchExpr
private class BeforeSearchExpressionRwsState extends State { private class BeforeSearchExpressionRwsState extends State {
public BeforeSearchExpressionRwsState() {
super(null);
}
@Override @Override
public State nextChar(char c) throws SearchTokenizerException { public State nextChar(char c) throws SearchTokenizerException {
if (isWhitespace(c)) { if (isWhitespace(c)) {
@ -548,15 +545,11 @@ public class SearchTokenizer {
} }
private class BeforePhraseOrWordRwsState extends State { private class BeforePhraseOrWordRwsState extends State {
public BeforePhraseOrWordRwsState() {
super(null);
}
@Override @Override
public State nextChar(char c) throws SearchTokenizerException { public State nextChar(char c) throws SearchTokenizerException {
if (isWhitespace(c)) { if (isWhitespace(c)) {
return allowed(c); return allowed(c);
} else if (c == '"') { } else if (c == QUOTATION_MARK) {
return new SearchPhraseState(c); return new SearchPhraseState(c);
} else { } else {
return new SearchWordState(c); return new SearchWordState(c);
@ -565,10 +558,6 @@ public class SearchTokenizer {
} }
private class RwsState extends State { private class RwsState extends State {
public RwsState() {
super(null);
}
@Override @Override
public State nextChar(char c) throws SearchTokenizerException { public State nextChar(char c) throws SearchTokenizerException {
if (isWhitespace(c)) { if (isWhitespace(c)) {

View File

@ -420,10 +420,9 @@ public class SearchTokenizerTest {
@Test @Test
public void tokenizeInvalidQueryForParser() throws SearchTokenizerException { public void tokenizeInvalidQueryForParser() throws SearchTokenizerException {
// TokenizerValidator.init("NOT").validate(NOT);
TokenizerValidator.init("AND").validate(AND); TokenizerValidator.init("AND").validate(AND);
TokenizerValidator.init("OR").validate(OR); TokenizerValidator.init("OR").validate(OR);
TokenizerValidator.init("NOT").validate(NOT);
TokenizerValidator.init("NOT AND").validate(NOT, AND); TokenizerValidator.init("NOT AND").validate(NOT, AND);
TokenizerValidator.init("NOT OR").validate(NOT, OR); TokenizerValidator.init("NOT OR").validate(NOT, OR);
TokenizerValidator.init("NOT NOT").validate(NOT, NOT); TokenizerValidator.init("NOT NOT").validate(NOT, NOT);