Java
61 строка · 1.7 Кб
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.Enums;
21import java.util.Collections;
22import java.util.List;
23import java.util.Set;
24
25/**
26* An abstract TestSetGenerator for generating sets containing enum values.
27*
28* @author Kevin Bourrillion
29*/
30@GwtCompatible
31@ElementTypesAreNonnullByDefault
32public abstract class TestEnumSetGenerator implements TestSetGenerator<AnEnum> {
33@Override
34public SampleElements<AnEnum> samples() {
35return new Enums();
36}
37
38@Override
39public Set<AnEnum> create(Object... elements) {
40AnEnum[] array = new AnEnum[elements.length];
41int i = 0;
42for (Object e : elements) {
43array[i++] = (AnEnum) e;
44}
45return create(array);
46}
47
48protected abstract Set<AnEnum> create(AnEnum[] elements);
49
50@Override
51public AnEnum[] createArray(int length) {
52return new AnEnum[length];
53}
54
55/** Sorts the enums according to their natural ordering. */
56@Override
57public List<AnEnum> order(List<AnEnum> insertionOrder) {
58Collections.sort(insertionOrder);
59return insertionOrder;
60}
61}
62