2 * Copyright (c) 2019 PANTHEON.tech s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104;
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;
16 * Utility methods for converting legacy RFC7895 {@code modules-state} Revision to and from various representations.
18 @SuppressWarnings("deprecation")
19 public final class LegacyRevisionUtils {
20 private static final CommonLeafs.@NonNull Revision EMPTY_REVISION = new CommonLeafs.Revision("");
22 private LegacyRevisionUtils() {
27 * Return an empty {@link CommonLeafs.Revision}.
29 * @return An empty Revision.
31 public static CommonLeafs.@NonNull Revision emptyRevision() {
32 return EMPTY_REVISION;
35 public static CommonLeafs.@NonNull Revision fromString(final String defaultValue) {
36 return defaultValue.isEmpty() ? EMPTY_REVISION
37 : new CommonLeafs.Revision(new RevisionIdentifier(defaultValue));
41 * Create a {@link CommonLeafs.Revision} from an optional {@link Revision}.
43 * @param revision Optional {@link Revision}
45 * @throws NullPointerException if {@code revision} is null
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);
53 * Create an optional {@link Revision} from a {@link CommonLeafs.Revision}.
55 * @param revision A Revision
56 * @return Optional {@link Revision}
57 * @throws NullPointerException if {@code revision} is null
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();