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.features; 018 019import static com.google.common.collect.testing.Helpers.copyToSet; 020 021import com.google.common.annotations.GwtCompatible; 022import java.util.Collections; 023import java.util.Set; 024import org.checkerframework.checker.nullness.qual.Nullable; 025 026/** 027 * Encapsulates the constraints that a class under test must satisfy in order for a tester method to 028 * be run against that class. 029 * 030 * @author George van den Driessche 031 */ 032@GwtCompatible 033public final class TesterRequirements { 034 private final Set<Feature<?>> presentFeatures; 035 private final Set<Feature<?>> absentFeatures; 036 037 public TesterRequirements(Set<Feature<?>> presentFeatures, Set<Feature<?>> absentFeatures) { 038 this.presentFeatures = copyToSet(presentFeatures); 039 this.absentFeatures = copyToSet(absentFeatures); 040 } 041 042 public TesterRequirements(TesterRequirements tr) { 043 this(tr.getPresentFeatures(), tr.getAbsentFeatures()); 044 } 045 046 public TesterRequirements() { 047 this(Collections.<Feature<?>>emptySet(), Collections.<Feature<?>>emptySet()); 048 } 049 050 public final Set<Feature<?>> getPresentFeatures() { 051 return presentFeatures; 052 } 053 054 public final Set<Feature<?>> getAbsentFeatures() { 055 return absentFeatures; 056 } 057 058 @Override 059 public boolean equals(@Nullable Object object) { 060 if (object == this) { 061 return true; 062 } 063 if (object instanceof TesterRequirements) { 064 TesterRequirements that = (TesterRequirements) object; 065 return this.presentFeatures.equals(that.presentFeatures) 066 && this.absentFeatures.equals(that.absentFeatures); 067 } 068 return false; 069 } 070 071 @Override 072 public int hashCode() { 073 return presentFeatures.hashCode() * 31 + absentFeatures.hashCode(); 074 } 075 076 @Override 077 public String toString() { 078 return "{TesterRequirements: present=" + presentFeatures + ", absent=" + absentFeatures + "}"; 079 } 080 081 private static final long serialVersionUID = 0; 082}