Rename binding-runtime-dynamic to binding-loader
[yangtools.git] / common / yang-common / src / main / java / org / opendaylight / yangtools / yang / common / NotRevision.java
1 /*
2  * Copyright (c) 2024 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.common;
9
10 import java.io.DataInput;
11 import java.io.IOException;
12 import java.io.ObjectInputStream;
13 import java.io.ObjectOutputStream;
14 import java.io.ObjectStreamException;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17
18 /**
19  * An empty alternative to {@link Revision}. This contract is exactly the same as the {@code type string} block from
20  * this fragment from {@code ietf-yang-library}:
21  * <pre>{@code
22  *   type union {
23  *     type revision-identifier;
24  *     type string {
25  *       length "0";
26  *     }
27  *   }
28  * }</pre>
29  */
30 @NonNullByDefault
31 public final class NotRevision implements RevisionUnion {
32     @java.io.Serial
33     private static final long serialVersionUID = 1L;
34     private static final NotRevision INSTANCE = new NotRevision();
35
36     private NotRevision() {
37         // Hidden on purpose
38     }
39
40     public static NotRevision of() {
41         return INSTANCE;
42     }
43
44     public static NotRevision readFrom(final DataInput in) throws IOException {
45         final var str = in.readUTF();
46         if (!str.isEmpty()) {
47             throw new IOException("Unexpected value '" + str + "'");
48         }
49         return of();
50     }
51
52     @Override
53     public @Nullable Revision revision() {
54         return null;
55     }
56
57     @Override
58     public String unionString() {
59         return "";
60     }
61
62     @Override
63     public int hashCode() {
64         return 0;
65     }
66
67     @Override
68     public boolean equals(final @Nullable Object obj) {
69         return this == obj;
70     }
71
72     @Override
73     public String toString() {
74         return unionString();
75     }
76
77     @java.io.Serial
78     Object writeReplace() {
79         return new RUv1("");
80     }
81
82     @java.io.Serial
83     private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException {
84         Revision.throwNSE();
85     }
86
87     @java.io.Serial
88     private void readObjectNoData() throws ObjectStreamException {
89         Revision.throwNSE();
90     }
91
92     @java.io.Serial
93     private void writeObject(final ObjectOutputStream stream) throws IOException {
94         Revision.throwNSE();
95     }
96 }