Skip to content

Commit

Permalink
[#693] Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
opatrascoiu committed Aug 20, 2024
1 parent 0c83933 commit 6ca816d
Show file tree
Hide file tree
Showing 94 changed files with 952 additions and 1,015 deletions.
26 changes: 13 additions & 13 deletions dmn-core/src/main/java/com/gs/dmn/ast/visitor/TraversalVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -719,31 +719,31 @@ private void visitTExpression(TExpression element, C context) {

visitTExpressionProperties(element, context);
if (element instanceof TContext) {
((TContext) element).accept(this, context);
element.accept(this, context);
} else if (element instanceof TDecisionTable) {
((TDecisionTable) element).accept(this, context);
element.accept(this, context);
} else if (element instanceof TFunctionDefinition) {
((TFunctionDefinition) element).accept(this, context);
element.accept(this, context);
} else if (element instanceof TInvocation) {
((TInvocation) element).accept(this, context);
element.accept(this, context);
} else if (element instanceof TList) {
((TList) element).accept(this, context);
element.accept(this, context);
} else if (element instanceof TLiteralExpression) {
((TLiteralExpression) element).accept(this, context);
element.accept(this, context);
} else if (element instanceof TRelation) {
((TRelation) element).accept(this, context);
element.accept(this, context);
} else if (element instanceof TUnaryTests) {
((TUnaryTests) element).accept(this, context);
element.accept(this, context);
} else if (element instanceof TConditional) {
((TConditional) element).accept(this, context);
element.accept(this, context);
} else if (element instanceof TFor) {
((TFor) element).accept(this, context);
element.accept(this, context);
} else if (element instanceof TFilter) {
((TFilter) element).accept(this, context);
element.accept(this, context);
} else if (element instanceof TEvery) {
((TEvery) element).accept(this, context);
element.accept(this, context);
} else if (element instanceof TSome) {
((TSome) element).accept(this, context);
element.accept(this, context);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import com.gs.dmn.transformation.basic.BasicDMNToNativeTransformer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -285,7 +285,7 @@ public Element<Type> visit(Context<Type> element, DMNContext context) {

// Derive type
ContextType type = new ContextType();
entries.forEach(e -> type.addMember(e.getKey().getKey(), Arrays.asList(), e.getExpression().getType()));
entries.forEach(e -> type.addMember(e.getKey().getKey(), Collections.emptyList(), e.getExpression().getType()));
element.setType(type);

return element;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import static com.gs.dmn.feel.analysis.syntax.ast.expression.function.ConversionKind.*;

public abstract class FunctionType implements com.gs.dmn.el.analysis.semantics.type.FunctionType {
public static final FunctionType ANY_FUNCTION = new FunctionType(Arrays.asList(), ANY) {
public static final FunctionType ANY_FUNCTION = new FunctionType(Collections.emptyList(), ANY) {
@Override
public boolean equivalentTo(Type other) {
return this == other;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public boolean equals(Object o) {

ItemDefinitionType that = (ItemDefinitionType) o;

if (name != null ? !name.equals(that.name) : that.name != null) return false;
if (modelName != null ? !modelName.equals(that.modelName) : that.modelName != null) return false;
if (!Objects.equals(name, that.name)) return false;
if (!Objects.equals(modelName, that.modelName)) return false;
if (!members.equals(that.members)) return false;
return aliases.equals(that.aliases);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.gs.dmn.feel.analysis.syntax.ast.expression.Expression;
import com.gs.dmn.feel.analysis.syntax.ast.expression.Iterator;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -51,7 +51,7 @@ public ForExpression<T> toNestedForExpression() {
} else {
Expression<T> newBody = this.body;
for(int i=this.iterators.size()-1; i>=0; i--) {
newBody = new ForExpression<>(Arrays.asList(this.iterators.get(i)), newBody);
newBody = new ForExpression<>(Collections.singletonList(this.iterators.get(i)), newBody);
}
return (ForExpression<T>) newBody;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@ public Element<T> visit(ContextEntry<T> element, C context) {

@Override
public Element<T> visit(ContextEntryKey<T> element, C context) {
if (element == null) {
return null;
}

return element;
}

Expand Down Expand Up @@ -429,46 +425,26 @@ public Element<T> visit(PositionalParameters<T> element, C context) {
//
@Override
public Element<T> visit(BooleanLiteral<T> element, C context) {
if (element == null) {
return null;
}

return element;
}

@Override
public Element<T> visit(DateTimeLiteral<T> element, C context) {
if (element == null) {
return null;
}

return element;
}

@Override
public Element<T> visit(NullLiteral<T> element, C context) {
if (element == null) {
return null;
}

return element;
}

@Override
public Element<T> visit(NumericLiteral<T> element, C context) {
if (element == null) {
return null;
}

return element;
}

@Override
public Element<T> visit(StringLiteral<T> element, C context) {
if (element == null) {
return null;
}

return element;
}

Expand All @@ -484,64 +460,36 @@ public Element<T> visit(ListLiteral<T> element, C context) {

@Override
public Element<T> visit(QualifiedName<T> element, C context) {
if (element == null) {
return null;
}

return element;
}

@Override
public Element<T> visit(Name<T> element, C context) {
if (element == null) {
return null;
}

return element;
}

@Override
public Element<T> visit(NamedTypeExpression<T> element, C context) {
if (element == null) {
return null;
}

return element;
}

@Override
public Element<T> visit(ContextTypeExpression<T> element, C context) {
if (element == null) {
return null;
}

return element;
}

@Override
public Element<T> visit(RangeTypeExpression<T> element, C context) {
if (element == null) {
return null;
}

return element;
}

@Override
public Element<T> visit(FunctionTypeExpression<T> element, C context) {
if (element == null) {
return null;
}

return element;
}

@Override
public Element<T> visit(ListTypeExpression<T> element, C context) {
if (element == null) {
return null;
}

return element;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ public Object visit(FilterExpression<Type> element, DMNContext context) {
Type filterType = element.getFilter().getType();
Object source = element.getSource().accept(this, context);
if (!(sourceType instanceof ListType)) {
source = Arrays.asList(source);
source = Collections.singletonList(source);
}
if (filterType == BooleanType.BOOLEAN) {
List<Object> result = new ArrayList<>();
Expand Down Expand Up @@ -1062,7 +1062,7 @@ private Object navigate(PathExpression<Type> element, Type sourceType, Object so
return evaluateRangeMember(source, member);
} else if (sourceType instanceof AnyType) {
// source is Context
List<String> aliases = Arrays.asList();
List<String> aliases = Collections.emptyList();
return ((com.gs.dmn.runtime.Context) source).get(member, aliases.toArray());
} else {
this.errorHandler.reportError(String.format("Cannot evaluate '%s'.", element));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ private Object evaluateDefaultValue(TDRGElement element, TDecisionTable decision
// Return result
if (repository.isCompoundDecisionTable(element)) {
if (dmnTransformer.hasListType(element)) {
return Arrays.asList(defaultValue);
return Collections.singletonList(defaultValue);
} else {
return defaultValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected static boolean getOptionalBooleanParam(Map<String, String> parameters,
private final boolean mockTesting;
private final boolean generateExtra;

private boolean checkConstraints;
private final boolean checkConstraints;

public InputParameters() {
this(new LinkedHashMap<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public Type expressionType(TDRGElement element, TExpression expression, DMNConte
if (columnType == null) {
columnType = AnyType.ANY;
}
rowType.addMember(column.getName(), Arrays.asList(), columnType);
rowType.addMember(column.getName(), Collections.emptyList(), columnType);
}
return new ListType(rowType);
} else if (expression instanceof TConditional) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import com.gs.dmn.runtime.DMNRuntimeException;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

public class FieldType {
private final String modifier;
private final String type;
Expand Down Expand Up @@ -46,8 +48,8 @@ public boolean equals(Object o) {

FieldType fieldType = (FieldType) o;

if (modifier != null ? !modifier.equals(fieldType.modifier) : fieldType.modifier != null) return false;
return type != null ? type.equals(fieldType.type) : fieldType.type == null;
if (!Objects.equals(modifier, fieldType.modifier)) return false;
return Objects.equals(type, fieldType.type);
}

@Override
Expand Down
7 changes: 2 additions & 5 deletions dmn-core/src/test/java/com/gs/dmn/DMNModelRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@

import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -113,7 +110,7 @@ public void testDirectSubInvocables() {
List<DRGElementReference<TInvocable>> references = this.dmnModelRepository.directSubInvocables(root);

List<String> actual = references.stream().map(DRGElementReference::toString).collect(Collectors.toList());
List<String> expected = Arrays.asList(
List<String> expected = Collections.singletonList(
"DMNReference(import='[]', namespace='http://www.trisotech.com/definitions/_4e0f0b70-d31c-471c-bd52-5ca709ed362b', model='Lending1', element='BureauCallTypeTable')"
);
assertEquals(expected, actual);
Expand Down
22 changes: 11 additions & 11 deletions dmn-core/src/test/java/com/gs/dmn/TestFilesScripts.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
import java.util.*;

public class TestFilesScripts {
private static File LOCAL_TCK_FOLDER = new File("C:/Work/Projects/tck/TestCases/compliance-level-3/");

private static File TEST_CASES_FOLDER = new File("dmn-test-cases/standard/");
private static File TCK_11_CL2_FOLDER = new File(TEST_CASES_FOLDER, "tck/1.1/cl2/");
private static File TCK_11_CL3_FOLDER = new File(TEST_CASES_FOLDER, "tck/1.1/cl3/");
private static File TCK_12_CL2_FOLDER = new File(TEST_CASES_FOLDER, "tck/1.2/cl2/");
private static File TCK_12_CL3_FOLDER = new File(TEST_CASES_FOLDER, "tck/1.2/cl3/");
private static File TCK_13_CL2_FOLDER = new File(TEST_CASES_FOLDER, "tck/1.3/cl2/");
private static File TCK_13_CL3_FOLDER = new File(TEST_CASES_FOLDER, "tck/1.3/cl3/");
private static File COMPOSITE_FOLDER = new File(TEST_CASES_FOLDER, "composite/1.2");
private static File PROTO_FOLDER = new File(TEST_CASES_FOLDER, "proto/1.1");
private static final File LOCAL_TCK_FOLDER = new File("C:/Work/Projects/tck/TestCases/compliance-level-3/");

private static final File TEST_CASES_FOLDER = new File("dmn-test-cases/standard/");
private static final File TCK_11_CL2_FOLDER = new File(TEST_CASES_FOLDER, "tck/1.1/cl2/");
private static final File TCK_11_CL3_FOLDER = new File(TEST_CASES_FOLDER, "tck/1.1/cl3/");
private static final File TCK_12_CL2_FOLDER = new File(TEST_CASES_FOLDER, "tck/1.2/cl2/");
private static final File TCK_12_CL3_FOLDER = new File(TEST_CASES_FOLDER, "tck/1.2/cl3/");
private static final File TCK_13_CL2_FOLDER = new File(TEST_CASES_FOLDER, "tck/1.3/cl2/");
private static final File TCK_13_CL3_FOLDER = new File(TEST_CASES_FOLDER, "tck/1.3/cl3/");
private static final File COMPOSITE_FOLDER = new File(TEST_CASES_FOLDER, "composite/1.2");
private static final File PROTO_FOLDER = new File(TEST_CASES_FOLDER, "proto/1.1");

private static void deleteAlienFilesFromTestFolders(boolean dryRun) throws IOException {
deleteAlienFilesFromTestFolders(TCK_11_CL2_FOLDER, dryRun);
Expand Down
Loading

0 comments on commit 6ca816d

Please sign in to comment.