001/* 002 * Copyright (C) 2012 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.google.common.collect.testing.google; 018 019import com.google.common.annotations.GwtCompatible; 020import com.google.common.collect.ListMultimap; 021import com.google.common.collect.testing.Helpers; 022import com.google.common.collect.testing.SampleElements; 023import java.util.Collection; 024import java.util.List; 025import java.util.Map.Entry; 026 027/** 028 * A skeleton generator for a {@code ListMultimap} implementation. 029 * 030 * @author Louis Wasserman 031 */ 032@GwtCompatible 033@ElementTypesAreNonnullByDefault 034public abstract class TestStringListMultimapGenerator 035 implements TestListMultimapGenerator<String, String> { 036 037 @Override 038 public SampleElements<Entry<String, String>> samples() { 039 return new SampleElements<>( 040 Helpers.mapEntry("one", "January"), 041 Helpers.mapEntry("two", "February"), 042 Helpers.mapEntry("three", "March"), 043 Helpers.mapEntry("four", "April"), 044 Helpers.mapEntry("five", "May")); 045 } 046 047 @Override 048 public SampleElements<String> sampleKeys() { 049 return new SampleElements<>("one", "two", "three", "four", "five"); 050 } 051 052 @Override 053 public SampleElements<String> sampleValues() { 054 return new SampleElements<>("January", "February", "March", "April", "May"); 055 } 056 057 @Override 058 public Collection<String> createCollection(Iterable<? extends String> values) { 059 return Helpers.copyToList(values); 060 } 061 062 @Override 063 public final ListMultimap<String, String> create(Object... entries) { 064 @SuppressWarnings("unchecked") 065 Entry<String, String>[] array = (Entry<String, String>[]) new Entry<?, ?>[entries.length]; 066 int i = 0; 067 for (Object o : entries) { 068 @SuppressWarnings("unchecked") 069 Entry<String, String> e = (Entry<String, String>) o; 070 array[i++] = e; 071 } 072 return create(array); 073 } 074 075 protected abstract ListMultimap<String, String> create(Entry<String, String>[] entries); 076 077 @Override 078 @SuppressWarnings("unchecked") 079 public final Entry<String, String>[] createArray(int length) { 080 return (Entry<String, String>[]) new Entry<?, ?>[length]; 081 } 082 083 @Override 084 public final String[] createKeyArray(int length) { 085 return new String[length]; 086 } 087 088 @Override 089 public final String[] createValueArray(int length) { 090 return new String[length]; 091 } 092 093 /** Returns the original element list, unchanged. */ 094 @Override 095 public Iterable<Entry<String, String>> order(List<Entry<String, String>> insertionOrder) { 096 return insertionOrder; 097 } 098}