ea34dcd2a6c12aca6d521a920a99b1f1d74c2caf
[mdsal.git] / model / ietf / rfc8525 / src / main / java / org / opendaylight / yang / gen / v1 / urn / ietf / params / xml / ns / yang / ietf / yang / library / rev190104 / module / list / CommonLeafsRevisionBuilder.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.module.list;
9
10 import java.util.Optional;
11 import org.eclipse.jdt.annotation.Nullable;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.RevisionIdentifier;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.list.CommonLeafs.Revision;
14
15 @SuppressWarnings("deprecation")
16 public final class CommonLeafsRevisionBuilder {
17     private static final Revision EMPTY_REVISION = new Revision("");
18
19     private CommonLeafsRevisionBuilder() {
20
21     }
22
23     /**
24      * Return an empty {@link Revision}.
25      *
26      * @return An empty Revision.
27      */
28     public static Revision emptyRevision() {
29         return EMPTY_REVISION;
30     }
31
32     /**
33      * Create a {@link Revision} from an optional {@link org.opendaylight.yangtools.yang.common.Revision}.
34      *
35      * @param revision Optional {@link org.opendaylight.yangtools.yang.common.Revision}
36      * @return A Revision
37      * @throws NullPointerException if revision is null
38      */
39     public static Revision fromYangCommon(final Optional<org.opendaylight.yangtools.yang.common.Revision> revision) {
40         return revision.map(rev -> new Revision(new RevisionIdentifier(rev.toString()))).orElse(EMPTY_REVISION);
41     }
42
43     /**
44      * Create an optional {@link org.opendaylight.yangtools.yang.common.Revision} from a {@link Revision}.
45      *
46      * @param revision A Revision
47      * @return Optional {@link org.opendaylight.yangtools.yang.common.Revision}
48      * @throws NullPointerException if revision is null
49      */
50     public static Optional<org.opendaylight.yangtools.yang.common.Revision> toYangCommon(final Revision revision) {
51         final @Nullable RevisionIdentifier id = revision.getRevisionIdentifier();
52         return id != null ? Optional.of(org.opendaylight.yangtools.yang.common.Revision.of(id.getValue()))
53                 : Optional.empty();
54     }
55
56     public static Revision getDefaultInstance(final String defaultValue) {
57         return defaultValue.isEmpty() ? EMPTY_REVISION : new Revision(new RevisionIdentifier(defaultValue));
58     }
59 }
60