2 * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.util;
10 import com.google.common.annotations.Beta;
11 import com.google.common.base.MoreObjects;
12 import java.util.function.BiFunction;
15 * Utility helping to implement readable equals() methods.
20 * public boolean equals(Object obj) {
21 * return EvenMoreObjects.equalsHelper(this, obj,
22 * (one, another) -> Objects.equals(one.name, another.name) && Objects.equals(one.age, another.age));
26 * <p>See <a href="https://github.com/google/guava/issues/2521">Guava issue proposing contributing this</a>.
30 * @author Michael Vorburger, Red Hat
33 public final class EvenMoreObjects {
35 @SuppressWarnings("unchecked")
36 public static <T> boolean equalsHelper(T self, Object other, BooleanEqualsFunction<T> equals) {
43 if (self.getClass() != other.getClass()) {
46 return equals.apply(self, (T) other);
50 public interface BooleanEqualsFunction<T> extends BiFunction<T, T, Boolean> { }
52 private EvenMoreObjects() { }