2753d9d6e25c9602723bee48bfb051ccd27c6946
[bgpcep.git] / bgp / path-selection-mode / src / main / java / org / opendaylight / protocol / bgp / mode / spi / RouteEntryUtil.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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
9 package org.opendaylight.protocol.bgp.mode.spi;
10
11 import org.opendaylight.protocol.bgp.mode.api.BestPath;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
14 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
15 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
16 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
17
18 public final class RouteEntryUtil {
19     private RouteEntryUtil() {
20         throw new UnsupportedOperationException();
21     }
22
23     public static MapEntryNode createSimpleRouteValue(final PathArgument routeId, final BestPath path) {
24         final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> b = Builders.mapEntryBuilder();
25         b.withNodeIdentifier((NodeIdentifierWithPredicates) routeId);
26         b.addChild(path.getAttributes());
27         return b.build();
28     }
29
30     public static MapEntryNode createComplexRouteValue(final PathArgument routeId, final BestPath path,
31             final MapEntryNode mapValues) {
32         final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder
33                 = Builders.mapEntryBuilder();
34         mapEntryBuilder.withNodeIdentifier((NodeIdentifierWithPredicates) routeId);
35         mapEntryBuilder.addChild(path.getAttributes());
36         mapValues.getValue().forEach(mapEntryBuilder::addChild);
37         return mapEntryBuilder.build();
38     }
39 }