1/*
2 * Copyright (C) 2009 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.Unhashables;
21
22import java.util.Collection;
23import java.util.List;
24
25/**
26 * Creates collections containing unhashable sample elements, to be tested.
27 *
28 * @author Regina O'Dell
29 */
30@GwtCompatible
31public abstract class
32    TestUnhashableCollectionGenerator<T extends Collection<UnhashableObject>>
33    implements TestCollectionGenerator<UnhashableObject> {
34  @Override
35  public SampleElements<UnhashableObject> samples() {
36    return new Unhashables();
37  }
38
39  @Override
40  public T create(Object... elements) {
41    UnhashableObject[] array = createArray(elements.length);
42    int i = 0;
43    for (Object e : elements) {
44      array[i++] = (UnhashableObject) e;
45    }
46    return create(array);
47  }
48
49  /**
50   * Creates a new collection containing the given elements; implement this
51   * method instead of {@link #create(Object...)}.
52   */
53  protected abstract T create(UnhashableObject[] elements);
54
55  @Override
56  public UnhashableObject[] createArray(int length) {
57    return new UnhashableObject[length];
58  }
59
60  @Override
61  public Iterable<UnhashableObject> order(
62      List<UnhashableObject> insertionOrder) {
63    return insertionOrder;
64  }
65}
66