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