1 /* 2 * Copyright (C) 2007 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 java.util.Arrays; 21 import java.util.List; 22 import java.util.Set; 23 24 @GwtIncompatible 25 public class ImmutableSetFloodingTest extends AbstractHashFloodingTest<Set<Object>> { ImmutableSetFloodingTest()26 public ImmutableSetFloodingTest() { 27 super( 28 Arrays.asList(ConstructionPathway.values()), 29 n -> n * Math.log(n), 30 ImmutableList.of( 31 QueryOp.create( 32 "contains", 33 (s, o) -> { 34 boolean unused = s.contains(o); 35 }, 36 Math::log))); 37 } 38 39 /** All the ways to construct an ImmutableSet. */ 40 enum ConstructionPathway implements Construction<Set<Object>> { 41 OF { 42 @Override create(List<?> list)43 public ImmutableSet<Object> create(List<?> list) { 44 Object o1 = list.get(0); 45 Object o2 = list.get(1); 46 Object o3 = list.get(2); 47 Object o4 = list.get(3); 48 Object o5 = list.get(4); 49 Object o6 = list.get(5); 50 Object[] rest = list.subList(6, list.size()).toArray(); 51 return ImmutableSet.of(o1, o2, o3, o4, o5, o6, rest); 52 } 53 }, 54 COPY_OF_ARRAY { 55 @Override create(List<?> list)56 public ImmutableSet<Object> create(List<?> list) { 57 return ImmutableSet.copyOf(list.toArray()); 58 } 59 }, 60 COPY_OF_LIST { 61 @Override create(List<?> list)62 public ImmutableSet<Object> create(List<?> list) { 63 return ImmutableSet.copyOf(list); 64 } 65 }, 66 BUILDER_ADD_ONE_BY_ONE { 67 @Override create(List<?> list)68 public ImmutableSet<Object> create(List<?> list) { 69 ImmutableSet.Builder<Object> builder = ImmutableSet.builder(); 70 for (Object o : list) { 71 builder.add(o); 72 } 73 return builder.build(); 74 } 75 }, 76 BUILDER_ADD_ARRAY { 77 @Override create(List<?> list)78 public ImmutableSet<Object> create(List<?> list) { 79 ImmutableSet.Builder<Object> builder = ImmutableSet.builder(); 80 builder.add(list.toArray()); 81 return builder.build(); 82 } 83 }, 84 BUILDER_ADD_LIST { 85 @Override create(List<?> list)86 public ImmutableSet<Object> create(List<?> list) { 87 ImmutableSet.Builder<Object> builder = ImmutableSet.builder(); 88 builder.addAll(list); 89 return builder.build(); 90 } 91 }; 92 } 93 } 94