alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.incubator.net.mcast.impl; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableList; |
| 19 | import com.google.common.collect.Lists; |
| 20 | import org.onosproject.net.ConnectPoint; |
| 21 | |
| 22 | import java.util.Collections; |
| 23 | import java.util.List; |
| 24 | |
alshabib | c6b6080 | 2015-10-06 11:42:50 +0200 | [diff] [blame] | 25 | import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 27 | /** |
| 28 | * Simple entity maintaining a mapping between a source and a collection of sink |
| 29 | * connect points. |
| 30 | */ |
| 31 | public final class MulticastData { |
| 32 | |
| 33 | private final ConnectPoint source; |
| 34 | private final List<ConnectPoint> sinks; |
alshabib | c6b6080 | 2015-10-06 11:42:50 +0200 | [diff] [blame] | 35 | private final boolean isEmpty; |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 36 | |
| 37 | private MulticastData() { |
| 38 | this.source = null; |
| 39 | this.sinks = Collections.EMPTY_LIST; |
alshabib | c6b6080 | 2015-10-06 11:42:50 +0200 | [diff] [blame] | 40 | isEmpty = true; |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | public MulticastData(ConnectPoint source, List<ConnectPoint> sinks) { |
alshabib | c6b6080 | 2015-10-06 11:42:50 +0200 | [diff] [blame] | 44 | this.source = checkNotNull(source, "Multicast source cannot be null."); |
| 45 | this.sinks = checkNotNull(sinks, "List of sinks cannot be null."); |
| 46 | isEmpty = false; |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | public MulticastData(ConnectPoint source, ConnectPoint sink) { |
alshabib | c6b6080 | 2015-10-06 11:42:50 +0200 | [diff] [blame] | 50 | this.source = checkNotNull(source, "Multicast source cannot be null."); |
| 51 | this.sinks = Lists.newArrayList(checkNotNull(sink, "Sink cannot be null.")); |
| 52 | isEmpty = false; |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | public MulticastData(ConnectPoint source) { |
alshabib | c6b6080 | 2015-10-06 11:42:50 +0200 | [diff] [blame] | 56 | this.source = checkNotNull(source, "Multicast source cannot be null."); |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 57 | this.sinks = Lists.newArrayList(); |
alshabib | c6b6080 | 2015-10-06 11:42:50 +0200 | [diff] [blame] | 58 | isEmpty = false; |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | public ConnectPoint source() { |
| 62 | return source; |
| 63 | } |
| 64 | |
| 65 | public List<ConnectPoint> sinks() { |
| 66 | return ImmutableList.copyOf(sinks); |
| 67 | } |
| 68 | |
| 69 | public void appendSink(ConnectPoint sink) { |
| 70 | sinks.add(sink); |
| 71 | } |
| 72 | |
| 73 | public boolean removeSink(ConnectPoint sink) { |
| 74 | return sinks.remove(sink); |
| 75 | } |
| 76 | |
| 77 | public boolean isEmpty() { |
alshabib | c6b6080 | 2015-10-06 11:42:50 +0200 | [diff] [blame] | 78 | return isEmpty; |
alshabib | ed0951f | 2015-10-02 21:39:27 +0200 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | public static MulticastData empty() { |
| 82 | return new MulticastData(); |
| 83 | } |
| 84 | |
| 85 | } |