001/* 002 * Copyright (C) 2007 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 com.google.common.collect.testing.SampleElements.Strings; 021import java.util.List; 022import java.util.Set; 023 024/** 025 * Create string sets for collection tests. 026 * 027 * @author Kevin Bourrillion 028 */ 029@GwtCompatible 030public abstract class TestStringSetGenerator implements TestSetGenerator<String> { 031 @Override 032 public SampleElements<String> samples() { 033 return new Strings(); 034 } 035 036 @Override 037 public Set<String> create(Object... elements) { 038 String[] array = new String[elements.length]; 039 int i = 0; 040 for (Object e : elements) { 041 array[i++] = (String) e; 042 } 043 return create(array); 044 } 045 046 protected abstract Set<String> create(String[] elements); 047 048 @Override 049 public String[] createArray(int length) { 050 return new String[length]; 051 } 052 053 /** 054 * {@inheritDoc} 055 * 056 * <p>By default, returns the supplied elements in their given order; however, generators for 057 * containers with a known order other than insertion order must override this method. 058 * 059 * <p>Note: This default implementation is overkill (but valid) for an unordered container. An 060 * equally valid implementation for an unordered container is to throw an exception. The chosen 061 * implementation, however, has the advantage of working for insertion-ordered containers, as 062 * well. 063 */ 064 @Override 065 public List<String> order(List<String> insertionOrder) { 066 return insertionOrder; 067 } 068}