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