Use pattern matching on instanceof in yang-common
[yangtools.git] / common / yang-common / src / main / java / org / opendaylight / yangtools / yang / common / ETv1.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.common;
9
10 import java.io.Externalizable;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14
15 /**
16  * Externalizable proxy for {@link ErrorTag}.
17  */
18 final class ETv1 implements Externalizable {
19     private static final long serialVersionUID = 1L;
20
21     private String elementBody;
22
23     @SuppressWarnings("checkstyle:redundantModifier")
24     public ETv1() {
25         // visible for Externalizable
26     }
27
28     ETv1(final ErrorTag tag) {
29         elementBody = tag.elementBody();
30     }
31
32     @Override
33     public void writeExternal(final ObjectOutput out) throws IOException {
34         out.writeUTF(elementBody);
35     }
36
37     @Override
38     public void readExternal(final ObjectInput in) throws IOException {
39         elementBody = in.readUTF();
40     }
41
42     Object readResolve() {
43         return new ErrorTag(elementBody);
44     }
45 }