Remove getValue() methods from model.api.stmt interfaces
[yangtools.git] / common / util / src / main / java / org / opendaylight / yangtools / util / EvenMoreObjects.java
1 /*
2  * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.util;
9
10 import com.google.common.base.MoreObjects;
11 import java.util.function.BiFunction;
12
13 /**
14  * Utility helping to implement readable equals() methods.
15  *
16  * <p>Usage:
17  * <pre>
18  *{@literal @}Override
19  * public boolean equals(Object obj) {
20  *     return EvenMoreObjects.equalsHelper(this, obj,
21  *        (one, another) -&gt; Objects.equals(one.name, another.name) &amp;&amp; Objects.equals(one.age, another.age));
22  * }
23  * </pre>
24  *
25  * <p>See <a href="https://github.com/google/guava/issues/2521">Guava issue proposing contributing this</a>.
26  *
27  * @see MoreObjects
28  *
29  * @author Michael Vorburger, Red Hat
30  */
31 @Deprecated(since = "11.0.0", forRemoval = true)
32 public final class EvenMoreObjects {
33
34     @SuppressWarnings("unchecked")
35     public static <T> boolean equalsHelper(final T self, final Object other, final BooleanEqualsFunction<T> equals) {
36         if (other == self) {
37             return true;
38         }
39         if (other == null) {
40             return false;
41         }
42         if (self.getClass() != other.getClass()) {
43             return false;
44         }
45         return equals.apply(self, (T) other);
46     }
47
48     @FunctionalInterface
49     public interface BooleanEqualsFunction<T> extends BiFunction<T, T, Boolean> { }
50
51     private EvenMoreObjects() {
52
53     }
54 }
55