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