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