001/*
002 * Copyright (C) 2008 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.ImmutableBiMap;
022import com.google.common.collect.Maps;
023import java.util.Arrays;
024import java.util.Map;
025import java.util.Map.Entry;
026
027/**
028 * Generators of various {@link com.google.common.collect.BiMap}s and derived collections.
029 *
030 * @author Jared Levy
031 * @author Hayward Chan
032 */
033@GwtCompatible
034@ElementTypesAreNonnullByDefault
035public class BiMapGenerators {
036  public static class ImmutableBiMapGenerator extends TestStringBiMapGenerator {
037    @Override
038    protected BiMap<String, String> create(Entry<String, String>[] entries) {
039      ImmutableBiMap.Builder<String, String> builder = ImmutableBiMap.builder();
040      for (Entry<String, String> entry : entries) {
041        builder.put(entry.getKey(), entry.getValue());
042      }
043      return builder.build();
044    }
045  }
046
047  public static class ImmutableBiMapCopyOfGenerator extends TestStringBiMapGenerator {
048    @Override
049    protected BiMap<String, String> create(Entry<String, String>[] entries) {
050      Map<String, String> builder = Maps.newLinkedHashMap();
051      for (Entry<String, String> entry : entries) {
052        builder.put(entry.getKey(), entry.getValue());
053      }
054      return ImmutableBiMap.copyOf(builder);
055    }
056  }
057
058  public static class ImmutableBiMapCopyOfEntriesGenerator extends TestStringBiMapGenerator {
059    @Override
060    protected BiMap<String, String> create(Entry<String, String>[] entries) {
061      return ImmutableBiMap.copyOf(Arrays.asList(entries));
062    }
063  }
064}