View Javadoc
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  package com.google.common.collect.testing.google;
17  
18  import com.google.common.annotations.GwtCompatible;
19  import com.google.common.collect.SetMultimap;
20  import com.google.common.collect.testing.Helpers;
21  import com.google.common.collect.testing.SampleElements;
22  import java.util.Collection;
23  import java.util.List;
24  import java.util.Map;
25  import java.util.Map.Entry;
26  
27  /**
28   * A skeleton generator for a {@code SetMultimap} implementation.
29   *
30   * @author Louis Wasserman
31   */
32  @GwtCompatible
33  public abstract class TestStringSetMultimapGenerator
34      implements TestSetMultimapGenerator<String, String> {
35  
36    @Override
37    public SampleElements<Map.Entry<String, String>> samples() {
38      return new SampleElements<>(
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    @Override
47    public SampleElements<String> sampleKeys() {
48      return new SampleElements<>("one", "two", "three", "four", "five");
49    }
50  
51    @Override
52    public SampleElements<String> sampleValues() {
53      return new SampleElements<>("January", "February", "March", "April", "May");
54    }
55  
56    @Override
57    public Collection<String> createCollection(Iterable<? extends String> values) {
58      return Helpers.copyToSet(values);
59    }
60  
61    @Override
62    public final SetMultimap<String, String> create(Object... entries) {
63      @SuppressWarnings("unchecked")
64      Entry<String, String>[] array = new Entry[entries.length];
65      int i = 0;
66      for (Object o : entries) {
67        @SuppressWarnings("unchecked")
68        Entry<String, String> e = (Entry<String, String>) o;
69        array[i++] = e;
70      }
71      return create(array);
72    }
73  
74    protected abstract SetMultimap<String, String> create(Entry<String, String>[] entries);
75  
76    @Override
77    @SuppressWarnings("unchecked")
78    public final Entry<String, String>[] createArray(int length) {
79      return new Entry[length];
80    }
81  
82    @Override
83    public final String[] createKeyArray(int length) {
84      return new String[length];
85    }
86  
87    @Override
88    public final String[] createValueArray(int length) {
89      return new String[length];
90    }
91  
92    /** Returns the original element list, unchanged. */
93    @Override
94    public Iterable<Entry<String, String>> order(List<Entry<String, String>> insertionOrder) {
95      return insertionOrder;
96    }
97  }