From 62c2b541dd21eb16c4b50622aa68ba12ab51339a Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Mon, 31 Aug 2020 01:16:37 +0300 Subject: [PATCH] Add checkreturnvalue --- .../org/apache/calcite/plan/RelTraitSet.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/src/main/java/org/apache/calcite/plan/RelTraitSet.java b/core/src/main/java/org/apache/calcite/plan/RelTraitSet.java index 43603cfa5d2a..f8566b437284 100644 --- a/core/src/main/java/org/apache/calcite/plan/RelTraitSet.java +++ b/core/src/main/java/org/apache/calcite/plan/RelTraitSet.java @@ -33,6 +33,7 @@ import java.util.List; import java.util.Map; import java.util.function.Supplier; +import javax.annotation.CheckReturnValue; /** * RelTraitSet represents an ordered set of {@link RelTrait}s. @@ -73,6 +74,7 @@ private RelTraitSet(Cache cache, RelTrait[] traits) { *

It has a new cache, which will be shared by any trait set created from * it. Thus each empty trait set is the start of a new ancestral line. */ + @CheckReturnValue public static RelTraitSet createEmpty() { return new RelTraitSet(new Cache(), EMPTY_TRAITS); } @@ -125,6 +127,7 @@ public boolean isEnabled(RelTraitDef traitDef) { * @param traitDef the type of RelTrait to retrieve * @return the RelTrait, or null if not found */ + @CheckReturnValue public @Nullable T getTrait(RelTraitDef traitDef) { int index = findIndex(traitDef); if (index >= 0) { @@ -143,6 +146,7 @@ public boolean isEnabled(RelTraitDef traitDef) { * @param traitDef the type of RelTrait to retrieve * @return the RelTrait, or null if not found */ + @CheckReturnValue public @Nullable List getTraits( RelTraitDef traitDef) { int index = findIndex(traitDef); @@ -162,6 +166,7 @@ public boolean isEnabled(RelTraitDef traitDef) { * @param trait the new RelTrait * @return the old RelTrait at the index */ + @CheckReturnValue public RelTraitSet replace(int index, RelTrait trait) { assert traits[index].getTraitDef() == trait.getTraitDef() : "RelTrait has different RelTraitDef than replacement"; @@ -185,6 +190,7 @@ public RelTraitSet replace(int index, RelTrait trait) { * @return New set * @see #plus(RelTrait) */ + @CheckReturnValue public RelTraitSet replace( RelTrait trait) { // Quick check for common case @@ -218,6 +224,7 @@ private static boolean containsShallow(T[] ts, RelTrait seek) { * *

The list must not be empty, and all traits must be of the same type. */ + @CheckReturnValue public RelTraitSet replace(List traits) { assert !traits.isEmpty(); final RelTraitDef def = traits.get(0).getTraitDef(); @@ -229,6 +236,7 @@ public RelTraitSet replace(List traits) { * *

The list must not be empty, and all traits must be of the same type. */ + @CheckReturnValue public RelTraitSet replace(RelTraitDef def, List traits) { return replace(RelCompositeTrait.of(def, traits)); @@ -236,6 +244,7 @@ public RelTraitSet replace(RelTraitDef def, /** If a given multiple trait is enabled, replaces it by calling the given * function. */ + @CheckReturnValue public RelTraitSet replaceIfs(RelTraitDef def, Supplier> traitSupplier) { int index = findIndex(def); @@ -247,6 +256,7 @@ public RelTraitSet replaceIfs(RelTraitDef def, } /** If a given trait is enabled, replaces it by calling the given function. */ + @CheckReturnValue public RelTraitSet replaceIf(RelTraitDef def, Supplier traitSupplier) { int index = findIndex(def); @@ -263,6 +273,7 @@ public RelTraitSet replaceIf(RelTraitDef def, * @param mapping Mapping * @return traitSet with mapping applied */ + @CheckReturnValue public RelTraitSet apply(Mappings.TargetMapping mapping) { RelTrait[] newTraits = new RelTrait[traits.length]; for (int i = 0; i < traits.length; i++) { @@ -402,6 +413,7 @@ public int size() { * @param trait Trait * @return Trait in canonical form */ + @CheckReturnValue public T canonize(T trait) { if (trait == null) { // Return "trait" makes the input type to be the same as the output type, @@ -621,6 +633,7 @@ private int findIndex(RelTraitDef traitDef) { * @param trait Trait * @return Trait set with given trait */ + @CheckReturnValue public RelTraitSet plus(RelTrait trait) { if (contains(trait)) { return this; @@ -637,6 +650,7 @@ public RelTraitSet plus(RelTrait trait) { return cache.getOrAdd(new RelTraitSet(cache, newTraits)); } + @CheckReturnValue public RelTraitSet plusAll(RelTrait[] traits) { RelTraitSet t = this; for (RelTrait trait : traits) { @@ -645,12 +659,14 @@ public RelTraitSet plusAll(RelTrait[] traits) { return t; } + @CheckReturnValue public RelTraitSet merge(RelTraitSet additionalTraits) { return plusAll(additionalTraits.traits); } /** Returns a list of traits that are in {@code traitSet} but not in this * RelTraitSet. */ + @CheckReturnValue public ImmutableList difference(RelTraitSet traitSet) { final ImmutableList.Builder builder = ImmutableList.builder(); final int n = @@ -680,6 +696,7 @@ public boolean allSimple() { /** Returns a trait set similar to this one but with all composite traits * flattened. */ + @CheckReturnValue public RelTraitSet simplify() { RelTraitSet x = this; for (int i = 0; i < traits.length; i++) { @@ -701,6 +718,7 @@ private static class Cache { Cache() { } + @CheckReturnValue RelTraitSet getOrAdd(RelTraitSet t) { RelTraitSet exist = map.putIfAbsent(t, t); return exist == null ? t : exist;