tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.device; |
| 2 | |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 3 | import org.onlab.onos.net.AbstractDescription; |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 4 | import org.onlab.onos.net.PortNumber; |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 5 | import org.onlab.onos.net.SparseAnnotations; |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 6 | |
Yuta HIGUCHI | 9ee60f6 | 2014-10-09 10:00:01 -0700 | [diff] [blame] | 7 | import com.google.common.base.MoreObjects; |
| 8 | |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 9 | /** |
| 10 | * Default implementation of immutable port description. |
| 11 | */ |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 12 | public class DefaultPortDescription extends AbstractDescription |
| 13 | implements PortDescription { |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 14 | |
| 15 | private final PortNumber number; |
tom | d40fc7a | 2014-09-04 16:41:10 -0700 | [diff] [blame] | 16 | private final boolean isEnabled; |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 17 | |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 18 | /** |
| 19 | * Creates a port description using the supplied information. |
| 20 | * |
| 21 | * @param number port number |
| 22 | * @param isEnabled port enabled state |
| 23 | * @param annotations optional key/value annotations map |
| 24 | */ |
| 25 | public DefaultPortDescription(PortNumber number, boolean isEnabled, |
| 26 | SparseAnnotations... annotations) { |
| 27 | super(annotations); |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 28 | this.number = number; |
tom | d40fc7a | 2014-09-04 16:41:10 -0700 | [diff] [blame] | 29 | this.isEnabled = isEnabled; |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 30 | } |
| 31 | |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Creates a port description using the supplied information. |
| 34 | * |
| 35 | * @param base PortDescription to get basic information from |
| 36 | * @param annotations optional key/value annotations map |
| 37 | */ |
| 38 | public DefaultPortDescription(PortDescription base, |
| 39 | SparseAnnotations annotations) { |
| 40 | this(base.portNumber(), base.isEnabled(), annotations); |
| 41 | } |
| 42 | |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 43 | @Override |
| 44 | public PortNumber portNumber() { |
| 45 | return number; |
| 46 | } |
| 47 | |
| 48 | @Override |
tom | d40fc7a | 2014-09-04 16:41:10 -0700 | [diff] [blame] | 49 | public boolean isEnabled() { |
| 50 | return isEnabled; |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Yuta HIGUCHI | 9ee60f6 | 2014-10-09 10:00:01 -0700 | [diff] [blame] | 53 | @Override |
| 54 | public String toString() { |
| 55 | return MoreObjects.toStringHelper(getClass()) |
| 56 | .add("number", number) |
| 57 | .add("isEnabled", isEnabled) |
| 58 | .add("annotations", annotations()) |
| 59 | .toString(); |
| 60 | } |
| 61 | |
Yuta HIGUCHI | f1f1d32 | 2014-10-07 21:09:56 -0700 | [diff] [blame] | 62 | // default constructor for serialization |
| 63 | private DefaultPortDescription() { |
| 64 | this.number = null; |
| 65 | this.isEnabled = false; |
| 66 | } |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 67 | } |