Use List.of() in DuplicateEntry
[yangtools.git] / data / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / YangErrorInfo.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, s.r.o. 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.yang.data.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.MoreObjects;
14 import org.eclipse.jdt.annotation.NonNullByDefault;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
17
18 /**
19  * An element of {@code error-info} container, as modeled in {@code errorInfoType} of
20  * <a href="https://datatracker.ietf.org/doc/html/rfc6241#appendix-B">RFC6241, Appendix B</a>.
21  */
22 @Beta
23 @NonNullByDefault
24 // FIXME: 8.0.0: Split this into two interfaces + scenery:
25 //               - yang.common.ErrorInfoRepresentation
26 //               - make NormalizedNodeContainer implement ErrorInfoRepresentation
27 public final class YangErrorInfo {
28     // FIXME: 8.0.0: implies it extends ErrorInfoRepresentation, but ... perhaps NormalizedErrorInfo
29     private final DataContainerChild value;
30
31     private YangErrorInfo(final DataContainerChild value) {
32         this.value = requireNonNull(value);
33     }
34
35     public static YangErrorInfo of(final DataContainerChild value) {
36         return new YangErrorInfo(value);
37     }
38
39     // FIXME: 8.0.0: yang.common version returns ErrorInfoRepresentation
40     public DataContainerChild value() {
41         return value;
42     }
43
44     @Override
45     public int hashCode() {
46         return value.hashCode();
47     }
48
49     @Override
50     public boolean equals(final @Nullable Object obj) {
51         return obj == this || obj instanceof YangErrorInfo && value.equals(((YangErrorInfo) obj).value);
52     }
53
54     @Override
55     public String toString() {
56         return MoreObjects.toStringHelper(this).add("value", value).toString();
57     }
58 }