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