guava
81 строка · 2.5 Кб
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
17package com.google.common.collect.testing.features;
18
19import com.google.common.annotations.GwtCompatible;
20import com.google.common.collect.testing.Helpers;
21import java.util.Collections;
22import java.util.Set;
23import org.checkerframework.checker.nullness.qual.Nullable;
24
25/**
26* Encapsulates the constraints that a class under test must satisfy in order for a tester method to
27* be run against that class.
28*
29* @author George van den Driessche
30*/
31@GwtCompatible
32public final class TesterRequirements {
33private final Set<Feature<?>> presentFeatures;
34private final Set<Feature<?>> absentFeatures;
35
36public TesterRequirements(Set<Feature<?>> presentFeatures, Set<Feature<?>> absentFeatures) {
37this.presentFeatures = Helpers.copyToSet(presentFeatures);
38this.absentFeatures = Helpers.copyToSet(absentFeatures);
39}
40
41public TesterRequirements(TesterRequirements tr) {
42this(tr.getPresentFeatures(), tr.getAbsentFeatures());
43}
44
45public TesterRequirements() {
46this(Collections.<Feature<?>>emptySet(), Collections.<Feature<?>>emptySet());
47}
48
49public final Set<Feature<?>> getPresentFeatures() {
50return presentFeatures;
51}
52
53public final Set<Feature<?>> getAbsentFeatures() {
54return absentFeatures;
55}
56
57@Override
58public boolean equals(@Nullable Object object) {
59if (object == this) {
60return true;
61}
62if (object instanceof TesterRequirements) {
63TesterRequirements that = (TesterRequirements) object;
64return this.presentFeatures.equals(that.presentFeatures)
65&& this.absentFeatures.equals(that.absentFeatures);
66}
67return false;
68}
69
70@Override
71public int hashCode() {
72return presentFeatures.hashCode() * 31 + absentFeatures.hashCode();
73}
74
75@Override
76public String toString() {
77return "{TesterRequirements: present=" + presentFeatures + ", absent=" + absentFeatures + "}";
78}
79
80private static final long serialVersionUID = 0;
81}
82