1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*
* Copyright (C) 2008 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.common.collect.testing.features;
import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.testing.Helpers;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.SortedSet;
/**
* Optional features of classes derived from {@code Collection}.
*
* <p>This class is GWT compatible.
*
* @author George van den Driessche
*/
// Enum values use constructors with generic varargs.
@SuppressWarnings("unchecked")
@GwtCompatible
public enum CollectionFeature implements Feature<Collection> {
/**
* The collection must not throw {@code NullPointerException} on calls
* such as {@code contains(null)} or {@code remove(null)}, but instead
* must return a simple {@code false}.
*/
ALLOWS_NULL_QUERIES,
ALLOWS_NULL_VALUES (ALLOWS_NULL_QUERIES),
/**
* Indicates that a collection disallows certain elements (other than
* {@code null}, whose validity as an element is indicated by the presence
* or absence of {@link #ALLOWS_NULL_VALUES}).
* From the documentation for {@link Collection}:
* <blockquote>"Some collection implementations have restrictions on the
* elements that they may contain. For example, some implementations
* prohibit null elements, and some have restrictions on the types of their
* elements."</blockquote>
*/
RESTRICTS_ELEMENTS,
/**
* Indicates that a collection has a well-defined ordering of its elements.
* The ordering may depend on the element values, such as a {@link SortedSet},
* or on the insertion ordering, such as a {@link LinkedHashSet}. All list
* tests and sorted-collection tests automatically specify this feature.
*/
KNOWN_ORDER,
/**
* Indicates that a collection has a different {@link Object#toString}
* representation than most collections. If not specified, the collection
* tests will examine the value returned by {@link Object#toString}.
*/
NON_STANDARD_TOSTRING,
/**
* Indicates that the constructor or factory method of a collection, usually
* an immutable set, throws an {@link IllegalArgumentException} when presented
* with duplicate elements instead of collapsing them to a single element or
* including duplicate instances in the collection.
*/
REJECTS_DUPLICATES_AT_CREATION,
SUPPORTS_ADD,
SUPPORTS_REMOVE,
FAILS_FAST_ON_CONCURRENT_MODIFICATION,
/**
* Features supported by general-purpose collections -
* everything but {@link #RESTRICTS_ELEMENTS}.
* @see java.util.Collection the definition of general-purpose collections.
*/
GENERAL_PURPOSE(
SUPPORTS_ADD,
SUPPORTS_REMOVE),
/** Features supported by collections where only removal is allowed. */
REMOVE_OPERATIONS(
SUPPORTS_REMOVE),
SERIALIZABLE, SERIALIZABLE_INCLUDING_VIEWS(SERIALIZABLE),
/**
* For documenting collections that support no optional features, such as
* {@link java.util.Collections#emptySet}
*/
NONE();
private final Set<Feature<? super Collection>> implied;
CollectionFeature(Feature<? super Collection> ... implied) {
this.implied = Helpers.copyToSet(implied);
}
@Override
public Set<Feature<? super Collection>> getImpliedFeatures() {
return implied;
}
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@TesterAnnotation
public @interface Require {
CollectionFeature[] value() default {};
CollectionFeature[] absent() default {};
}
}
|