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 034public class BiMapGenerators { 035 public static class ImmutableBiMapGenerator extends TestStringBiMapGenerator { 036 @Override 037 protected BiMap<String, String> create(Entry<String, String>[] entries) { 038 ImmutableBiMap.Builder<String, String> builder = ImmutableBiMap.builder(); 039 for (Entry<String, String> entry : entries) { 040 builder.put(entry.getKey(), entry.getValue()); 041 } 042 return builder.build(); 043 } 044 } 045 046 public static class ImmutableBiMapCopyOfGenerator extends TestStringBiMapGenerator { 047 @Override 048 protected BiMap<String, String> create(Entry<String, String>[] entries) { 049 Map<String, String> builder = Maps.newLinkedHashMap(); 050 for (Entry<String, String> entry : entries) { 051 builder.put(entry.getKey(), entry.getValue()); 052 } 053 return ImmutableBiMap.copyOf(builder); 054 } 055 } 056 057 public static class ImmutableBiMapCopyOfEntriesGenerator extends TestStringBiMapGenerator { 058 @Override 059 protected BiMap<String, String> create(Entry<String, String>[] entries) { 060 return ImmutableBiMap.copyOf(Arrays.asList(entries)); 061 } 062 } 063}