Skip to content

Commit

Permalink
Add checkreturnvalue
Browse files Browse the repository at this point in the history
  • Loading branch information
vlsi committed Aug 30, 2020
1 parent 731f1e8 commit c2b751a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions core/src/main/java/org/apache/calcite/plan/RelTraitSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -73,6 +74,7 @@ private RelTraitSet(Cache cache, RelTrait[] traits) {
* <p>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);
}
Expand Down Expand Up @@ -125,6 +127,7 @@ public <T extends RelTrait> boolean isEnabled(RelTraitDef<T> traitDef) {
* @param traitDef the type of RelTrait to retrieve
* @return the RelTrait, or null if not found
*/
@CheckReturnValue
public <T extends RelTrait> @Nullable T getTrait(RelTraitDef<T> traitDef) {
int index = findIndex(traitDef);
if (index >= 0) {
Expand All @@ -143,6 +146,7 @@ public <T extends RelTrait> boolean isEnabled(RelTraitDef<T> traitDef) {
* @param traitDef the type of RelTrait to retrieve
* @return the RelTrait, or null if not found
*/
@CheckReturnValue
public <T extends RelMultipleTrait> @Nullable List<T> getTraits(
RelTraitDef<T> traitDef) {
int index = findIndex(traitDef);
Expand All @@ -162,6 +166,7 @@ public <T extends RelTrait> boolean isEnabled(RelTraitDef<T> 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";
Expand All @@ -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
Expand Down Expand Up @@ -218,6 +224,7 @@ private static <T> boolean containsShallow(T[] ts, RelTrait seek) {
*
* <p>The list must not be empty, and all traits must be of the same type.
*/
@CheckReturnValue
public <T extends RelMultipleTrait> RelTraitSet replace(List<T> traits) {
assert !traits.isEmpty();
final RelTraitDef def = traits.get(0).getTraitDef();
Expand All @@ -229,13 +236,15 @@ public <T extends RelMultipleTrait> RelTraitSet replace(List<T> traits) {
*
* <p>The list must not be empty, and all traits must be of the same type.
*/
@CheckReturnValue
public <T extends RelMultipleTrait> RelTraitSet replace(RelTraitDef<T> def,
List<T> traits) {
return replace(RelCompositeTrait.of(def, traits));
}

/** If a given multiple trait is enabled, replaces it by calling the given
* function. */
@CheckReturnValue
public <T extends RelMultipleTrait> RelTraitSet replaceIfs(RelTraitDef<T> def,
Supplier<List<T>> traitSupplier) {
int index = findIndex(def);
Expand All @@ -247,6 +256,7 @@ public <T extends RelMultipleTrait> RelTraitSet replaceIfs(RelTraitDef<T> def,
}

/** If a given trait is enabled, replaces it by calling the given function. */
@CheckReturnValue
public <T extends RelTrait> RelTraitSet replaceIf(RelTraitDef<T> def,
Supplier<T> traitSupplier) {
int index = findIndex(def);
Expand All @@ -263,6 +273,7 @@ public <T extends RelTrait> RelTraitSet replaceIf(RelTraitDef<T> 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++) {
Expand Down Expand Up @@ -402,6 +413,7 @@ public int size() {
* @param trait Trait
* @return Trait in canonical form
*/
@CheckReturnValue
public <T extends RelTrait> T canonize(T trait) {
if (trait == null) {
// Return "trait" makes the input type to be the same as the output type,
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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<RelTrait> difference(RelTraitSet traitSet) {
final ImmutableList.Builder<RelTrait> builder = ImmutableList.builder();
final int n =
Expand Down Expand Up @@ -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++) {
Expand All @@ -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;
Expand Down

0 comments on commit c2b751a

Please sign in to comment.