TestStringMapGenerator.java revision 7dd252788645e940eada959bdde927426e2531c9
1/* 2 * Copyright (C) 2008 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 17package com.google.common.collect.testing; 18 19import com.google.common.annotations.GwtCompatible; 20 21import java.util.List; 22import java.util.Map; 23import java.util.Map.Entry; 24 25/** 26 * Implementation helper for {@link TestMapGenerator} for use with maps of 27 * strings. 28 * 29 * <p>This class is GWT compatible. 30 * 31 * @author Chris Povirk 32 * @author Jared Levy 33 * @author George van den Driessche 34 */ 35@GwtCompatible 36public abstract class TestStringMapGenerator 37 implements TestMapGenerator<String, String> { 38 39 @Override 40 public SampleElements<Map.Entry<String, String>> samples() { 41 return new SampleElements<Map.Entry<String, String>>( 42 Helpers.mapEntry("one", "January"), 43 Helpers.mapEntry("two", "February"), 44 Helpers.mapEntry("three", "March"), 45 Helpers.mapEntry("four", "April"), 46 Helpers.mapEntry("five", "May") 47 ); 48 } 49 50 @Override 51 public Map<String, String> create(Object... entries) { 52 @SuppressWarnings("unchecked") 53 Entry<String, String>[] array = new Entry[entries.length]; 54 int i = 0; 55 for (Object o : entries) { 56 @SuppressWarnings("unchecked") 57 Entry<String, String> e = (Entry<String, String>) o; 58 array[i++] = e; 59 } 60 return create(array); 61 } 62 63 protected abstract Map<String, String> create( 64 Entry<String, String>[] entries); 65 66 @Override 67 @SuppressWarnings("unchecked") 68 public final Entry<String, String>[] createArray(int length) { 69 return new Entry[length]; 70 } 71 72 @Override 73 public final String[] createKeyArray(int length) { 74 return new String[length]; 75 } 76 77 @Override 78 public final String[] createValueArray(int length) { 79 return new String[length]; 80 } 81 82 /** Returns the original element list, unchanged. */ 83 @Override 84 public Iterable<Entry<String, String>> order( 85 List<Entry<String, String>> insertionOrder) { 86 return insertionOrder; 87 } 88} 89