Skip to content

Commit

Permalink
Cosmetic
Browse files Browse the repository at this point in the history
Require that Preconditions.checkArgument is used via static import;
and other changes that do not affect functionality.
  • Loading branch information
julianhyde committed Feb 27, 2024
1 parent 85d9620 commit 96485c0
Show file tree
Hide file tree
Showing 108 changed files with 461 additions and 409 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,8 @@ allprojects {
replace("hamcrest: startsWith", "org.hamcrest.core.StringStartsWith.startsWith", "org.hamcrest.CoreMatchers.startsWith")
replaceRegex("hamcrest: size", "\\.size\\(\\), (is|equalTo)\\(", ", hasSize\\(")
replaceRegex("use static import: toImmutableList", "ImmutableList\\.(toImmutableList\\(\\))", "$1")
replaceRegex("use static import: checkArgument", "Preconditions\\.(checkArgument\\()", "$1")
replaceRegex("use static import: checkArgument", "Preconditions\\.(checkState\\()", "$1")
custom("((() preventer", 1) { contents: String ->
ParenthesisBalancer.apply(contents)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import org.apache.calcite.rex.RexUtil;
import org.apache.calcite.sql.validate.SqlValidatorUtil;

import com.google.common.base.Preconditions;

import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.List;
import java.util.Set;

import static com.google.common.base.Preconditions.checkArgument;

/**
* Contains factory interface and default implementation for creating various
* rel nodes.
Expand Down Expand Up @@ -72,7 +72,7 @@ private static class ProjectFactoryImpl
List<? extends RexNode> childExprs,
@Nullable List<? extends @Nullable String> fieldNames,
Set<CorrelationId> variablesSet) {
Preconditions.checkArgument(variablesSet.isEmpty(),
checkArgument(variablesSet.isEmpty(),
"EnumerableProject does not allow variables");
final RelDataType rowType =
RexUtil.createStructType(input.getCluster().getTypeFactory(), childExprs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
import org.apache.calcite.util.Util;
import org.apache.calcite.util.trace.CalciteTrace;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

Expand All @@ -83,6 +82,8 @@
import java.util.Set;
import java.util.function.Consumer;

import static com.google.common.base.Preconditions.checkArgument;

import static java.util.Objects.requireNonNull;

/**
Expand All @@ -98,7 +99,7 @@ private JdbcRules() {

static final RelFactories.ProjectFactory PROJECT_FACTORY =
(input, hints, projects, fieldNames, variablesSet) -> {
Preconditions.checkArgument(variablesSet.isEmpty(),
checkArgument(variablesSet.isEmpty(),
"JdbcProject does not allow variables");
final RelOptCluster cluster = input.getCluster();
final RelDataType rowType =
Expand All @@ -110,7 +111,7 @@ private JdbcRules() {

static final RelFactories.FilterFactory FILTER_FACTORY =
(input, condition, variablesSet) -> {
Preconditions.checkArgument(variablesSet.isEmpty(),
checkArgument(variablesSet.isEmpty(),
"JdbcFilter does not allow variables");
return new JdbcFilter(input.getCluster(),
input.getTraitSet(), input, condition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.ImmutableIntList;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

Expand All @@ -89,6 +88,8 @@
import java.util.Set;
import java.util.SortedSet;

import static com.google.common.base.Preconditions.checkArgument;

/**
* Utilities pertaining to {@link BindableRel} and {@link BindableConvention}.
*/
Expand Down Expand Up @@ -219,7 +220,7 @@ public static class BindableTableScan
super(cluster, traitSet, ImmutableList.of(), table);
this.filters = Objects.requireNonNull(filters, "filters");
this.projects = Objects.requireNonNull(projects, "projects");
Preconditions.checkArgument(canHandle(table));
checkArgument(canHandle(table));
}

/** Creates a BindableTableScan. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
import org.apache.calcite.util.Holder;
import org.apache.calcite.util.Util;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

Expand All @@ -88,6 +87,8 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;

import static com.google.common.base.Preconditions.checkArgument;

import static org.apache.calcite.linq4j.Nullness.castNonNull;

import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -148,7 +149,7 @@ protected CalciteConnectionImpl(Driver driver, AvaticaFactory factory,
requireNonNull(rootSchema != null
? rootSchema
: CalciteSchema.createRootSchema(true));
Preconditions.checkArgument(this.rootSchema.isRoot(), "must be root schema");
checkArgument(this.rootSchema.isRoot(), "must be root schema");
this.properties.put(InternalProperty.CASE_SENSITIVE, cfg.caseSensitive());
this.properties.put(InternalProperty.UNQUOTED_CASING, cfg.unquotedCasing());
this.properties.put(InternalProperty.QUOTED_CASING, cfg.quotedCasing());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.apache.calcite.util.ImmutableIntList;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;

import org.checkerframework.checker.nullness.qual.Nullable;
Expand All @@ -60,6 +59,8 @@
import java.util.List;
import java.util.Map;

import static com.google.common.base.Preconditions.checkArgument;

import static org.apache.calcite.linq4j.Nullness.castNonNull;

import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -312,7 +313,7 @@ public AnalyzeViewResult(CalcitePrepareImpl prepare,
this.constraint = constraint;
this.columnMapping = columnMapping;
this.modifiable = modifiable;
Preconditions.checkArgument(modifiable == (table != null));
checkArgument(modifiable == (table != null));
}
}

Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.apache.calcite.util.NameSet;
import org.apache.calcite.util.Pair;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.ImmutableSortedSet;
Expand All @@ -49,6 +48,8 @@
import java.util.NavigableSet;
import java.util.Set;

import static com.google.common.base.Preconditions.checkArgument;

import static java.util.Objects.requireNonNull;

/**
Expand Down Expand Up @@ -441,7 +442,7 @@ public final NavigableMap<String, Table> getTablesBasedOnNullaryFunctions() {
* @return the schema snapshot.
*/
public CalciteSchema createSnapshot(SchemaVersion version) {
Preconditions.checkArgument(this.isRoot(), "must be root schema");
checkArgument(this.isRoot(), "must be root schema");
return snapshot(null, version);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import org.apache.calcite.util.graph.TopologicalOrderIterator;
import org.apache.calcite.util.mapping.IntPair;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableSortedSet;
Expand Down Expand Up @@ -86,6 +85,8 @@
import java.util.function.IntFunction;
import java.util.stream.Collectors;

import static com.google.common.base.Preconditions.checkArgument;

import static org.apache.calcite.linq4j.Nullness.castNonNull;

import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -130,7 +131,7 @@ private Lattice(CalciteSchema rootSchema, LatticeRootNode rootNode,
// [CALCITE-429] Add statistics SPI for lattice optimization algorithm
rowCountEstimate = 1000d;
}
Preconditions.checkArgument(rowCountEstimate > 0d);
checkArgument(rowCountEstimate > 0d);
this.rowCountEstimate = rowCountEstimate;
@SuppressWarnings("argument.type.incompatible")
LatticeStatisticProvider statisticProvider =
Expand Down Expand Up @@ -798,7 +799,7 @@ public static class Builder {

public Builder(LatticeSpace space, CalciteSchema schema, String sql) {
this.rootSchema = requireNonNull(schema.root());
Preconditions.checkArgument(rootSchema.isRoot(), "must be root schema");
checkArgument(rootSchema.isRoot(), "must be root schema");
CalcitePrepare.ConvertResult parsed =
Schemas.convert(MaterializedViewTable.MATERIALIZATION_CONNECTION,
schema, schema.path(null), sql);
Expand Down Expand Up @@ -934,7 +935,7 @@ public Lattice build() {
LatticeStatisticProvider.Factory.class,
this.statisticProvider)
: Lattices.CACHED_SQL;
Preconditions.checkArgument(rootSchema.isRoot(), "must be root schema");
checkArgument(rootSchema.isRoot(), "must be root schema");
final ImmutableList.Builder<Column> columnBuilder =
ImmutableList.<Column>builder()
.addAll(baseColumns)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
import org.apache.calcite.plan.RelOptTable;
import org.apache.calcite.util.mapping.IntPair;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;

import org.checkerframework.checker.initialization.qual.Initialized;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.List;

import static com.google.common.base.Preconditions.checkArgument;

import static java.util.Objects.requireNonNull;

/** Source relation of a lattice.
Expand All @@ -51,8 +52,8 @@ public abstract class LatticeNode {
this.startCol = mutableNode.startCol;
this.endCol = mutableNode.endCol;
this.alias = mutableNode.alias;
Preconditions.checkArgument(startCol >= 0);
Preconditions.checkArgument(endCol > startCol);
checkArgument(startCol >= 0);
checkArgument(endCol > startCol);

final StringBuilder sb = new StringBuilder()
.append(space.simpleName(table));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.apache.calcite.jdbc.CalciteSchema;
import org.apache.calcite.rel.type.RelDataType;

import com.google.common.base.Preconditions;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;

Expand All @@ -30,6 +29,8 @@
import java.util.Map;
import java.util.Objects;

import static com.google.common.base.Preconditions.checkArgument;

/**
* Actor that manages the state of materializations in the system.
*/
Expand Down Expand Up @@ -78,7 +79,7 @@ static class Materialization {
@Nullable List<String> viewSchemaPath) {
this.key = key;
this.rootSchema = Objects.requireNonNull(rootSchema, "rootSchema");
Preconditions.checkArgument(rootSchema.isRoot(), "must be root schema");
checkArgument(rootSchema.isRoot(), "must be root schema");
this.materializedTable = materializedTable; // may be null
this.sql = sql;
this.rowType = rowType;
Expand Down
11 changes: 6 additions & 5 deletions core/src/main/java/org/apache/calcite/profile/ProfilerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.calcite.util.PartiallyOrderedSet;
import org.apache.calcite.util.Util;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Iterables;
Expand Down Expand Up @@ -57,6 +56,8 @@
import java.util.TreeSet;
import java.util.function.Predicate;

import static com.google.common.base.Preconditions.checkArgument;

import static org.apache.calcite.linq4j.Nullness.castNonNull;
import static org.apache.calcite.profile.ProfilerImpl.CompositeCollector.OF;

Expand Down Expand Up @@ -96,8 +97,8 @@ public static Builder builder() {
*/
ProfilerImpl(int combinationsPerPass,
int interestingCount, Predicate<Pair<Space, Column>> predicate) {
Preconditions.checkArgument(combinationsPerPass > 2);
Preconditions.checkArgument(interestingCount > 2);
checkArgument(combinationsPerPass > 2);
checkArgument(interestingCount > 2);
this.combinationsPerPass = combinationsPerPass;
this.interestingCount = interestingCount;
this.predicate = predicate;
Expand Down Expand Up @@ -770,8 +771,8 @@ static class SurpriseQueue {
SurpriseQueue(int warmUpCount, int size) {
this.warmUpCount = warmUpCount;
this.size = size;
Preconditions.checkArgument(warmUpCount > 3);
Preconditions.checkArgument(size > 0);
checkArgument(warmUpCount > 3);
checkArgument(size > 0);
}

@Override public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.calcite.util.Util;
import org.apache.calcite.util.mapping.Mappings;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.UnmodifiableIterator;

Expand All @@ -35,6 +34,8 @@
import java.util.Iterator;
import java.util.List;

import static com.google.common.base.Preconditions.checkArgument;

/**
* Simple implementation of {@link RelCollation}.
*/
Expand All @@ -55,8 +56,7 @@ public class RelCollationImpl implements RelCollation {

protected RelCollationImpl(ImmutableList<RelFieldCollation> fieldCollations) {
this.fieldCollations = fieldCollations;
Preconditions.checkArgument(
Util.isDistinct(RelCollations.ordinals(fieldCollations)),
checkArgument(Util.isDistinct(RelCollations.ordinals(fieldCollations)),
"fields must be distinct");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
import org.apache.calcite.util.mapping.Mapping;
import org.apache.calcite.util.mapping.Mappings;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;

import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.List;
import java.util.Objects;

import static com.google.common.base.Preconditions.checkArgument;

import static java.util.Objects.requireNonNull;

/**
Expand Down Expand Up @@ -121,10 +122,10 @@ private AggregateCall(SqlAggFunction aggFunction, boolean distinct,
this.distinct = distinct;
this.approximate = approximate;
this.ignoreNulls = ignoreNulls;
Preconditions.checkArgument(
aggFunction.getDistinctOptionality() != Optionality.IGNORED || !distinct,
checkArgument(aggFunction.getDistinctOptionality() != Optionality.IGNORED
|| !distinct,
"DISTINCT has no effect for this aggregate function, so must be false");
Preconditions.checkArgument(filterArg < 0 || aggFunction.allowsFilter());
checkArgument(filterArg < 0 || aggFunction.allowsFilter());
}

//~ Methods ----------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/org/apache/calcite/rel/core/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.apache.calcite.sql.fun.SqlSumEmptyIsZeroAggFunction;
import org.apache.calcite.util.ImmutableBitSet;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.ImmutableSortedSet;
Expand All @@ -52,6 +51,8 @@
import java.util.TreeMap;
import java.util.TreeSet;

import static com.google.common.base.Preconditions.checkArgument;

/**
* Relational expression that represent a MATCH_RECOGNIZE node.
*
Expand Down Expand Up @@ -105,7 +106,7 @@ protected Match(RelOptCluster cluster, RelTraitSet traitSet, RelNode input,
super(cluster, traitSet, input);
this.rowType = Objects.requireNonNull(rowType, "rowType");
this.pattern = Objects.requireNonNull(pattern, "pattern");
Preconditions.checkArgument(patternDefinitions.size() > 0);
checkArgument(!patternDefinitions.isEmpty());
this.strictStart = strictStart;
this.strictEnd = strictEnd;
this.patternDefinitions = ImmutableMap.copyOf(patternDefinitions);
Expand Down
Loading

0 comments on commit 96485c0

Please sign in to comment.