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.Map;
25  import java.util.Set;
26  
27  /**
28   * Optional features of classes derived from {@code Map}.
29   *
30   * @author George van den Driessche
31   */
32  // Enum values use constructors with generic varargs.
33  @SuppressWarnings("unchecked")
34  @GwtCompatible
35  public enum MapFeature implements Feature<Map> {
36    /**
37     * The map does not throw {@code NullPointerException} on calls such as
38     * {@code containsKey(null)}, {@code get(null)},
39     * {@code keySet().contains(null)} or {@code remove(null)}.
40     */
41    ALLOWS_NULL_KEY_QUERIES,
42    ALLOWS_NULL_KEYS(ALLOWS_NULL_KEY_QUERIES),
43    /**
44     * The map does not throw {@code NullPointerException} on calls such as
45     * {@code containsValue(null)}, {@code values().contains(null)} or
46     * {@code values().remove(null)}.
47     */
48    ALLOWS_NULL_VALUE_QUERIES,
49    ALLOWS_NULL_VALUES(ALLOWS_NULL_VALUE_QUERIES),
50    /**
51     * The map does not throw {@code NullPointerException} on calls such as
52     * {@code entrySet().contains(null)} or {@code entrySet().remove(null)}
53     */
54    ALLOWS_NULL_ENTRY_QUERIES,
55    /**
56     * The map does not throw {@code NullPointerException} on any {@code null}
57     * queries.
58     *
59     * @see #ALLOWS_NULL_KEY_QUERIES
60     * @see #ALLOWS_NULL_VALUE_QUERIES
61     * @see #ALLOWS_NULL_ENTRY_QUERIES
62     */
63    ALLOWS_ANY_NULL_QUERIES(
64        ALLOWS_NULL_ENTRY_QUERIES, ALLOWS_NULL_KEY_QUERIES, ALLOWS_NULL_VALUE_QUERIES),
65    RESTRICTS_KEYS,
66    RESTRICTS_VALUES,
67    SUPPORTS_PUT,
68    SUPPORTS_REMOVE,
69    FAILS_FAST_ON_CONCURRENT_MODIFICATION,
70    /**
71     * Indicates that the constructor or factory method of a map, usually an
72     * immutable map, throws an {@link IllegalArgumentException} when presented
73     * with duplicate keys instead of discarding all but one.
74     */
75    REJECTS_DUPLICATES_AT_CREATION,
76  
77    GENERAL_PURPOSE(SUPPORTS_PUT, SUPPORTS_REMOVE);
78  
79    private final Set<Feature<? super Map>> implied;
80  
81    MapFeature(Feature<? super Map>... implied) {
82      this.implied = Helpers.copyToSet(implied);
83    }
84  
85    @Override
86    public Set<Feature<? super Map>> getImpliedFeatures() {
87      return implied;
88    }
89  
90    @Retention(RetentionPolicy.RUNTIME)
91    @Inherited
92    @TesterAnnotation
93    public @interface Require {
94      public abstract MapFeature[] value() default {};
95  
96      public abstract MapFeature[] absent() default {};
97    }
98  }