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 033public abstract class TestStringListMultimapGenerator 034 implements TestListMultimapGenerator<String, String> { 035 036 @Override 037 public SampleElements<Entry<String, String>> samples() { 038 return new SampleElements<>( 039 Helpers.mapEntry("one", "January"), 040 Helpers.mapEntry("two", "February"), 041 Helpers.mapEntry("three", "March"), 042 Helpers.mapEntry("four", "April"), 043 Helpers.mapEntry("five", "May")); 044 } 045 046 @Override 047 public SampleElements<String> sampleKeys() { 048 return new SampleElements<>("one", "two", "three", "four", "five"); 049 } 050 051 @Override 052 public SampleElements<String> sampleValues() { 053 return new SampleElements<>("January", "February", "March", "April", "May"); 054 } 055 056 @Override 057 public Collection<String> createCollection(Iterable<? extends String> values) { 058 return Helpers.copyToList(values); 059 } 060 061 @Override 062 public final ListMultimap<String, String> create(Object... entries) { 063 @SuppressWarnings("unchecked") 064 Entry<String, String>[] array = new Entry[entries.length]; 065 int i = 0; 066 for (Object o : entries) { 067 @SuppressWarnings("unchecked") 068 Entry<String, String> e = (Entry<String, String>) o; 069 array[i++] = e; 070 } 071 return create(array); 072 } 073 074 protected abstract ListMultimap<String, String> create(Entry<String, String>[] entries); 075 076 @Override 077 @SuppressWarnings("unchecked") 078 public final Entry<String, String>[] createArray(int length) { 079 return new Entry[length]; 080 } 081 082 @Override 083 public final String[] createKeyArray(int length) { 084 return new String[length]; 085 } 086 087 @Override 088 public final String[] createValueArray(int length) { 089 return new String[length]; 090 } 091 092 /** Returns the original element list, unchanged. */ 093 @Override 094 public Iterable<Entry<String, String>> order(List<Entry<String, String>> insertionOrder) { 095 return insertionOrder; 096 } 097}