TestUnhashableCollectionGenerator.java revision 7dd252788645e940eada959bdde927426e2531c9
1/* 2 * Copyright (C) 2009 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; 20import com.google.common.collect.testing.SampleElements.Unhashables; 21 22import java.util.Collection; 23import java.util.List; 24 25/** 26 * Creates collections containing unhashable sample elements, to be tested. 27 * 28 * <p>This class is GWT compatible. 29 * 30 * @author Regina O'Dell 31 */ 32@GwtCompatible 33public abstract class 34 TestUnhashableCollectionGenerator<T extends Collection<UnhashableObject>> 35 implements TestCollectionGenerator<UnhashableObject> { 36 @Override 37 public SampleElements<UnhashableObject> samples() { 38 return new Unhashables(); 39 } 40 41 @Override 42 public T create(Object... elements) { 43 UnhashableObject[] array = createArray(elements.length); 44 int i = 0; 45 for (Object e : elements) { 46 array[i++] = (UnhashableObject) e; 47 } 48 return create(array); 49 } 50 51 /** 52 * Creates a new collection containing the given elements; implement this 53 * method instead of {@link #create(Object...)}. 54 */ 55 protected abstract T create(UnhashableObject[] elements); 56 57 @Override 58 public UnhashableObject[] createArray(int length) { 59 return new UnhashableObject[length]; 60 } 61 62 @Override 63 public Iterable<UnhashableObject> order( 64 List<UnhashableObject> insertionOrder) { 65 return insertionOrder; 66 } 67} 68