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