Replace Preconditions.CheckNotNull per RequireNonNull
[bgpcep.git] / bgp / parser-spi / src / main / java / org / opendaylight / protocol / bgp / parser / spi / pojo / MultiPathSupportImpl.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.parser.spi.pojo;
10
11 import static java.util.Objects.requireNonNull;
12
13 import com.google.common.collect.ImmutableSet;
14 import java.util.List;
15 import java.util.Set;
16 import java.util.stream.Collectors;
17 import javax.annotation.Nonnull;
18 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
19 import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.SendReceive;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.add.path.capability.AddressFamilies;
23
24 public final class MultiPathSupportImpl implements MultiPathSupport {
25
26     private final Set<BgpTableType> supportedTables;
27
28     private MultiPathSupportImpl(final Set<BgpTableType> supportedTables) {
29         this.supportedTables = ImmutableSet.copyOf(supportedTables);
30     }
31
32     /**
33      * Creates instance of {@link MultiPathSupport} holder to be used
34      * as a parser constraint, hence only "send" add-path capabilities are
35      * taken into the account.
36      *
37      * @param addPathCapabilities The remote add-path capabilities list.
38      * @return MultiPathSupport instance.
39      */
40     public static MultiPathSupport createParserMultiPathSupport(@Nonnull final List<AddressFamilies> addPathCapabilities) {
41         requireNonNull(addPathCapabilities);
42         final Set<BgpTableType> support = addPathCapabilities
43             .stream()
44             .filter(e -> e.getSendReceive() == SendReceive.Both || e.getSendReceive() == SendReceive.Send)
45             .map(e -> new BgpTableTypeImpl(e.getAfi(), e.getSafi()))
46             .collect(Collectors.toSet());
47         return new MultiPathSupportImpl(support);
48     }
49
50     @Override
51     public boolean isTableTypeSupported(final BgpTableType tableType) {
52         return this.supportedTables.contains(tableType);
53     }
54
55 }