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