diff options
author | 2016-06-02 13:23:39 +0200 | |
---|---|---|
committer | 2016-06-06 12:52:33 +0000 | |
commit | 303c10fd52abfbeeeb17a94b3b502d539e9197ac (patch) | |
tree | 41bc38400138a6e956e34428f48d8dfe22db0d4d /v3po/translate-utils/src/main/java | |
parent | 64c12426da9aaf583a0262783b8bc5a1674f7081 (diff) |
Intializers for the new vlan model
Change-Id: I513f0b190e9d9e669663a9a216e7c72b1ebeb10d
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'v3po/translate-utils/src/main/java')
-rw-r--r-- | v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/RWUtils.java | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/RWUtils.java b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/RWUtils.java index dbfed04b0..b712e159c 100644 --- a/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/RWUtils.java +++ b/v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/RWUtils.java @@ -21,13 +21,15 @@ import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; +import io.fd.honeycomb.v3po.translate.SubtreeManager; import io.fd.honeycomb.v3po.translate.read.ChildReader; import io.fd.honeycomb.v3po.translate.write.ChildWriter; -import io.fd.honeycomb.v3po.translate.SubtreeManager; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.stream.Collector; +import java.util.stream.Collectors; import javax.annotation.Nonnull; import org.opendaylight.yangtools.yang.binding.Augmentation; import org.opendaylight.yangtools.yang.binding.ChildOf; @@ -41,6 +43,21 @@ public final class RWUtils { private RWUtils() {} /** + * Collector expecting only a single resulting item from a stream + */ + public static<T> Collector<T,?,T> singleItemCollector() { + return Collectors.collectingAndThen( + Collectors.toList(), + list -> { + if (list.size() != 1) { + throw new IllegalStateException("Unexpected size of list: " + list + ". Single item expected"); + } + return list.get(0); + } + ); + } + + /** * Find next item in ID after provided type */ @Nonnull |