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