Use RevisionUnion in QNameModule
[yangtools.git] / common / yang-common / src / main / java / org / opendaylight / yangtools / yang / common / Revision.java
index 53722d3ca877e70d8871bdfe268b566506ced98f..cb4ca183f4ec82bc8ae5a3431f32f8a911fec1ef 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.yangtools.yang.common;
 
 import static java.util.Objects.requireNonNull;
 
+import java.io.DataInput;
 import java.io.Externalizable;
 import java.io.IOException;
 import java.io.NotSerializableException;
@@ -109,6 +110,18 @@ public final class Revision implements RevisionUnion {
         return str;
     }
 
+    public static @NonNull Revision readFrom(final DataInput in) throws IOException {
+        return ofRead(in.readUTF());
+    }
+
+    static @NonNull Revision ofRead(final @NonNull String str) throws IOException {
+        try {
+            return of(str);
+        } catch (DateTimeParseException e) {
+            throw new IOException("Invalid revision-date string", e);
+        }
+    }
+
     /**
      * Compare two {@link Optional}s wrapping Revisions. Arguments and return value are consistent with
      * {@link java.util.Comparator#compare(Object, Object)} interface contract. Missing revisions compare as lower