11d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert/* 21d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Copyright (C) 2009 The Guava Authors 31d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 41d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Licensed under the Apache License, Version 2.0 (the "License"); 51d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * you may not use this file except in compliance with the License. 61d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * You may obtain a copy of the License at 71d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 81d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * http://www.apache.org/licenses/LICENSE-2.0 91d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 101d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Unless required by applicable law or agreed to in writing, software 111d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * distributed under the License is distributed on an "AS IS" BASIS, 121d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * See the License for the specific language governing permissions and 141d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * limitations under the License. 151d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 161d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 171d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertpackage com.google.common.collect.testing; 181d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 197dd252788645e940eada959bdde927426e2531c9Paul Duffinimport com.google.common.annotations.GwtCompatible; 201d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertimport com.google.common.collect.testing.SampleElements.Unhashables; 211d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 221d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertimport java.util.Collection; 231d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertimport java.util.List; 241d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 251d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert/** 261d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Creates collections containing unhashable sample elements, to be tested. 271d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 281d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @author Regina O'Dell 291d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 307dd252788645e940eada959bdde927426e2531c9Paul Duffin@GwtCompatible 311d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertpublic abstract class 321d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert TestUnhashableCollectionGenerator<T extends Collection<UnhashableObject>> 331d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert implements TestCollectionGenerator<UnhashableObject> { 341d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert @Override 351d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert public SampleElements<UnhashableObject> samples() { 361d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert return new Unhashables(); 371d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert } 381d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 391d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert @Override 401d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert public T create(Object... elements) { 411d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert UnhashableObject[] array = createArray(elements.length); 421d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert int i = 0; 431d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert for (Object e : elements) { 441d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert array[i++] = (UnhashableObject) e; 451d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert } 461d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert return create(array); 471d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert } 481d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 491d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 501d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Creates a new collection containing the given elements; implement this 511d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * method instead of {@link #create(Object...)}. 521d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 531d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert protected abstract T create(UnhashableObject[] elements); 541d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 551d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert @Override 561d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert public UnhashableObject[] createArray(int length) { 571d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert return new UnhashableObject[length]; 581d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert } 591d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 601d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert @Override 611d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert public Iterable<UnhashableObject> order( 621d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert List<UnhashableObject> insertionOrder) { 631d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert return insertionOrder; 641d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert } 657dd252788645e940eada959bdde927426e2531c9Paul Duffin} 66