• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.collect.testing.Helpers;
20 
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  * <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")
36 public enum MapFeature implements Feature<Map> {
37   /**
38    * The map does not throw {@code NullPointerException} on calls such as
39    * {@code containsKey(null)}, {@code get(null)}, or {@code remove(null)}.
40    */
41   ALLOWS_NULL_QUERIES,
42   ALLOWS_NULL_KEYS (ALLOWS_NULL_QUERIES),
43   ALLOWS_NULL_VALUES,
44   RESTRICTS_KEYS,
45   RESTRICTS_VALUES,
46   SUPPORTS_PUT,
47   SUPPORTS_PUT_ALL,
48   SUPPORTS_REMOVE,
49   SUPPORTS_CLEAR,
50   /**
51    * Indicates that the constructor or factory method of a map, usually an
52    * immutable map, throws an {@link IllegalArgumentException} when presented
53    * with duplicate keys instead of discarding all but one.
54    */
55   REJECTS_DUPLICATES_AT_CREATION,
56 
57   GENERAL_PURPOSE(
58       SUPPORTS_PUT,
59       SUPPORTS_PUT_ALL,
60       SUPPORTS_REMOVE,
61       SUPPORTS_CLEAR
62   ),
63 
64   /** Features supported by maps where only removal is allowed. */
65   REMOVE_OPERATIONS(
66       SUPPORTS_REMOVE,
67       SUPPORTS_CLEAR
68     );
69 
70   private final Set<Feature<? super Map>> implied;
71 
MapFeature(Feature<? super Map> .... implied)72   MapFeature(Feature<? super Map> ... implied) {
73     this.implied = Helpers.copyToSet(implied);
74   }
75 
76   @Override
getImpliedFeatures()77   public Set<Feature<? super Map>> getImpliedFeatures() {
78     return implied;
79   }
80 
81   @Retention(RetentionPolicy.RUNTIME)
82   @Inherited
83   @TesterAnnotation
84   public @interface Require {
value()85     public abstract MapFeature[] value() default {};
absent()86     public abstract MapFeature[] absent() default {};
87   }
88 }
89