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