1 /*
2 * Copyright 2014 - 2020 Rafael Winterhalter
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 package net.bytebuddy.matcher;
17
18 import net.bytebuddy.build.HashCodeAndEqualsPlugin;
19
20 /**
21 * An element matcher that checks an object's equality to another object.
22 *
23 * @param <T> The type of the matched entity.
24 */
25 @HashCodeAndEqualsPlugin.Enhance
26 public class EqualityMatcher<T> extends ElementMatcher.Junction.AbstractBase<T> {
27
28 /**
29 * The object that is checked to be equal to the matched value.
30 */
31 private final Object value;
32
33 /**
34 * Creates an element matcher that tests for equality.
35 *
36 * @param value The object that is checked to be equal to the matched value.
37 */
38 public EqualityMatcher(Object value) {
39 this.value = value;
40 }
41
42 /**
43 * {@inheritDoc}
44 */
45 public boolean matches(T target) {
46 return value.equals(target);
47 }
48
49 @Override
50 public String toString() {
51 return "is(" + value + ")";
52 }
53 }
54