summaryrefslogtreecommitdiffstats
path: root/v3po/translate-utils/src/main/java/io
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2016-06-02 13:23:39 +0200
committerMarek Gradzki <mgradzki@cisco.com>2016-06-06 12:52:33 +0000
commit2da2d410e5bd679b356b079972b441695c353833 (patch)
tree606c630e72af772aedfbe48a67c8d8dc28206718 /v3po/translate-utils/src/main/java/io
parentf6df9d5f3456e8bd2c355a9ae852ef2ecf75e6b5 (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/io')
-rw-r--r--v3po/translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/util/RWUtils.java19
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