33
33
import java .util .List ;
34
34
import java .util .Map ;
35
35
import java .util .function .Supplier ;
36
+ import javax .annotation .CheckReturnValue ;
36
37
37
38
/**
38
39
* RelTraitSet represents an ordered set of {@link RelTrait}s.
@@ -73,6 +74,7 @@ private RelTraitSet(Cache cache, RelTrait[] traits) {
73
74
* <p>It has a new cache, which will be shared by any trait set created from
74
75
* it. Thus each empty trait set is the start of a new ancestral line.
75
76
*/
77
+ @ CheckReturnValue
76
78
public static RelTraitSet createEmpty () {
77
79
return new RelTraitSet (new Cache (), EMPTY_TRAITS );
78
80
}
@@ -125,6 +127,7 @@ public <T extends RelTrait> boolean isEnabled(RelTraitDef<T> traitDef) {
125
127
* @param traitDef the type of RelTrait to retrieve
126
128
* @return the RelTrait, or null if not found
127
129
*/
130
+ @ CheckReturnValue
128
131
public <T extends RelTrait > @ Nullable T getTrait (RelTraitDef <T > traitDef ) {
129
132
int index = findIndex (traitDef );
130
133
if (index >= 0 ) {
@@ -143,6 +146,7 @@ public <T extends RelTrait> boolean isEnabled(RelTraitDef<T> traitDef) {
143
146
* @param traitDef the type of RelTrait to retrieve
144
147
* @return the RelTrait, or null if not found
145
148
*/
149
+ @ CheckReturnValue
146
150
public <T extends RelMultipleTrait > @ Nullable List <T > getTraits (
147
151
RelTraitDef <T > traitDef ) {
148
152
int index = findIndex (traitDef );
@@ -162,6 +166,7 @@ public <T extends RelTrait> boolean isEnabled(RelTraitDef<T> traitDef) {
162
166
* @param trait the new RelTrait
163
167
* @return the old RelTrait at the index
164
168
*/
169
+ @ CheckReturnValue
165
170
public RelTraitSet replace (int index , RelTrait trait ) {
166
171
assert traits [index ].getTraitDef () == trait .getTraitDef ()
167
172
: "RelTrait has different RelTraitDef than replacement" ;
@@ -185,6 +190,7 @@ public RelTraitSet replace(int index, RelTrait trait) {
185
190
* @return New set
186
191
* @see #plus(RelTrait)
187
192
*/
193
+ @ CheckReturnValue
188
194
public RelTraitSet replace (
189
195
RelTrait trait ) {
190
196
// Quick check for common case
@@ -218,6 +224,7 @@ private static <T> boolean containsShallow(T[] ts, RelTrait seek) {
218
224
*
219
225
* <p>The list must not be empty, and all traits must be of the same type.
220
226
*/
227
+ @ CheckReturnValue
221
228
public <T extends RelMultipleTrait > RelTraitSet replace (List <T > traits ) {
222
229
assert !traits .isEmpty ();
223
230
final RelTraitDef def = traits .get (0 ).getTraitDef ();
@@ -229,13 +236,15 @@ public <T extends RelMultipleTrait> RelTraitSet replace(List<T> traits) {
229
236
*
230
237
* <p>The list must not be empty, and all traits must be of the same type.
231
238
*/
239
+ @ CheckReturnValue
232
240
public <T extends RelMultipleTrait > RelTraitSet replace (RelTraitDef <T > def ,
233
241
List <T > traits ) {
234
242
return replace (RelCompositeTrait .of (def , traits ));
235
243
}
236
244
237
245
/** If a given multiple trait is enabled, replaces it by calling the given
238
246
* function. */
247
+ @ CheckReturnValue
239
248
public <T extends RelMultipleTrait > RelTraitSet replaceIfs (RelTraitDef <T > def ,
240
249
Supplier <List <T >> traitSupplier ) {
241
250
int index = findIndex (def );
@@ -247,6 +256,7 @@ public <T extends RelMultipleTrait> RelTraitSet replaceIfs(RelTraitDef<T> def,
247
256
}
248
257
249
258
/** If a given trait is enabled, replaces it by calling the given function. */
259
+ @ CheckReturnValue
250
260
public <T extends RelTrait > RelTraitSet replaceIf (RelTraitDef <T > def ,
251
261
Supplier <T > traitSupplier ) {
252
262
int index = findIndex (def );
@@ -263,6 +273,7 @@ public <T extends RelTrait> RelTraitSet replaceIf(RelTraitDef<T> def,
263
273
* @param mapping Mapping
264
274
* @return traitSet with mapping applied
265
275
*/
276
+ @ CheckReturnValue
266
277
public RelTraitSet apply (Mappings .TargetMapping mapping ) {
267
278
RelTrait [] newTraits = new RelTrait [traits .length ];
268
279
for (int i = 0 ; i < traits .length ; i ++) {
@@ -402,6 +413,7 @@ public int size() {
402
413
* @param trait Trait
403
414
* @return Trait in canonical form
404
415
*/
416
+ @ CheckReturnValue
405
417
public <T extends RelTrait > T canonize (T trait ) {
406
418
if (trait == null ) {
407
419
// Return "trait" makes the input type to be the same as the output type,
@@ -621,6 +633,7 @@ private int findIndex(RelTraitDef traitDef) {
621
633
* @param trait Trait
622
634
* @return Trait set with given trait
623
635
*/
636
+ @ CheckReturnValue
624
637
public RelTraitSet plus (RelTrait trait ) {
625
638
if (contains (trait )) {
626
639
return this ;
@@ -637,6 +650,7 @@ public RelTraitSet plus(RelTrait trait) {
637
650
return cache .getOrAdd (new RelTraitSet (cache , newTraits ));
638
651
}
639
652
653
+ @ CheckReturnValue
640
654
public RelTraitSet plusAll (RelTrait [] traits ) {
641
655
RelTraitSet t = this ;
642
656
for (RelTrait trait : traits ) {
@@ -645,12 +659,14 @@ public RelTraitSet plusAll(RelTrait[] traits) {
645
659
return t ;
646
660
}
647
661
662
+ @ CheckReturnValue
648
663
public RelTraitSet merge (RelTraitSet additionalTraits ) {
649
664
return plusAll (additionalTraits .traits );
650
665
}
651
666
652
667
/** Returns a list of traits that are in {@code traitSet} but not in this
653
668
* RelTraitSet. */
669
+ @ CheckReturnValue
654
670
public ImmutableList <RelTrait > difference (RelTraitSet traitSet ) {
655
671
final ImmutableList .Builder <RelTrait > builder = ImmutableList .builder ();
656
672
final int n =
@@ -680,6 +696,7 @@ public boolean allSimple() {
680
696
681
697
/** Returns a trait set similar to this one but with all composite traits
682
698
* flattened. */
699
+ @ CheckReturnValue
683
700
public RelTraitSet simplify () {
684
701
RelTraitSet x = this ;
685
702
for (int i = 0 ; i < traits .length ; i ++) {
@@ -701,6 +718,7 @@ private static class Cache {
701
718
Cache () {
702
719
}
703
720
721
+ @ CheckReturnValue
704
722
RelTraitSet getOrAdd (RelTraitSet t ) {
705
723
RelTraitSet exist = map .putIfAbsent (t , t );
706
724
return exist == null ? t : exist ;
0 commit comments