53bdbdc32203ff0e5150ae4d76434cd190935fe8
[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.yangtools.yang.data.api.schema.ContainerNode;
16
17 final class PeerExportGroupImpl implements PeerExportGroup {
18     private final Map<PeerId, PeerExporTuple> peers;
19     private final AbstractExportPolicy policy;
20
21     public PeerExportGroupImpl(final Map<PeerId, PeerExporTuple> peers, final AbstractExportPolicy policy) {
22         this.peers = Preconditions.checkNotNull(peers);
23         this.policy = Preconditions.checkNotNull(policy);
24     }
25
26     @Override
27     public ContainerNode effectiveAttributes(final PeerId sourcePeerId, final ContainerNode attributes) {
28         final PeerExporTuple peer = this.peers.get(sourcePeerId);
29         return attributes == null || peer == null ? null : policy.effectiveAttributes(peer.getRole(), attributes);
30     }
31
32     @Override
33     public Collection<Map.Entry<PeerId, PeerExporTuple>> getPeers() {
34         return peers.entrySet();
35     }
36 }