1 /* 2 * Copyright (C) 2008 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.common.collect; 18 19 import com.google.common.annotations.GwtIncompatible; 20 import com.google.errorprone.annotations.CanIgnoreReturnValue; 21 import java.util.Arrays; 22 import java.util.List; 23 24 @GwtIncompatible 25 public class ImmutableMultisetFloodingTest extends AbstractHashFloodingTest<Multiset<Object>> { ImmutableMultisetFloodingTest()26 public ImmutableMultisetFloodingTest() { 27 super( 28 Arrays.asList(ConstructionPathway.values()), 29 n -> n * Math.log(n), 30 ImmutableList.of( 31 QueryOp.create( 32 "count", 33 (ms, o) -> { 34 int unused = ms.count(o); 35 }, 36 Math::log))); 37 } 38 39 /** All the ways to create an ImmutableMultiset. */ 40 enum ConstructionPathway implements Construction<Multiset<Object>> { 41 COPY_OF_COLLECTION { 42 @Override create(List<?> keys)43 public ImmutableMultiset<Object> create(List<?> keys) { 44 return ImmutableMultiset.copyOf(keys); 45 } 46 }, 47 COPY_OF_ITERATOR { 48 @Override create(List<?> keys)49 public ImmutableMultiset<Object> create(List<?> keys) { 50 return ImmutableMultiset.copyOf(keys.iterator()); 51 } 52 }, 53 BUILDER_ADD_ENTRY_BY_ENTRY { 54 @Override create(List<?> keys)55 public ImmutableMultiset<Object> create(List<?> keys) { 56 ImmutableMultiset.Builder<Object> builder = ImmutableMultiset.builder(); 57 for (Object o : keys) { 58 builder.add(o); 59 } 60 return builder.build(); 61 } 62 }, 63 BUILDER_ADD_ALL_COLLECTION { 64 @Override create(List<?> keys)65 public ImmutableMultiset<Object> create(List<?> keys) { 66 ImmutableMultiset.Builder<Object> builder = ImmutableMultiset.builder(); 67 builder.addAll(keys); 68 return builder.build(); 69 } 70 }; 71 72 @CanIgnoreReturnValue 73 @Override create(List<?> keys)74 public abstract ImmutableMultiset<Object> create(List<?> keys); 75 } 76 } 77