BUG-6378: Fix PeerExportGroup
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / PeerExportGroupImpl.java
1 /*
2  * Copyright (c) 2015 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 package org.opendaylight.protocol.bgp.rib.impl;
9
10 import com.google.common.base.Preconditions;
11 import java.util.Collection;
12 import java.util.Map;
13 import org.opendaylight.protocol.bgp.rib.spi.PeerExportGroup;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerId;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
16 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
17
18 final class PeerExportGroupImpl implements PeerExportGroup {
19     private final Map<PeerId, PeerExporTuple> peers;
20     private final AbstractExportPolicy policy;
21
22     public PeerExportGroupImpl(final Map<PeerId, PeerExporTuple> peers, final AbstractExportPolicy policy) {
23         this.peers = Preconditions.checkNotNull(peers);
24         this.policy = Preconditions.checkNotNull(policy);
25     }
26
27     @Override
28     public ContainerNode effectiveAttributes(final PeerRole role, final ContainerNode attributes) {
29         return attributes == null || role == null ? null : policy.effectiveAttributes(role, attributes);
30     }
31
32     @Override
33     public Collection<Map.Entry<PeerId, PeerExporTuple>> getPeers() {
34         return peers.entrySet();
35     }
36
37     @Override
38     public boolean containsPeer(final PeerId routePeerId) {
39         return this.peers.containsKey(routePeerId);
40     }
41 }