View Javadoc
1   /*
2    * Copyright (C) 2008 The Guava Authors
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.google.common.collect.testing.features;
18  
19  import com.google.common.annotations.GwtCompatible;
20  import com.google.common.collect.testing.Helpers;
21  import java.lang.annotation.Inherited;
22  import java.lang.annotation.Retention;
23  import java.lang.annotation.RetentionPolicy;
24  import java.util.List;
25  import java.util.Set;
26  
27  /**
28   * Optional features of classes derived from {@code List}.
29   *
30   * @author George van den Driessche
31   */
32  // Enum values use constructors with generic varargs.
33  @SuppressWarnings("unchecked")
34  @GwtCompatible
35  public enum ListFeature implements Feature<List> {
36    SUPPORTS_SET,
37    SUPPORTS_ADD_WITH_INDEX(CollectionFeature.SUPPORTS_ADD),
38    SUPPORTS_REMOVE_WITH_INDEX(CollectionFeature.SUPPORTS_REMOVE),
39  
40    GENERAL_PURPOSE(
41        CollectionFeature.GENERAL_PURPOSE,
42        SUPPORTS_SET,
43        SUPPORTS_ADD_WITH_INDEX,
44        SUPPORTS_REMOVE_WITH_INDEX),
45  
46    /** Features supported by lists where only removal is allowed. */
47    REMOVE_OPERATIONS(CollectionFeature.REMOVE_OPERATIONS, SUPPORTS_REMOVE_WITH_INDEX);
48  
49    private final Set<Feature<? super List>> implied;
50  
51    ListFeature(Feature<? super List>... implied) {
52      this.implied = Helpers.copyToSet(implied);
53    }
54  
55    @Override
56    public Set<Feature<? super List>> getImpliedFeatures() {
57      return implied;
58    }
59  
60    @Retention(RetentionPolicy.RUNTIME)
61    @Inherited
62    @TesterAnnotation
63    public @interface Require {
64      ListFeature[] value() default {};
65  
66      ListFeature[] absent() default {};
67    }
68  }