Skip to content

Commit e28937c

Browse files
#27: fixed sonar findings (#86)
* #27: fixed sonar findings
1 parent 2074111 commit e28937c

File tree

16 files changed

+98
-120
lines changed

16 files changed

+98
-120
lines changed

doc/changes/changes-4.0.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
* #76: Added `SELECT FROM VALUES ... AS` support.
1212
* #77: Added `SELECT FROM (SELECT ...)` support.
1313

14+
## Refactoring
15+
16+
* #27: Fix sonar findings.
17+
1418
## Dependency updates
1519

1620
* Added `org.sonatype.ossindex.maven:ossindex-maven-plugin:3.1.0`

src/main/java/com/exasol/datatype/type/IntervalDayToSecond.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.exasol.sql.ColumnDefinitionVisitor;
44

55
/**
6-
* This class implements the Exasol-proprietary data type interval day to second
6+
* This class implements the Exasol-proprietary data type interval day to second.
77
*/
88
public class IntervalDayToSecond implements DataType {
99
private static final String NAME = "INTERVAL DAY(%s) TO SECOND(%s)";
@@ -48,7 +48,7 @@ public int getYearPrecision() {
4848
}
4949

5050
/**
51-
* @return millisecond precisiom
51+
* @return millisecond precision
5252
*/
5353
public int getMillisecondPrecision() {
5454
return this.millisecondPrecision;

src/main/java/com/exasol/datatype/value/IntervalDayToSecond.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* This is also the recommended way to represent the interval values in other systems which do
2727
* not natively support this data type.
2828
*/
29+
@java.lang.SuppressWarnings("squid:S4784") //regular expression is safe here
2930
public final class IntervalDayToSecond extends AbstractInterval {
3031
private static final int SIGN_MATCHING_GROUP = 1;
3132
private static final int DAYS_MATCHING_GROUP = 2;

src/main/java/com/exasol/datatype/value/IntervalYearToMonth.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* also the recommended way to represent the interval values in other systems which do not
2424
* natively support this data type.
2525
*/
26+
@java.lang.SuppressWarnings("squid:S4784") //regular expression is safe here
2627
public final class IntervalYearToMonth extends AbstractInterval {
2728
private static final int SIGN_MATCHING_GROUP = 1;
2829
private static final int YEARS_MATCHING_GROUP = 2;

src/main/java/com/exasol/sql/dql/select/rendering/SelectRenderer.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,22 @@ public void visit(final OrderByClause orderByClause) {
105105
appendKeyWord(" ORDER BY ");
106106
appendListOfValueExpressions(orderByClause.getColumnReferences());
107107
final Boolean desc = orderByClause.getDesc();
108-
appendStringDependingOnBoolean(desc, " DESC", " ASC");
108+
if (desc != null) {
109+
appendStringDependingOnBoolean(desc, " DESC", " ASC");
110+
}
109111
final Boolean nullsFirst = orderByClause.getNullsFirst();
110-
appendStringDependingOnBoolean(nullsFirst, " NULLS FIRST", " NULLS LAST");
112+
if (nullsFirst != null) {
113+
appendStringDependingOnBoolean(nullsFirst, " NULLS FIRST", " NULLS LAST");
114+
}
111115
setLastVisited(orderByClause);
112116
}
113117

114-
private void appendStringDependingOnBoolean(final Boolean booleanValue, final String string1,
118+
private void appendStringDependingOnBoolean(final boolean booleanValue, final String string1,
115119
final String string2) {
116-
if (booleanValue != null) {
117-
if (booleanValue) {
118-
appendKeyWord(string1);
119-
} else {
120-
appendKeyWord(string2);
121-
}
120+
if (booleanValue) {
121+
appendKeyWord(string1);
122+
} else {
123+
appendKeyWord(string2);
122124
}
123125
}
124126

src/main/java/com/exasol/sql/expression/rendering/AbstractExpressionRenderer.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ protected void appendAutoQuoted(final String identifier) {
6161
}
6262

6363
protected void appendCommaWhenNeeded(final ValueExpression valueExpression) {
64-
if (this.lastVisited != null && !(valueExpression.getParent() instanceof BinaryArithmeticExpression)) {
65-
if (this.lastVisited.isSibling(valueExpression) || (valueExpression.getParent() != this.lastVisited
66-
&& this.lastVisited.getClass().equals(valueExpression.getClass()))) {
67-
append(", ");
68-
}
64+
if ((this.lastVisited != null && !(valueExpression.getParent() instanceof BinaryArithmeticExpression))
65+
&& (this.lastVisited.isSibling(valueExpression) || (valueExpression.getParent() != this.lastVisited
66+
&& this.lastVisited.getClass().equals(valueExpression.getClass())))) {
67+
append(", ");
6968
}
7069
}
7170

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
package com.exasol.util;
22

3-
import java.util.*;
3+
import java.util.Arrays;
4+
import java.util.List;
45

56
/**
67
* This is an abstract base class for nodes in a tree structure.
78
*/
8-
public abstract class AbstractBottomUpTreeNode implements TreeNode {
9-
private TreeNode parent = null;
10-
private final List<TreeNode> children;
11-
12-
/**
13-
* Create a new instance of a {@link AbstractBottomUpTreeNode} that serves as leaf node for a tree.
14-
*/
15-
public AbstractBottomUpTreeNode() {
16-
this.children = Collections.emptyList();
17-
}
18-
9+
public abstract class AbstractBottomUpTreeNode extends AbstractTree {
1910
/**
2011
* Create a new instance of a {@link AbstractBottomUpTreeNode}.
2112
*
@@ -68,49 +59,14 @@ public TreeNode getRoot() {
6859
}
6960
}
7061

71-
@Override
72-
public TreeNode getParent() {
73-
return this.parent;
74-
}
75-
7662
@Override
7763
public void addChild(final TreeNode child) {
7864
throw new UnsupportedOperationException("Node \"" + child.toString()
7965
+ "\" can only be added as child node in parent constructor in a bottom-up tree.");
8066
}
8167

82-
@Override
83-
public List<TreeNode> getChildren() {
84-
return this.children;
85-
}
86-
87-
@Override
88-
public TreeNode getChild(final int index) {
89-
return this.children.get(index);
90-
}
91-
92-
@Override
93-
public boolean isRoot() {
94-
return (this == getRoot());
95-
}
96-
97-
@Override
98-
public boolean isChild() {
99-
return (this.parent != null);
100-
}
101-
102-
@Override
103-
public boolean isSibling(final TreeNode node) {
104-
return (this.parent != null) && (this.getParent().getChildren().contains(node));
105-
}
106-
10768
@Override
10869
public void setParent(final TreeNode parent) {
10970
this.parent = parent;
11071
}
111-
112-
@Override
113-
public boolean isFirstSibling() {
114-
return (this.parent != null) && (this.getParent().getChild(0) == this);
115-
}
11672
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.exasol.util;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
/**
7+
* An abstract base for {@link TreeNode} implementations.
8+
*/
9+
public abstract class AbstractTree implements TreeNode {
10+
protected TreeNode parent = null;
11+
protected List<TreeNode> children = new ArrayList<>();
12+
13+
@Override
14+
public TreeNode getParent() {
15+
return this.parent;
16+
}
17+
18+
@Override
19+
public List<TreeNode> getChildren() {
20+
return this.children;
21+
}
22+
23+
@Override
24+
public TreeNode getChild(final int index) {
25+
return this.children.get(index);
26+
}
27+
28+
@Override
29+
public boolean isRoot() {
30+
return (this == getRoot());
31+
}
32+
33+
@Override
34+
public boolean isChild() {
35+
return (this.parent != null);
36+
}
37+
38+
@Override
39+
public boolean isFirstSibling() {
40+
return (this.parent != null) && (this.getParent().getChild(0) == this);
41+
}
42+
43+
@Override
44+
public boolean isSibling(final TreeNode node) {
45+
return (this.parent != null) && (this.getParent().getChildren().contains(node));
46+
}
47+
}
Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
package com.exasol.util;
22

3-
import java.util.ArrayList;
4-
import java.util.List;
5-
63
/**
74
* This is an abstract base class for nodes in a tree structure.
85
*/
9-
public abstract class AbstractTreeNode implements TreeNode {
6+
public abstract class AbstractTreeNode extends AbstractTree {
107
private TreeNode root;
11-
private TreeNode parent;
12-
private final List<TreeNode> children = new ArrayList<>();
138

149
/**
1510
* Create a new instance of a {@link AbstractTreeNode} that serves as root for a tree.
@@ -43,44 +38,9 @@ public TreeNode getRoot() {
4338
return this.root;
4439
}
4540

46-
@Override
47-
public TreeNode getParent() {
48-
return this.parent;
49-
}
50-
5141
@Override
5242
public void addChild(final TreeNode child) {
5343
this.children.add(child);
5444
child.setParent(this);
5545
}
56-
57-
@Override
58-
public List<TreeNode> getChildren() {
59-
return this.children;
60-
}
61-
62-
@Override
63-
public TreeNode getChild(final int index) {
64-
return this.children.get(index);
65-
}
66-
67-
@Override
68-
public boolean isRoot() {
69-
return (this == getRoot());
70-
}
71-
72-
@Override
73-
public boolean isChild() {
74-
return (this.parent != null);
75-
}
76-
77-
@Override
78-
public boolean isFirstSibling() {
79-
return (this.parent != null) && (this.getParent().getChild(0) == this);
80-
}
81-
82-
@Override
83-
public boolean isSibling(final TreeNode node) {
84-
return (this.parent != null) && (this.getParent().getChildren().contains(node));
85-
}
8646
}

src/test/java/com/exasol/sql/dml/merge/MatchedClauseTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import org.junit.jupiter.api.BeforeEach;
88
import org.junit.jupiter.api.Test;
99

10-
public class MatchedClauseTest {
10+
class MatchedClauseTest {
1111
private MatchedClause matched;
1212

1313
@BeforeEach

0 commit comments

Comments
 (0)