001/* 002 * Copyright (C) 2008 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; 018 019import com.google.common.annotations.GwtCompatible; 020import java.util.List; 021import java.util.Map; 022import java.util.Map.Entry; 023 024/** 025 * Implementation helper for {@link TestMapGenerator} for use with maps of strings. 026 * 027 * @author Chris Povirk 028 * @author Jared Levy 029 * @author George van den Driessche 030 */ 031@GwtCompatible 032public abstract class TestStringMapGenerator implements TestMapGenerator<String, String> { 033 034 @Override 035 public SampleElements<Entry<String, String>> samples() { 036 return new SampleElements<>( 037 Helpers.mapEntry("one", "January"), 038 Helpers.mapEntry("two", "February"), 039 Helpers.mapEntry("three", "March"), 040 Helpers.mapEntry("four", "April"), 041 Helpers.mapEntry("five", "May")); 042 } 043 044 @Override 045 public Map<String, String> create(Object... entries) { 046 @SuppressWarnings("unchecked") 047 Entry<String, String>[] array = new Entry[entries.length]; 048 int i = 0; 049 for (Object o : entries) { 050 @SuppressWarnings("unchecked") 051 Entry<String, String> e = (Entry<String, String>) o; 052 array[i++] = e; 053 } 054 return create(array); 055 } 056 057 protected abstract Map<String, String> create(Entry<String, String>[] entries); 058 059 @Override 060 @SuppressWarnings("unchecked") 061 public final Entry<String, String>[] createArray(int length) { 062 return new Entry[length]; 063 } 064 065 @Override 066 public final String[] createKeyArray(int length) { 067 return new String[length]; 068 } 069 070 @Override 071 public final String[] createValueArray(int length) { 072 return new String[length]; 073 } 074 075 /** Returns the original element list, unchanged. */ 076 @Override 077 public Iterable<Entry<String, String>> order(List<Entry<String, String>> insertionOrder) { 078 return insertionOrder; 079 } 080}