ListFeature.java revision 3c77433663281544363151bf284b0240dfd22a42
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
17package com.google.common.collect.testing.features;
18
19import com.google.common.annotations.GwtCompatible;
20import com.google.common.collect.testing.Helpers;
21
22import java.lang.annotation.Inherited;
23import java.lang.annotation.Retention;
24import java.lang.annotation.RetentionPolicy;
25import java.util.List;
26import java.util.Set;
27
28/**
29 * Optional features of classes derived from {@code List}.
30 *
31 * <p>This class is GWT compatible.
32 *
33 * @author George van den Driessche
34 */
35// Enum values use constructors with generic varargs.
36@SuppressWarnings("unchecked")
37@GwtCompatible
38public enum ListFeature implements Feature<List> {
39  SUPPORTS_SET,
40  SUPPORTS_ADD_WITH_INDEX(CollectionFeature.SUPPORTS_ADD),
41  SUPPORTS_REMOVE_WITH_INDEX(CollectionFeature.SUPPORTS_REMOVE),
42
43  GENERAL_PURPOSE(
44      CollectionFeature.GENERAL_PURPOSE,
45      SUPPORTS_SET,
46      SUPPORTS_ADD_WITH_INDEX,
47      SUPPORTS_REMOVE_WITH_INDEX
48  ),
49
50  /** Features supported by lists where only removal is allowed. */
51  REMOVE_OPERATIONS(
52      CollectionFeature.SUPPORTS_REMOVE,
53      SUPPORTS_REMOVE_WITH_INDEX
54  );
55
56  private final Set<Feature<? super List>> implied;
57
58  ListFeature(Feature<? super List> ... implied) {
59    this.implied = Helpers.copyToSet(implied);
60  }
61
62  @Override
63  public Set<Feature<? super List>> getImpliedFeatures() {
64    return implied;
65  }
66
67  @Retention(RetentionPolicy.RUNTIME)
68  @Inherited
69  @TesterAnnotation
70  public @interface Require {
71    ListFeature[] value() default {};
72    ListFeature[] absent() default {};
73  }
74}
75