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 
17 package com.google.common.collect.testing.google;
18 
19 import com.google.common.annotations.GwtCompatible;
20 import com.google.common.collect.BiMap;
21 import com.google.common.collect.testing.Helpers;
22 import com.google.common.collect.testing.SampleElements;
23 
24 import java.util.List;
25 import java.util.Map;
26 import 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
38 public abstract class TestStringBiMapGenerator
39     implements TestBiMapGenerator<String, String> {
40 
41   @Override
samples()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
create(Object... entries)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 
create( Entry<String, String>[] entries)65   protected abstract BiMap<String, String> create(
66       Entry<String, String>[] entries);
67 
68   @Override
69   @SuppressWarnings("unchecked")
createArray(int length)70   public final Entry<String, String>[] createArray(int length) {
71     return new Entry[length];
72   }
73 
74   @Override
createKeyArray(int length)75   public final String[] createKeyArray(int length) {
76     return new String[length];
77   }
78 
79   @Override
createValueArray(int length)80   public final String[] createValueArray(int length) {
81     return new String[length];
82   }
83 
84   /** Returns the original element list, unchanged. */
85   @Override
order( List<Entry<String, String>> insertionOrder)86   public Iterable<Entry<String, String>> order(
87       List<Entry<String, String>> insertionOrder) {
88     return insertionOrder;
89   }
90 }
91