Do not generate union builders
[mdsal.git] / model / ietf / rfc8525 / src / main / java / org / opendaylight / yang / gen / v1 / urn / ietf / params / xml / ns / yang / ietf / yang / library / rev190104 / LegacyRevisionUtils.java
1 /*
2  * Copyright (c) 2019 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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104;
9
10 import java.util.Optional;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.CommonLeafs;
13 import org.opendaylight.yangtools.yang.common.Revision;
14
15 /**
16  * Utility methods for converting legacy RFC7895 {@code modules-state} Revision to and from various representations.
17  */
18 @SuppressWarnings("deprecation")
19 public final class LegacyRevisionUtils {
20     private static final CommonLeafs.@NonNull Revision EMPTY_REVISION = new CommonLeafs.Revision("");
21
22     private LegacyRevisionUtils() {
23         // Hidden on purpose
24     }
25
26     /**
27      * Return an empty {@link CommonLeafs.Revision}.
28      *
29      * @return An empty Revision.
30      */
31     public static CommonLeafs.@NonNull Revision emptyRevision() {
32         return EMPTY_REVISION;
33     }
34
35     public static CommonLeafs.@NonNull Revision fromString(final String defaultValue) {
36         return defaultValue.isEmpty() ? EMPTY_REVISION
37             : new CommonLeafs.Revision(new RevisionIdentifier(defaultValue));
38     }
39
40     /**
41      * Create a {@link CommonLeafs.Revision} from an optional {@link Revision}.
42      *
43      * @param revision Optional {@link Revision}
44      * @return A Revision
45      * @throws NullPointerException if {@code revision} is null
46      */
47     public static CommonLeafs.@NonNull Revision fromYangCommon(final Optional<Revision> revision) {
48         return revision.map(rev -> new CommonLeafs.Revision(new RevisionIdentifier(rev.toString())))
49             .orElse(EMPTY_REVISION);
50     }
51
52     /**
53      * Create an optional {@link Revision} from a {@link CommonLeafs.Revision}.
54      *
55      * @param revision A Revision
56      * @return Optional {@link Revision}
57      * @throws NullPointerException if {@code revision} is null
58      */
59     public static Optional<Revision> toYangCommon(final CommonLeafs.Revision revision) {
60         final var id = revision.getRevisionIdentifier();
61         return id != null ? Optional.of(Revision.of(id.getValue())) : Optional.empty();
62     }
63 }
64