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