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.features; 18 19 import com.google.common.annotations.GwtCompatible; 20 import com.google.common.collect.testing.Helpers; 21 import java.util.Collections; 22 import java.util.Set; 23 import org.checkerframework.checker.nullness.qual.Nullable; 24 25 /** 26 * Encapsulates the constraints that a class under test must satisfy in order for a tester method to 27 * be run against that class. 28 * 29 * @author George van den Driessche 30 */ 31 @GwtCompatible 32 public final class TesterRequirements { 33 private final Set<Feature<?>> presentFeatures; 34 private final Set<Feature<?>> absentFeatures; 35 TesterRequirements(Set<Feature<?>> presentFeatures, Set<Feature<?>> absentFeatures)36 public TesterRequirements(Set<Feature<?>> presentFeatures, Set<Feature<?>> absentFeatures) { 37 this.presentFeatures = Helpers.copyToSet(presentFeatures); 38 this.absentFeatures = Helpers.copyToSet(absentFeatures); 39 } 40 TesterRequirements(TesterRequirements tr)41 public TesterRequirements(TesterRequirements tr) { 42 this(tr.getPresentFeatures(), tr.getAbsentFeatures()); 43 } 44 TesterRequirements()45 public TesterRequirements() { 46 this(Collections.<Feature<?>>emptySet(), Collections.<Feature<?>>emptySet()); 47 } 48 getPresentFeatures()49 public final Set<Feature<?>> getPresentFeatures() { 50 return presentFeatures; 51 } 52 getAbsentFeatures()53 public final Set<Feature<?>> getAbsentFeatures() { 54 return absentFeatures; 55 } 56 57 @Override equals(@ullable Object object)58 public boolean equals(@Nullable Object object) { 59 if (object == this) { 60 return true; 61 } 62 if (object instanceof TesterRequirements) { 63 TesterRequirements that = (TesterRequirements) object; 64 return this.presentFeatures.equals(that.presentFeatures) 65 && this.absentFeatures.equals(that.absentFeatures); 66 } 67 return false; 68 } 69 70 @Override hashCode()71 public int hashCode() { 72 return presentFeatures.hashCode() * 31 + absentFeatures.hashCode(); 73 } 74 75 @Override toString()76 public String toString() { 77 return "{TesterRequirements: present=" + presentFeatures + ", absent=" + absentFeatures + "}"; 78 } 79 80 private static final long serialVersionUID = 0; 81 } 82