Skip to content

Commit

Permalink
Replace Collections.singletonList and emptyList with List.of in…
Browse files Browse the repository at this point in the history
… cases where `List` is already imported.

Signed-off-by: currantw <[email protected]>
  • Loading branch information
currantw committed Dec 9, 2024
1 parent 823cffe commit c603113
Show file tree
Hide file tree
Showing 24 changed files with 45 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

package org.opensearch.sql.ast.expression;

import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;

import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand Down Expand Up @@ -44,7 +41,7 @@ public class AggregateFunction extends UnresolvedExpression {
public AggregateFunction(String funcName, UnresolvedExpression field) {
this.funcName = funcName;
this.field = field;
this.argList = emptyList();
this.argList = List.of();
}

/**
Expand All @@ -57,13 +54,13 @@ public AggregateFunction(String funcName, UnresolvedExpression field) {
public AggregateFunction(String funcName, UnresolvedExpression field, Boolean distinct) {
this.funcName = funcName;
this.field = field;
this.argList = emptyList();
this.argList = List.of();
this.distinct = distinct;
}

@Override
public List<UnresolvedExpression> getChild() {
return singletonList(field);
return List.of(field);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.opensearch.sql.ast.expression;

import static java.util.Collections.singletonList;

import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -26,7 +24,7 @@ public class Argument extends UnresolvedExpression {
// private final DataType valueType;
@Override
public List<UnresolvedExpression> getChild() {
return singletonList(value);
return List.of(value);
}

@Override
Expand Down
4 changes: 1 addition & 3 deletions core/src/main/java/org/opensearch/sql/ast/expression/In.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.opensearch.sql.ast.expression;

import static java.util.Collections.singletonList;

import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -29,7 +27,7 @@ public class In extends UnresolvedExpression {

@Override
public List<UnresolvedExpression> getChild() {
return singletonList(field);
return List.of(field);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.opensearch.sql.ast.expression;

import static java.util.Collections.singletonList;

import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -30,7 +28,7 @@ public Interval(UnresolvedExpression value, String unit) {

@Override
public List<UnresolvedExpression> getChild() {
return singletonList(value);
return List.of(value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.opensearch.sql.ast.expression;

import static java.util.Collections.singletonList;

import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -24,7 +22,7 @@ public class Not extends UnresolvedExpression {

@Override
public List<UnresolvedExpression> getChild() {
return singletonList(expression);
return List.of(expression);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.opensearch.sql.ast.expression;

import static java.util.Collections.singletonList;

import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -28,7 +26,7 @@ public UnresolvedArgument(String argName, UnresolvedExpression value) {

@Override
public List<UnresolvedExpression> getChild() {
return singletonList(value);
return List.of(value);
}

@Override
Expand Down
4 changes: 1 addition & 3 deletions core/src/main/java/org/opensearch/sql/ast/tree/RareTopN.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.opensearch.sql.ast.tree;

import static java.util.Collections.singletonList;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -42,7 +40,7 @@ public RareTopN attach(UnresolvedPlan child) {

@Override
public List<UnresolvedPlan> getChild() {
return singletonList(this.child);
return List.of(this.child);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package org.opensearch.sql.expression.text;

import static java.util.Collections.singletonList;
import static org.opensearch.sql.data.type.ExprCoreType.ARRAY;
import static org.opensearch.sql.data.type.ExprCoreType.INTEGER;
import static org.opensearch.sql.data.type.ExprCoreType.STRING;
Expand Down Expand Up @@ -176,7 +175,7 @@ private DefaultFunctionResolver concat() {
concatFuncName,
funcName ->
Pair.of(
new FunctionSignature(concatFuncName, singletonList(ARRAY)),
new FunctionSignature(concatFuncName, List.of(ARRAY)),
(funcProp, args) ->
new FunctionExpression(funcName, args) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.opensearch.sql.expression.window.ranking;

import static java.util.Collections.emptyList;

import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -35,7 +33,7 @@ public abstract class RankingWindowFunction extends FunctionExpression
protected int rank;

public RankingWindowFunction(FunctionName functionName) {
super(functionName, emptyList());
super(functionName, List.of());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.opensearch.sql.planner.logical;

import static java.util.Collections.singletonList;

import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -26,7 +24,7 @@ public class LogicalAggregation extends LogicalPlan {
/** Constructor of LogicalAggregation. */
public LogicalAggregation(
LogicalPlan child, List<NamedAggregator> aggregatorList, List<NamedExpression> groupByList) {
super(singletonList(child));
super(List.of(child));
this.aggregatorList = aggregatorList;
this.groupByList = groupByList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.opensearch.sql.planner.logical;

import static java.util.Collections.singletonList;

import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -31,7 +29,7 @@ public LogicalDedupe(
Integer allowedDuplication,
Boolean keepEmpty,
Boolean consecutive) {
super(singletonList(child));
super(List.of(child));
this.dedupeList = dedupeList;
this.allowedDuplication = allowedDuplication;
this.keepEmpty = keepEmpty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.opensearch.sql.planner.logical;

import static java.util.Collections.singletonList;

import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -28,7 +26,7 @@ public class LogicalEval extends LogicalPlan {

/** Constructor of LogicalEval. */
public LogicalEval(LogicalPlan child, List<Pair<ReferenceExpression, Expression>> expressions) {
super(singletonList(child));
super(List.of(child));
this.expressions = expressions;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.opensearch.sql.planner.logical;

import static java.util.Collections.singletonList;

import java.util.List;
import java.util.Map;
import lombok.EqualsAndHashCode;
Expand All @@ -28,7 +26,7 @@ public LogicalNested(
LogicalPlan childPlan,
List<Map<String, ReferenceExpression>> fields,
List<NamedExpression> projectList) {
super(singletonList(childPlan));
super(List.of(childPlan));
this.fields = fields;
this.projectList = projectList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.opensearch.sql.planner.logical;

import static java.util.Collections.singletonList;

import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -26,7 +24,7 @@ public LogicalProject(
LogicalPlan child,
List<NamedExpression> projectList,
List<NamedExpression> namedParseExpressions) {
super(singletonList(child));
super(List.of(child));
this.projectList = projectList;
this.namedParseExpressions = namedParseExpressions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.opensearch.sql.planner.logical;

import static java.util.Collections.singletonList;

import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -32,7 +30,7 @@ public LogicalRareTopN(
Integer noOfResults,
List<Expression> fieldList,
List<Expression> groupByList) {
super(singletonList(child));
super(List.of(child));
this.commandType = commandType;
this.noOfResults = noOfResults;
this.fieldList = fieldList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.opensearch.sql.planner.logical;

import static java.util.Collections.singletonList;

import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -25,7 +23,7 @@ public class LogicalSort extends LogicalPlan {

/** Constructor of LogicalSort. */
public LogicalSort(LogicalPlan child, List<Pair<SortOption, Expression>> sortList) {
super(singletonList(child));
super(List.of(child));
this.sortList = sortList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.opensearch.sql.planner.logical;

import static java.util.Collections.singletonList;

import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -27,7 +25,7 @@ public class LogicalWrite extends LogicalPlan {

/** Construct a logical write with given child node, table and column name list. */
public LogicalWrite(LogicalPlan child, Table table, List<String> columns) {
super(singletonList(child));
super(List.of(child));
this.table = table;
this.columns = columns;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.opensearch.sql.planner.physical;

import static java.util.Collections.singletonList;

import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand Down Expand Up @@ -37,7 +35,7 @@ public <R, C> R accept(PhysicalPlanNodeVisitor<R, C> visitor, C context) {

@Override
public List<PhysicalPlan> getChild() {
return singletonList(input);
return List.of(input);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.opensearch.sql.storage.write;

import static java.util.Collections.singletonList;

import java.util.List;
import lombok.RequiredArgsConstructor;
import org.opensearch.sql.planner.physical.PhysicalPlan;
Expand All @@ -30,7 +28,7 @@ public <R, C> R accept(PhysicalPlanNodeVisitor<R, C> visitor, C context) {

@Override
public List<PhysicalPlan> getChild() {
return singletonList(input);
return List.of(input);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package org.opensearch.sql.analysis;

import static java.util.Collections.singletonList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
Expand Down Expand Up @@ -77,11 +76,11 @@ protected List<NamedExpression> analyze(UnresolvedExpression unresolvedExpressio
.when(optimizer)
.optimize(any(), any());
return new SelectExpressionAnalyzer(expressionAnalyzer)
.analyze(singletonList(unresolvedExpression), analysisContext, optimizer);
.analyze(List.of(unresolvedExpression), analysisContext, optimizer);
}

protected void assertAnalyzeEqual(
NamedExpression expected, UnresolvedExpression unresolvedExpression) {
assertEquals(singletonList(expected), analyze(unresolvedExpression));
assertEquals(List.of(expected), analyze(unresolvedExpression));
}
}
Loading

0 comments on commit c603113

Please sign in to comment.