001/*
002 * Copyright (C) 2012 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 */
016package com.google.common.collect.testing.google;
017
018import com.google.common.annotations.GwtCompatible;
019import com.google.common.collect.SetMultimap;
020import com.google.common.collect.testing.Helpers;
021import com.google.common.collect.testing.SampleElements;
022import java.util.Collection;
023import java.util.List;
024import java.util.Map.Entry;
025
026/**
027 * A skeleton generator for a {@code SetMultimap} implementation.
028 *
029 * @author Louis Wasserman
030 */
031@GwtCompatible
032public abstract class TestStringSetMultimapGenerator
033    implements TestSetMultimapGenerator<String, String> {
034
035  @Override
036  public SampleElements<Entry<String, String>> samples() {
037    return new SampleElements<>(
038        Helpers.mapEntry("one", "January"),
039        Helpers.mapEntry("two", "February"),
040        Helpers.mapEntry("three", "March"),
041        Helpers.mapEntry("four", "April"),
042        Helpers.mapEntry("five", "May"));
043  }
044
045  @Override
046  public SampleElements<String> sampleKeys() {
047    return new SampleElements<>("one", "two", "three", "four", "five");
048  }
049
050  @Override
051  public SampleElements<String> sampleValues() {
052    return new SampleElements<>("January", "February", "March", "April", "May");
053  }
054
055  @Override
056  public Collection<String> createCollection(Iterable<? extends String> values) {
057    return Helpers.copyToSet(values);
058  }
059
060  @Override
061  public final SetMultimap<String, String> create(Object... entries) {
062    @SuppressWarnings("unchecked")
063    Entry<String, String>[] array = new Entry[entries.length];
064    int i = 0;
065    for (Object o : entries) {
066      @SuppressWarnings("unchecked")
067      Entry<String, String> e = (Entry<String, String>) o;
068      array[i++] = e;
069    }
070    return create(array);
071  }
072
073  protected abstract SetMultimap<String, String> create(Entry<String, String>[] entries);
074
075  @Override
076  @SuppressWarnings("unchecked")
077  public final Entry<String, String>[] createArray(int length) {
078    return new Entry[length];
079  }
080
081  @Override
082  public final String[] createKeyArray(int length) {
083    return new String[length];
084  }
085
086  @Override
087  public final String[] createValueArray(int length) {
088    return new String[length];
089  }
090
091  /** Returns the original element list, unchanged. */
092  @Override
093  public Iterable<Entry<String, String>> order(List<Entry<String, String>> insertionOrder) {
094    return insertionOrder;
095  }
096}