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 17 package com.google.common.collect.testing; 18 19 import java.util.List; 20 import java.util.Map; 21 import java.util.Set; 22 23 /** 24 * Creates map entries using sample keys and sample values. 25 * 26 * <p>This class is GWT compatible. 27 * 28 * @author Jesse Wilson 29 */ 30 public abstract class TestMapEntrySetGenerator<K, V> 31 implements TestSetGenerator<Map.Entry<K, V>> { 32 private final SampleElements<K> keys; 33 private final SampleElements<V> values; 34 35 protected TestMapEntrySetGenerator( 36 SampleElements<K> keys, SampleElements<V> values) { 37 this.keys = keys; 38 this.values = values; 39 } 40 41 @Override 42 public SampleElements<Map.Entry<K, V>> samples() { 43 return SampleElements.mapEntries(keys, values); 44 } 45 46 @Override 47 public Set<Map.Entry<K, V>> create(Object... elements) { 48 Map.Entry<K, V>[] entries = createArray(elements.length); 49 Platform.unsafeArrayCopy(elements, 0, entries, 0, elements.length); 50 return createFromEntries(entries); 51 } 52 53 public abstract Set<Map.Entry<K, V>> createFromEntries( 54 Map.Entry<K, V>[] entries); 55 56 @Override 57 @SuppressWarnings("unchecked") // generic arrays make typesafety sad 58 public Map.Entry<K, V>[] createArray(int length) { 59 return new Map.Entry[length]; 60 } 61 62 /** Returns the original element list, unchanged. */ 63 @Override 64 public List<Map.Entry<K, V>> order(List<Map.Entry<K, V>> insertionOrder) { 65 return insertionOrder; 66 } 67 } 68