001/*
002 * Copyright (C) 2008 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.google.common.collect.testing.features;
018
019import com.google.common.annotations.GwtCompatible;
020import com.google.common.collect.testing.Helpers;
021import java.lang.annotation.Inherited;
022import java.lang.annotation.Retention;
023import java.lang.annotation.RetentionPolicy;
024import java.util.List;
025import java.util.Set;
026
027/**
028 * Optional features of classes derived from {@code List}.
029 *
030 * @author George van den Driessche
031 */
032// Enum values use constructors with generic varargs.
033@SuppressWarnings("unchecked")
034@GwtCompatible
035public enum ListFeature implements Feature<List> {
036  SUPPORTS_SET,
037  SUPPORTS_ADD_WITH_INDEX(CollectionFeature.SUPPORTS_ADD),
038  SUPPORTS_REMOVE_WITH_INDEX(CollectionFeature.SUPPORTS_REMOVE),
039
040  GENERAL_PURPOSE(
041      CollectionFeature.GENERAL_PURPOSE,
042      SUPPORTS_SET,
043      SUPPORTS_ADD_WITH_INDEX,
044      SUPPORTS_REMOVE_WITH_INDEX),
045
046  /** Features supported by lists where only removal is allowed. */
047  REMOVE_OPERATIONS(CollectionFeature.REMOVE_OPERATIONS, SUPPORTS_REMOVE_WITH_INDEX);
048
049  private final Set<Feature<? super List>> implied;
050
051  ListFeature(Feature<? super List>... implied) {
052    this.implied = Helpers.copyToSet(implied);
053  }
054
055  @Override
056  public Set<Feature<? super List>> getImpliedFeatures() {
057    return implied;
058  }
059
060  @Retention(RetentionPolicy.RUNTIME)
061  @Inherited
062  @TesterAnnotation
063  public @interface Require {
064    ListFeature[] value() default {};
065
066    ListFeature[] absent() default {};
067  }
068}