Java
69 строк · 2.1 Кб
1/*
2* Copyright (C) 2007 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;
18
19import com.google.common.annotations.GwtCompatible;
20import com.google.common.collect.testing.SampleElements.Strings;
21import java.util.List;
22import java.util.Set;
23
24/**
25* Create string sets for collection tests.
26*
27* @author Kevin Bourrillion
28*/
29@GwtCompatible
30@ElementTypesAreNonnullByDefault
31public abstract class TestStringSetGenerator implements TestSetGenerator<String> {
32@Override
33public SampleElements<String> samples() {
34return new Strings();
35}
36
37@Override
38public Set<String> create(Object... elements) {
39String[] array = new String[elements.length];
40int i = 0;
41for (Object e : elements) {
42array[i++] = (String) e;
43}
44return create(array);
45}
46
47protected abstract Set<String> create(String[] elements);
48
49@Override
50public String[] createArray(int length) {
51return new String[length];
52}
53
54/**
55* {@inheritDoc}
56*
57* <p>By default, returns the supplied elements in their given order; however, generators for
58* containers with a known order other than insertion order must override this method.
59*
60* <p>Note: This default implementation is overkill (but valid) for an unordered container. An
61* equally valid implementation for an unordered container is to throw an exception. The chosen
62* implementation, however, has the advantage of working for insertion-ordered containers, as
63* well.
64*/
65@Override
66public List<String> order(List<String> insertionOrder) {
67return insertionOrder;
68}
69}
70