Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ViewExpressionToStringTest {

@Test
public void testTimseriesOperand() {
String fullPath = new String("root.db.device.s01");
String fullPath = "root.db.device.s01";
TimeSeriesViewOperand timeSeriesViewOperand = new TimeSeriesViewOperand(fullPath);
Assert.assertEquals(fullPath, timeSeriesViewOperand.toString());
Assert.assertEquals(fullPath, timeSeriesViewOperand.toString(true));
Expand All @@ -55,8 +55,8 @@ public void testAdditionViewExpression() {
AdditionViewExpression add =
new AdditionViewExpression(timeSeriesViewOperand, constantViewOperand);

String expectedRoot = new String("root.db.device.s01 + 2");
String expectedNotRoot = new String("(root.db.device.s01 + 2)");
String expectedRoot = "root.db.device.s01 + 2";
String expectedNotRoot = "(root.db.device.s01 + 2)";
Assert.assertEquals(expectedRoot, add.toString());
Assert.assertEquals(expectedRoot, add.toString(true));
Assert.assertEquals(expectedNotRoot, add.toString(false));
Expand All @@ -70,8 +70,8 @@ public void testTwoBinaryExpression() {
TimeSeriesViewOperand ts2 = new TimeSeriesViewOperand("root.ln.d.s01");
MultiplicationViewExpression multiplication = new MultiplicationViewExpression(add, ts2);

String expectedRoot = new String("(root.db.device.s01 + 2) * root.ln.d.s01");
String expectedNotRoot = new String("((root.db.device.s01 + 2) * root.ln.d.s01)");
String expectedRoot = "(root.db.device.s01 + 2) * root.ln.d.s01";
String expectedNotRoot = "((root.db.device.s01 + 2) * root.ln.d.s01)";
Assert.assertEquals(expectedRoot, multiplication.toString());
Assert.assertEquals(expectedRoot, multiplication.toString(true));
Assert.assertEquals(expectedNotRoot, multiplication.toString(false));
Expand All @@ -82,8 +82,8 @@ public void testFunctionViewExpression01() {
String functionName = "func";
FunctionViewExpression func = new FunctionViewExpression(functionName);

String expectedRoot = new String("func()");
String expectedNotRoot = new String("func()");
String expectedRoot = "func()";
String expectedNotRoot = "func()";
Assert.assertEquals(expectedRoot, func.toString());
Assert.assertEquals(expectedRoot, func.toString(true));
Assert.assertEquals(expectedNotRoot, func.toString(false));
Expand All @@ -103,8 +103,8 @@ public void testFunctionViewExpression02() {

FunctionViewExpression func = new FunctionViewExpression(functionName, keys, values, exps);

String expectedRoot = new String("MAX(root.db.device.s01 + 2, root.ln.d.s01)");
String expectedNotRoot = new String("MAX(root.db.device.s01 + 2, root.ln.d.s01)");
String expectedRoot = "MAX(root.db.device.s01 + 2, root.ln.d.s01)";
String expectedNotRoot = "MAX(root.db.device.s01 + 2, root.ln.d.s01)";
Assert.assertEquals(expectedRoot, func.toString());
Assert.assertEquals(expectedRoot, func.toString(true));
Assert.assertEquals(expectedNotRoot, func.toString(false));
Expand All @@ -121,8 +121,8 @@ public void testFunctionViewExpression03() {

FunctionViewExpression func = new FunctionViewExpression(functionName, keys, values, exps);

String expectedRoot = new String("CAST(type=INT32)(root.ln.d.s01)");
String expectedNotRoot = new String("CAST(type=INT32)(root.ln.d.s01)");
String expectedRoot = "CAST(root.ln.d.s01, type=INT32)";
String expectedNotRoot = "CAST(root.ln.d.s01, type=INT32)";
Assert.assertEquals(expectedRoot, func.toString());
Assert.assertEquals(expectedRoot, func.toString(true));
Assert.assertEquals(expectedNotRoot, func.toString(false));
Expand All @@ -139,8 +139,8 @@ public void testFunctionViewExpression04() {

FunctionViewExpression func = new FunctionViewExpression(functionName, keys, values, exps);

String expectedRoot = new String("CAST(type=INT32)(root.ln.d.s01)");
String expectedNotRoot = new String("CAST(type=INT32)(root.ln.d.s01)");
String expectedRoot = "CAST(root.ln.d.s01, type=INT32)";
String expectedNotRoot = "CAST(root.ln.d.s01, type=INT32)";
Assert.assertEquals(expectedRoot, func.toString());
Assert.assertEquals(expectedRoot, func.toString(true));
Assert.assertEquals(expectedNotRoot, func.toString(false));
Expand All @@ -158,10 +158,8 @@ public void testFunctionViewExpression05() {

FunctionViewExpression func = new FunctionViewExpression(functionName, keys, values, exps);

String expectedRoot =
new String("FUNC(type=INT32, key=value)(root.db.device.s01, root.ln.d.s01)");
String expectedNotRoot =
new String("FUNC(type=INT32, key=value)(root.db.device.s01, root.ln.d.s01)");
String expectedRoot = "FUNC(root.db.device.s01, root.ln.d.s01, type=INT32, key=value)";
String expectedNotRoot = "FUNC(root.db.device.s01, root.ln.d.s01, type=INT32, key=value)";
Assert.assertEquals(expectedRoot, func.toString());
Assert.assertEquals(expectedRoot, func.toString(true));
Assert.assertEquals(expectedNotRoot, func.toString(false));
Expand All @@ -174,8 +172,8 @@ public void testBetweenViewExpression() {
TimeSeriesViewOperand ts1 = new TimeSeriesViewOperand("root.db.device.s01");
BetweenViewExpression exp = new BetweenViewExpression(ts1, timestamp01, timestamp02);

String expectedRoot = new String("root.db.device.s01 BETWEEN TIMESTAMP AND TIMESTAMP");
String expectedNotRoot = new String("(root.db.device.s01 BETWEEN TIMESTAMP AND TIMESTAMP)");
String expectedRoot = "root.db.device.s01 BETWEEN TIMESTAMP AND TIMESTAMP";
String expectedNotRoot = "(root.db.device.s01 BETWEEN TIMESTAMP AND TIMESTAMP)";
Assert.assertEquals(expectedRoot, exp.toString());
Assert.assertEquals(expectedRoot, exp.toString(true));
Assert.assertEquals(expectedNotRoot, exp.toString(false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

public class FunctionViewExpression extends ViewExpression {

// region member variables and init functions
/** region member variables and init functions */
private final String functionName;

/**
Expand Down Expand Up @@ -70,8 +70,7 @@ public FunctionViewExpression(
}
} else {
String errorMsg =
String.format(
"Illegal parameters during FunctionExpression construction. Array length mismatch.");
"Illegal parameters during FunctionExpression construction. Array length mismatch.";
throw new RuntimeException(errorMsg);
}
this.expressions = expressions;
Expand Down Expand Up @@ -116,10 +115,7 @@ public ViewExpressionType getExpressionType() {
@Override
protected boolean isLeafOperandInternal() {
// if this expression has no children, return true; else return false.
if (this.expressions.size() == 0) {
return true;
}
return false;
return this.expressions.isEmpty();
}

@Override
Expand All @@ -131,8 +127,21 @@ public List<ViewExpression> getChildViewExpressions() {
public String toString(boolean isRoot) {
StringBuilder result = new StringBuilder(this.functionName);
int keyValueSize = this.functionAttributesKeyValueList.size();

result.append("(");
for (int i = 0; i < this.expressions.size(); i++) {
result.append(this.expressions.get(i).toString());
if (i + 1 >= this.expressions.size()) {
break;
}
result.append(", ");
}

if (this.functionAttributesKeyValueList.size() > 1) {
result.append("(");
if (!this.expressions.isEmpty()) {
result.append(", ");
}

for (int i = 0; i + 1 < keyValueSize; i += 2) {
result
.append(this.functionAttributesKeyValueList.get(i))
Expand All @@ -143,16 +152,8 @@ public String toString(boolean isRoot) {
}
result.append(", ");
}
result.append(")");
}
result.append("(");
for (int i = 0; i < this.expressions.size(); i++) {
result.append(this.expressions.get(i).toString());
if (i + 1 >= this.expressions.size()) {
break;
}
result.append(", ");
}

result.append(")");
return result.toString();
}
Expand Down