BUG-2383 : Application peer rework.
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / PeerExportGroup.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 java.util.Map.Entry;
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.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
18
19 /**
20  * A collection of peers sharing the same export policy.
21  */
22 final class PeerExportGroup {
23     private final Collection<Entry<PeerId, YangInstanceIdentifier>> peers;
24     private final Map<PeerId, PeerRole> peerRoles;
25     private final AbstractExportPolicy policy;
26
27     PeerExportGroup(final Collection<Entry<PeerId, YangInstanceIdentifier>> peers, final Map<PeerId, PeerRole> peerRoles, final AbstractExportPolicy policy) {
28         this.peers = Preconditions.checkNotNull(peers);
29         this.peerRoles = Preconditions.checkNotNull(peerRoles);
30         this.policy = Preconditions.checkNotNull(policy);
31     }
32
33     ContainerNode effectiveAttributes(final PeerId sourcePeerId, final ContainerNode attributes) {
34         return policy.effectiveAttributes(peerRoles.get(sourcePeerId), attributes);
35     }
36
37     Collection<Entry<PeerId, YangInstanceIdentifier>> getPeers() {
38         return peers;
39     }
40 }