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.testing; 18 19 import java.util.Map; 20 21 /** 22 * A container class for the five sample elements we need for testing. 23 * 24 * <p>This class is GWT compatible. 25 * 26 * @author Kevin Bourrillion 27 */ 28 public class SampleElements<E> { 29 // TODO: rename e3, e4 => missing1, missing2 30 public final E e0; 31 public final E e1; 32 public final E e2; 33 public final E e3; 34 public final E e4; 35 36 public SampleElements(E e0, E e1, E e2, E e3, E e4) { 37 this.e0 = e0; 38 this.e1 = e1; 39 this.e2 = e2; 40 this.e3 = e3; 41 this.e4 = e4; 42 } 43 44 public static class Strings extends SampleElements<String> { 45 public Strings() { 46 // elements aren't sorted, to better test SortedSet iteration ordering 47 super("b", "a", "c", "d", "e"); 48 } 49 50 // for testing SortedSet and SortedMap methods 51 public static final String BEFORE_FIRST = "\0"; 52 public static final String BEFORE_FIRST_2 = "\0\0"; 53 public static final String MIN_ELEMENT = "a"; 54 public static final String AFTER_LAST = "z"; 55 public static final String AFTER_LAST_2 = "zz"; 56 } 57 58 public static class Enums extends SampleElements<AnEnum> { 59 public Enums() { 60 // elements aren't sorted, to better test SortedSet iteration ordering 61 super(AnEnum.B, AnEnum.A, AnEnum.C, AnEnum.D, AnEnum.E); 62 } 63 } 64 65 public static <K, V> SampleElements<Map.Entry<K, V>> mapEntries( 66 SampleElements<K> keys, SampleElements<V> values) { 67 return new SampleElements<Map.Entry<K, V>>( 68 Helpers.mapEntry(keys.e0, values.e0), 69 Helpers.mapEntry(keys.e1, values.e1), 70 Helpers.mapEntry(keys.e2, values.e2), 71 Helpers.mapEntry(keys.e3, values.e3), 72 Helpers.mapEntry(keys.e4, values.e4)); 73 } 74 75 public static class Unhashables extends SampleElements<UnhashableObject> { 76 public Unhashables() { 77 super(new UnhashableObject(1), 78 new UnhashableObject(2), 79 new UnhashableObject(3), 80 new UnhashableObject(4), 81 new UnhashableObject(5)); 82 } 83 } 84 85 public static class Colliders extends SampleElements<Object> { 86 public Colliders() { 87 super(new Collider(1), 88 new Collider(2), 89 new Collider(3), 90 new Collider(4), 91 new Collider(5)); 92 } 93 } 94 95 private static class Collider { 96 final int value; 97 98 Collider(int value) { 99 this.value = value; 100 } 101 102 @Override public boolean equals(Object obj) { 103 return obj instanceof Collider && ((Collider) obj).value == value; 104 } 105 106 @Override public int hashCode() { 107 return 1; // evil! 108 } 109 } 110 } 111