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 */
016
017package com.google.common.collect.testing.google;
018
019import com.google.common.annotations.GwtCompatible;
020import com.google.common.collect.BiMap;
021import com.google.common.collect.testing.Helpers;
022import com.google.common.collect.testing.SampleElements;
023import java.util.List;
024import java.util.Map.Entry;
025
026/**
027 * Implementation helper for {@link TestBiMapGenerator} for use with bimaps of strings.
028 *
029 * @author Chris Povirk
030 * @author Jared Levy
031 * @author George van den Driessche
032 * @author Louis Wasserman
033 */
034@GwtCompatible
035public abstract class TestStringBiMapGenerator implements TestBiMapGenerator<String, String> {
036
037  @Override
038  public SampleElements<Entry<String, String>> samples() {
039    return new SampleElements<>(
040        Helpers.mapEntry("one", "January"),
041        Helpers.mapEntry("two", "February"),
042        Helpers.mapEntry("three", "March"),
043        Helpers.mapEntry("four", "April"),
044        Helpers.mapEntry("five", "May"));
045  }
046
047  @Override
048  public final BiMap<String, String> create(Object... entries) {
049    @SuppressWarnings("unchecked")
050    Entry<String, String>[] array = new Entry[entries.length];
051    int i = 0;
052    for (Object o : entries) {
053      @SuppressWarnings("unchecked")
054      Entry<String, String> e = (Entry<String, String>) o;
055      array[i++] = e;
056    }
057    return create(array);
058  }
059
060  protected abstract BiMap<String, String> create(Entry<String, String>[] entries);
061
062  @Override
063  @SuppressWarnings("unchecked")
064  public final Entry<String, String>[] createArray(int length) {
065    return new Entry[length];
066  }
067
068  @Override
069  public final String[] createKeyArray(int length) {
070    return new String[length];
071  }
072
073  @Override
074  public final String[] createValueArray(int length) {
075    return new String[length];
076  }
077
078  /** Returns the original element list, unchanged. */
079  @Override
080  public Iterable<Entry<String, String>> order(List<Entry<String, String>> insertionOrder) {
081    return insertionOrder;
082  }
083}