Skip to content

Commit 62c2b54

Browse files
committed
Add checkreturnvalue
1 parent 3a2ad62 commit 62c2b54

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

core/src/main/java/org/apache/calcite/plan/RelTraitSet.java

+18
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.List;
3434
import java.util.Map;
3535
import java.util.function.Supplier;
36+
import javax.annotation.CheckReturnValue;
3637

3738
/**
3839
* RelTraitSet represents an ordered set of {@link RelTrait}s.
@@ -73,6 +74,7 @@ private RelTraitSet(Cache cache, RelTrait[] traits) {
7374
* <p>It has a new cache, which will be shared by any trait set created from
7475
* it. Thus each empty trait set is the start of a new ancestral line.
7576
*/
77+
@CheckReturnValue
7678
public static RelTraitSet createEmpty() {
7779
return new RelTraitSet(new Cache(), EMPTY_TRAITS);
7880
}
@@ -125,6 +127,7 @@ public <T extends RelTrait> boolean isEnabled(RelTraitDef<T> traitDef) {
125127
* @param traitDef the type of RelTrait to retrieve
126128
* @return the RelTrait, or null if not found
127129
*/
130+
@CheckReturnValue
128131
public <T extends RelTrait> @Nullable T getTrait(RelTraitDef<T> traitDef) {
129132
int index = findIndex(traitDef);
130133
if (index >= 0) {
@@ -143,6 +146,7 @@ public <T extends RelTrait> boolean isEnabled(RelTraitDef<T> traitDef) {
143146
* @param traitDef the type of RelTrait to retrieve
144147
* @return the RelTrait, or null if not found
145148
*/
149+
@CheckReturnValue
146150
public <T extends RelMultipleTrait> @Nullable List<T> getTraits(
147151
RelTraitDef<T> traitDef) {
148152
int index = findIndex(traitDef);
@@ -162,6 +166,7 @@ public <T extends RelTrait> boolean isEnabled(RelTraitDef<T> traitDef) {
162166
* @param trait the new RelTrait
163167
* @return the old RelTrait at the index
164168
*/
169+
@CheckReturnValue
165170
public RelTraitSet replace(int index, RelTrait trait) {
166171
assert traits[index].getTraitDef() == trait.getTraitDef()
167172
: "RelTrait has different RelTraitDef than replacement";
@@ -185,6 +190,7 @@ public RelTraitSet replace(int index, RelTrait trait) {
185190
* @return New set
186191
* @see #plus(RelTrait)
187192
*/
193+
@CheckReturnValue
188194
public RelTraitSet replace(
189195
RelTrait trait) {
190196
// Quick check for common case
@@ -218,6 +224,7 @@ private static <T> boolean containsShallow(T[] ts, RelTrait seek) {
218224
*
219225
* <p>The list must not be empty, and all traits must be of the same type.
220226
*/
227+
@CheckReturnValue
221228
public <T extends RelMultipleTrait> RelTraitSet replace(List<T> traits) {
222229
assert !traits.isEmpty();
223230
final RelTraitDef def = traits.get(0).getTraitDef();
@@ -229,13 +236,15 @@ public <T extends RelMultipleTrait> RelTraitSet replace(List<T> traits) {
229236
*
230237
* <p>The list must not be empty, and all traits must be of the same type.
231238
*/
239+
@CheckReturnValue
232240
public <T extends RelMultipleTrait> RelTraitSet replace(RelTraitDef<T> def,
233241
List<T> traits) {
234242
return replace(RelCompositeTrait.of(def, traits));
235243
}
236244

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

249258
/** If a given trait is enabled, replaces it by calling the given function. */
259+
@CheckReturnValue
250260
public <T extends RelTrait> RelTraitSet replaceIf(RelTraitDef<T> def,
251261
Supplier<T> traitSupplier) {
252262
int index = findIndex(def);
@@ -263,6 +273,7 @@ public <T extends RelTrait> RelTraitSet replaceIf(RelTraitDef<T> def,
263273
* @param mapping Mapping
264274
* @return traitSet with mapping applied
265275
*/
276+
@CheckReturnValue
266277
public RelTraitSet apply(Mappings.TargetMapping mapping) {
267278
RelTrait[] newTraits = new RelTrait[traits.length];
268279
for (int i = 0; i < traits.length; i++) {
@@ -402,6 +413,7 @@ public int size() {
402413
* @param trait Trait
403414
* @return Trait in canonical form
404415
*/
416+
@CheckReturnValue
405417
public <T extends RelTrait> T canonize(T trait) {
406418
if (trait == null) {
407419
// Return "trait" makes the input type to be the same as the output type,
@@ -621,6 +633,7 @@ private int findIndex(RelTraitDef traitDef) {
621633
* @param trait Trait
622634
* @return Trait set with given trait
623635
*/
636+
@CheckReturnValue
624637
public RelTraitSet plus(RelTrait trait) {
625638
if (contains(trait)) {
626639
return this;
@@ -637,6 +650,7 @@ public RelTraitSet plus(RelTrait trait) {
637650
return cache.getOrAdd(new RelTraitSet(cache, newTraits));
638651
}
639652

653+
@CheckReturnValue
640654
public RelTraitSet plusAll(RelTrait[] traits) {
641655
RelTraitSet t = this;
642656
for (RelTrait trait : traits) {
@@ -645,12 +659,14 @@ public RelTraitSet plusAll(RelTrait[] traits) {
645659
return t;
646660
}
647661

662+
@CheckReturnValue
648663
public RelTraitSet merge(RelTraitSet additionalTraits) {
649664
return plusAll(additionalTraits.traits);
650665
}
651666

652667
/** Returns a list of traits that are in {@code traitSet} but not in this
653668
* RelTraitSet. */
669+
@CheckReturnValue
654670
public ImmutableList<RelTrait> difference(RelTraitSet traitSet) {
655671
final ImmutableList.Builder<RelTrait> builder = ImmutableList.builder();
656672
final int n =
@@ -680,6 +696,7 @@ public boolean allSimple() {
680696

681697
/** Returns a trait set similar to this one but with all composite traits
682698
* flattened. */
699+
@CheckReturnValue
683700
public RelTraitSet simplify() {
684701
RelTraitSet x = this;
685702
for (int i = 0; i < traits.length; i++) {
@@ -701,6 +718,7 @@ private static class Cache {
701718
Cache() {
702719
}
703720

721+
@CheckReturnValue
704722
RelTraitSet getOrAdd(RelTraitSet t) {
705723
RelTraitSet exist = map.putIfAbsent(t, t);
706724
return exist == null ? t : exist;

0 commit comments

Comments
 (0)