Skip to content

Commit

Permalink
#27: Fixed Sonar findings.
Browse files Browse the repository at this point in the history
  • Loading branch information
redcatbear committed Feb 19, 2019
1 parent 7e5b884 commit d0418d4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/exasol/sql/dql/ValueTableRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ValueTableRow(final Fragment root, final ValueExpression... expressions)
*/
public ValueTableRow(final Fragment root, final String... values) {
super(root);
this.expressions = new ArrayList<ValueExpression>(values.length);
this.expressions = new ArrayList<>(values.length);
for (final String value : values) {
this.expressions.add(StringLiteral.of(value));
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/exasol/sql/expression/BooleanLiteral.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public static BooleanExpression of(final boolean value) {
* @return new {@link BooleanLiteral} instance
* @throws IllegalArgumentException in case the literal is not recognized.
*/
public static BooleanLiteral of(final String value) throws IllegalArgumentException {
public static BooleanLiteral of(final String value) {
return new BooleanLiteral(parse(value));
}

private static boolean parse(final String value) throws IllegalArgumentException {
private static boolean parse(final String value) {
if (value == null) {
throw new IllegalArgumentException("Unable to covert null value into a boolean value");
} else {
Expand All @@ -48,9 +48,10 @@ private static boolean parse(final String value) throws IllegalArgumentException
case "DISABLED":
case "0":
return false;
default:
throw new IllegalArgumentException("Unable to covert literal '" + value + "' into a boolean value");
}
}
throw new IllegalArgumentException("Unable to covert literal '" + value + "' into a boolean value");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.exasol.sql.expression.rendering;

import java.util.Stack;
import java.util.ArrayDeque;
import java.util.Deque;

import com.exasol.sql.expression.BooleanExpression;
import com.exasol.sql.expression.BooleanLiteral;
Expand All @@ -12,7 +13,7 @@
public class AbstractExpressionRenderer {
protected final StringRendererConfig config;
protected final StringBuilder builder = new StringBuilder();
protected final Stack<String> connectorStack = new Stack<>();
protected final Deque<String> connectorDeque = new ArrayDeque<>();

public AbstractExpressionRenderer(final StringRendererConfig config) {
this.config = config;
Expand All @@ -29,8 +30,8 @@ protected void connect(final BooleanExpression expression) {
}

private void appendConnector() {
if (!this.connectorStack.isEmpty()) {
appendKeyword(this.connectorStack.peek());
if (!this.connectorDeque.isEmpty()) {
appendKeyword(this.connectorDeque.peek());
}
}

Expand All @@ -46,10 +47,14 @@ protected void startParenthesis() {
this.builder.append("(");
}

protected void endParenthesis(final BooleanExpression expression) {
protected void endParenthesis() {
this.builder.append(")");
}

protected void append(final String string) {
this.builder.append(string);
}

/**
* Render expression to a string
*
Expand All @@ -58,8 +63,4 @@ protected void endParenthesis(final BooleanExpression expression) {
public String render() {
return this.builder.toString();
}

protected void append(final String string) {
this.builder.append(string);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public void visit(final Not not) {

@Override
public void leave(final Not not) {
endParenthesis(not);
endParenthesis();
}

@Override
public void visit(final And and) {
connect(and);
this.connectorStack.push(" AND ");
this.connectorDeque.push(" AND ");
if (!and.isRoot()) {
startParenthesis();
}
Expand All @@ -36,15 +36,15 @@ public void visit(final And and) {
@Override
public void leave(final And and) {
if (!and.isRoot()) {
endParenthesis(and);
endParenthesis();
}
this.connectorStack.pop();
this.connectorDeque.pop();
}

@Override
public void visit(final Or or) {
connect(or);
this.connectorStack.push(" OR ");
this.connectorDeque.push(" OR ");
if (!or.isRoot()) {
startParenthesis();
}
Expand All @@ -53,9 +53,9 @@ public void visit(final Or or) {
@Override
public void leave(final Or or) {
if (!or.isRoot()) {
endParenthesis(or);
endParenthesis();
}
this.connectorStack.pop();
this.connectorDeque.pop();
}

@Override
Expand Down Expand Up @@ -91,7 +91,7 @@ protected void appendOperand(final StringLiteral leftOperand) {
@Override
public void leave(final Comparison comparison) {
if (!comparison.isRoot()) {
endParenthesis(comparison);
endParenthesis();
}
}
}
8 changes: 3 additions & 5 deletions src/main/java/com/exasol/util/AbstractTreeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public abstract class AbstractTreeNode implements TreeNode {
private final List<TreeNode> children = new ArrayList<>();

/**
* Create a new instance of a {@link AbstractTreeNode} that serves as root for a
* tree.
* Create a new instance of a {@link AbstractTreeNode} that serves as root for a tree.
*/
public AbstractTreeNode() {
this.root = this;
Expand All @@ -25,10 +24,9 @@ public AbstractTreeNode() {
*
* @param parent the parent to which this node will be linked as a child
*
* @throws IllegalArgumentException if parent is <code>null</code> or parent and
* child are identical
* @throws IllegalArgumentException if parent is <code>null</code> or parent and child are identical
*/
public void setParent(final TreeNode parent) throws IllegalArgumentException {
public void setParent(final TreeNode parent) {
if (parent == null) {
throw new IllegalArgumentException("Parent tree node cannot be NULL.");
} else if (parent == this) {
Expand Down

0 comments on commit d0418d4

Please sign in to comment.