Skip to content

Commit

Permalink
Add checkreturnvalue
Browse files Browse the repository at this point in the history
  • Loading branch information
vlsi committed Aug 31, 2020
1 parent 1d4a816 commit 696d8f1
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 @@ -32,6 +32,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 @@ -72,6 +73,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 @@ -124,6 +126,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> T getTrait(RelTraitDef<T> traitDef) {
int index = findIndex(traitDef);
if (index >= 0) {
Expand All @@ -142,6 +145,7 @@ public <T extends RelTrait> T getTrait(RelTraitDef<T> traitDef) {
* @param traitDef the type of RelTrait to retrieve
* @return the RelTrait, or null if not found
*/
@CheckReturnValue
public <T extends RelMultipleTrait> List<T> getTraits(
RelTraitDef<T> traitDef) {
int index = findIndex(traitDef);
Expand All @@ -161,6 +165,7 @@ public <T extends RelMultipleTrait> List<T> getTraits(
* @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 @@ -184,6 +189,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 @@ -217,6 +223,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 @@ -228,13 +235,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 @@ -246,6 +255,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 @@ -262,6 +272,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 @@ -401,6 +412,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 null;
Expand Down Expand Up @@ -618,6 +630,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 @@ -634,6 +647,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 @@ -642,12 +656,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 @@ -677,6 +693,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 @@ -698,6 +715,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 696d8f1

Please sign in to comment.