Bump to odlparent-3.0.2 and yangtools-2.0.0
[bgpcep.git] / bgp / path-selection-mode / src / main / java / org / opendaylight / protocol / bgp / mode / BesthPathStateUtil.java
1 /*
2  * Copyright (c) 2018 AT&T Intellectual Property. 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 package org.opendaylight.protocol.bgp.mode;
9
10 import java.util.List;
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.Segments;
13
14 public final class BesthPathStateUtil {
15     private BesthPathStateUtil() {
16         throw new UnsupportedOperationException();
17     }
18
19     public static AsNumber getPeerAs(final List<Segments> segments) {
20         if (segments.isEmpty()) {
21             return new AsNumber(0L);
22         }
23         for (final Segments seg : segments) {
24             if (seg.getAsSequence() != null && !seg.getAsSequence().isEmpty()) {
25                 return segments.get(0).getAsSequence().get(0);
26             }
27         }
28         return new AsNumber(0L);
29     }
30 }