Debian Codegraph @

guava-testlib/src/com/google/common/collect/testing/TestContainerGenerator.java

raw
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;
18
19 import com.google.common.annotations.GwtCompatible;
20 import java.util.Collection;
21 import java.util.List;
22 import java.util.Map;
23
24 /**
25 * To be implemented by test generators of things that can contain elements. Such things include
26 * both {@link Collection} and {@link Map}; since there isn't an established collective noun that
27 * encompasses both of these, 'container' is used.
28 *
29 * @author George van den Driessche
30 */
31 @GwtCompatible
32 public interface TestContainerGenerator<T, E> {
33 /** Returns the sample elements that this generate populates its container with. */
34 SampleElements<E> samples();
35
36 /**
37 * Creates a new container containing the given elements. TODO: would be nice to figure out how to
38 * use E... or E[] as a parameter type, but this doesn't seem to work because Java creates an
39 * array of the erased type.
40 */
41 T create(Object... elements);
42
43 /**
44 * Helper method to create an array of the appropriate type used by this generator. The returned
45 * array will contain only nulls.
46 */
47 E[] createArray(int length);
48
49 /**
50 * Returns the iteration ordering of elements, given the order in which they were added to the
51 * container. This method may return the original list unchanged, the original list modified in
52 * place, or a different list.
53 *
54 * <p>If the order is non-deterministic, as with {@link java.util.HashSet}, this method can return
55 * its input unmodified. Provided that the test suite is built without {@link
56 * com.google.common.collect.testing.features.CollectionFeature#KNOWN_ORDER}, the tests will look
57 * only at the returned contents without regard for order.
58 */
59 Iterable<E> order(List<E> insertionOrder);
60 }