1/*
2 * Copyright (C) 2012 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.google;
18
19import com.google.common.annotations.GwtCompatible;
20import com.google.common.collect.BiMap;
21import com.google.common.collect.testing.Helpers;
22import com.google.common.collect.testing.SampleElements;
23
24import java.util.List;
25import java.util.Map;
26import java.util.Map.Entry;
27
28/**
29 * Implementation helper for {@link TestBiMapGenerator} for use with bimaps of
30 * strings.
31 *
32 * @author Chris Povirk
33 * @author Jared Levy
34 * @author George van den Driessche
35 * @author Louis Wasserman
36 */
37@GwtCompatible
38public abstract class TestStringBiMapGenerator
39    implements TestBiMapGenerator<String, String> {
40
41  @Override
42  public SampleElements<Map.Entry<String, String>> samples() {
43    return new SampleElements<Map.Entry<String, String>>(
44        Helpers.mapEntry("one", "January"),
45        Helpers.mapEntry("two", "February"),
46        Helpers.mapEntry("three", "March"),
47        Helpers.mapEntry("four", "April"),
48        Helpers.mapEntry("five", "May")
49    );
50  }
51
52  @Override
53  public final BiMap<String, String> create(Object... entries) {
54    @SuppressWarnings("unchecked")
55    Entry<String, String>[] array = new Entry[entries.length];
56    int i = 0;
57    for (Object o : entries) {
58      @SuppressWarnings("unchecked")
59      Entry<String, String> e = (Entry<String, String>) o;
60      array[i++] = e;
61    }
62    return create(array);
63  }
64
65  protected abstract BiMap<String, String> create(
66      Entry<String, String>[] entries);
67
68  @Override
69  @SuppressWarnings("unchecked")
70  public final Entry<String, String>[] createArray(int length) {
71    return new Entry[length];
72  }
73
74  @Override
75  public final String[] createKeyArray(int length) {
76    return new String[length];
77  }
78
79  @Override
80  public final String[] createValueArray(int length) {
81    return new String[length];
82  }
83
84  /** Returns the original element list, unchanged. */
85  @Override
86  public Iterable<Entry<String, String>> order(
87      List<Entry<String, String>> insertionOrder) {
88    return insertionOrder;
89  }
90}
91