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.collect.testing.Helpers;
20
21import java.lang.annotation.Inherited;
22import java.lang.annotation.Retention;
23import java.lang.annotation.RetentionPolicy;
24import java.util.List;
25import java.util.Set;
26
27/**
28 * Optional features of classes derived from {@code List}.
29 *
30 * <p>This class is GWT compatible.
31 *
32 * @author George van den Driessche
33 */
34// Enum values use constructors with generic varargs.
35@SuppressWarnings("unchecked")
36public enum ListFeature implements Feature<List> {
37  SUPPORTS_SET,
38  SUPPORTS_ADD_WITH_INDEX,
39  SUPPORTS_ADD_ALL_WITH_INDEX,
40  SUPPORTS_REMOVE_WITH_INDEX,
41
42  GENERAL_PURPOSE(
43      CollectionFeature.GENERAL_PURPOSE,
44      SUPPORTS_SET,
45      SUPPORTS_ADD_WITH_INDEX,
46      SUPPORTS_ADD_ALL_WITH_INDEX,
47      SUPPORTS_REMOVE_WITH_INDEX
48  ),
49
50  /** Features supported by lists where only removal is allowed. */
51  REMOVE_OPERATIONS(
52      CollectionFeature.REMOVE_OPERATIONS,
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