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