--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.opendaylight.odlparent</groupId>
+ <artifactId>bundle-parent</artifactId>
+ <version>1.7.0-SNAPSHOT</version>
+ <relativePath/>
+ </parent>
+
+ <groupId>org.opendaylight.ovsdb</groupId>
+ <artifactId>utils.yang-utils</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>jsr305</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.opendaylight.ovsdb.utils.yang
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
--- /dev/null
+/*
+ * Copyright © 2016 Red Hat, Inc. and others.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.ovsdb.utils.yang;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * YANG utility functions.
+ */
+public final class YangUtils {
+ /**
+ * Prevent instantiation.
+ */
+ private YangUtils() {
+ // Nothing to do
+ }
+
+ /**
+ * Copies a list of YANG key-value items to the given map. Any {@code null} key or value will cause an error.
+ *
+ * @param map The map to fill.
+ * @param yangList The list of YANG key-value items.
+ * @param keyExtractor The key extractor function to use.
+ * @param valueExtractor The value extractor function to use.
+ * @param <T> The YANG item type.
+ * @param <K> The key type.
+ * @param <V> The value type.
+ * @return The map.
+ */
+ @Nonnull
+ public static <T, K, V> Map<K, V> copyYangKeyValueListToMap(@Nonnull Map<K, V> map, @Nullable Iterable<T> yangList,
+ @Nonnull Function<T, K> keyExtractor,
+ @Nonnull Function<T, V> valueExtractor) {
+ if (yangList != null) {
+ for (T yangValue : yangList) {
+ K key = keyExtractor.apply(yangValue);
+ V value = valueExtractor.apply(yangValue);
+ Preconditions.checkNotNull(key);
+ Preconditions.checkNotNull(value);
+ map.put(key, value);
+ }
+ }
+ return map;
+ }
+
+ /**
+ * Converts a list of YANG key-value items to a map.
+ *
+ * @param yangList The list of YANG key-value items.
+ * @param keyExtractor The key extractor function to use.
+ * @param valueExtractor The value extractor function to use.
+ * @param <T> The YANG item type.
+ * @param <K> The key type.
+ * @param <V> The value type.
+ * @return The map.
+ */
+ @Nonnull
+ public static <T, K, V> Map<K, V> convertYangKeyValueListToMap(@Nullable Iterable<T> yangList,
+ @Nonnull Function<T, K> keyExtractor,
+ @Nonnull Function<T, V> valueExtractor) {
+ return copyYangKeyValueListToMap(new HashMap<>(), yangList, keyExtractor, valueExtractor);
+ }
+}